diff --git a/android/app/src/main/java/com/chatman/ChatFragment.java b/android/app/src/main/java/com/chatman/ChatFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..d9674387368c79d1dd460f093235555cb12c33de --- /dev/null +++ b/android/app/src/main/java/com/chatman/ChatFragment.java @@ -0,0 +1,119 @@ +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); + } +} diff --git a/android/app/src/main/java/com/chatman/adapter/ChatListAdapter.java b/android/app/src/main/java/com/chatman/adapter/ChatListAdapter.java index 8ca6dd433061060c4fad284519eb65ffd1d33b1a..f04453210c52173db2c8ca69d8cf6047f503490a 100644 --- a/android/app/src/main/java/com/chatman/adapter/ChatListAdapter.java +++ b/android/app/src/main/java/com/chatman/adapter/ChatListAdapter.java @@ -1,6 +1,10 @@ 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 diff --git a/android/app/src/main/res/layout/content_main.xml b/android/app/src/main/res/layout/content_main.xml index 9f85354e50b85d050ed94cbd1975afd6816438d3..fc7f50ba721481994e6cc7416b36e1657dc76a9e 100644 --- a/android/app/src/main/res/layout/content_main.xml +++ b/android/app/src/main/res/layout/content_main.xml @@ -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 diff --git a/android/app/src/main/res/layout/fragment_chat.xml b/android/app/src/main/res/layout/fragment_chat.xml new file mode 100644 index 0000000000000000000000000000000000000000..ea2cfd74483d56f051511236933b9e86521cf07e --- /dev/null +++ b/android/app/src/main/res/layout/fragment_chat.xml @@ -0,0 +1,14 @@ +<?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 diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index d8880fcae6738ca8bb84fddbcc5586783611a725..3c0a395c12fbc099c6d43b6aa834404162a38d6c 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -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>