Skip to content
Snippets Groups Projects
Commit 2fbaf80c authored by Ilham Firdausi Putra's avatar Ilham Firdausi Putra
Browse files

change main layout, add fragment container

parent f68310d3
No related merge requests found
package com.chatman;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.ValueEventListener;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link ChatFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link ChatFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ChatFragment extends Fragment {
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_NAMA = "nama";
private static final String ARG_KEY = "key";
private String nama;
private OnFragmentInteractionListener mListener;
public ChatFragment() {
// Required empty public constructor
}
public static ChatFragment newInstance(String param1) {
ChatFragment fragment = new ChatFragment();
Bundle args = new Bundle();
args.putString(ARG_NAMA, param1);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
nama = getArguments().getString(ARG_NAMA);
} else {
nama = "Dummy";
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_chat, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
((MainActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
// linearLayoutManager.setReverseLayout(true);
// linearLayoutManager.setStackFromEnd(true);
// recycler.setLayoutManager(linearLayoutManager);
// getChatList();
// adapter = new ChatAdapter(chatList);
// recycler.setAdapter(adapter);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
package com.chatman.adapter;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -10,6 +14,7 @@ import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.chatman.MainActivity;
import com.chatman.R;
import com.chatman.model.ChatList;
......@@ -51,7 +56,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
return items.size();
}
public class ChatListHolder extends RecyclerView.ViewHolder {
public class ChatListHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView chatListName;
private TextView chatListLastMessage;
......@@ -73,5 +78,24 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
chatListLastMessage.setText(item.getLastMessage());
chatListName.setText(item.getName());
}
@Override
public void onClick(View view) {
// AppCompatActivity activity = (AppCompatActivity) view.getContext();
// Fragment myFragment = new MyFragment();
// activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, myFragment).addToBackStack(null).commit();
}
// public boolean loadFragment(Fragment fragment) {
// switching fragment
// if (fragment != null) {
// ((MainActivity) getActivity())getSupportFragmentManager()
// .beginTransaction()
// .replace(R.id.fragment_container, fragment)
// .commit();
// return true;
// }
// return false;
// }
}
}
\ No newline at end of file
......@@ -8,15 +8,22 @@
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/chat_list_rv"
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v7.widget.RecyclerView>
<!--<android.support.v7.widget.RecyclerView-->
<!--android:id="@+id/chat_list_rv"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--app:layout_constraintStart_toStartOf="parent"-->
<!--app:layout_constraintEnd_toEndOf="parent"-->
<!--app:layout_constraintTop_toTopOf="parent"-->
<!--app:layout_constraintBottom_toBottomOf="parent">-->
<!--</android.support.v7.widget.RecyclerView>-->
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChatFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
\ No newline at end of file
......@@ -19,5 +19,8 @@
<string name="register">Daftar</string>
<string name="register_word">Belum punya akun?</string>
<string name="login_word">Sudah memiliki akun?</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment