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

add temporary toast to home_fragment's chatlist

parent e28bb930
Branches
No related merge requests found
......@@ -2,6 +2,7 @@ package com.chatman.adapter;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
......@@ -10,7 +11,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
......@@ -28,6 +31,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
private List<ChatList> items = new ArrayList<>();
private int itemLayout = R.layout.item_chat_list;
private Context context;
public ChatListAdapter(List<ChatList> items) {
this.items = items;
......@@ -35,12 +39,20 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
@Override
public ChatListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
context = parent.getContext();
return new ChatListHolder(LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false));
}
@Override
public void onBindViewHolder(ChatListHolder holder, int position) {
holder.bind(items.get(position));
final String nama = holder.chatListName.getText().toString();
holder.chatListBackground.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "Show "+nama+" chat room", Toast.LENGTH_SHORT).show();
}
});
}
public void addItems(List<ChatList> items) {
......@@ -56,8 +68,8 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
return items.size();
}
public class ChatListHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public class ChatListHolder extends RecyclerView.ViewHolder {
private RelativeLayout chatListBackground;
private TextView chatListName;
private TextView chatListLastMessage;
private ImageView chatListImage;
......@@ -71,6 +83,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
chatListImage = itemView.findViewById(R.id.chat_list_avatar);
chatListLastMessage = itemView.findViewById(R.id.chat_list_last_message);
chatListName = itemView.findViewById(R.id.chat_list_name);
chatListBackground = itemView.findViewById(R.id.chat_list_rl);
}
public void bind(ChatList item) {
......@@ -79,23 +92,5 @@ public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatLi
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
......@@ -6,8 +6,10 @@ import com.google.firebase.database.FirebaseDatabase;
public class FirebaseHelper {
private static final String DB_USER = "user";
private static final String DB_MESSAGE = "MESSAGE";
public static String USER_KEY, USER_EMAIL, USER_NAMA, USER_PASSWORD;
private static DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
public static final DatabaseReference dbUser = reference.child(DB_USER);
public static final DatabaseReference dbMessage = reference.child(DB_MESSAGE);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/chat_list_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
......
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