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

add chat list recycler view

parent 979984a3
Branches
No related merge requests found
Showing
with 274 additions and 29 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -31,6 +31,8 @@ dependencies {
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
}
apply plugin: 'com.google.gms.google-services'
package com.chatman;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
......@@ -15,10 +18,20 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.chatman.adapter.ChatListAdapter;
import com.chatman.helper.PreferencesHelper;
import com.chatman.model.ChatList;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private RecyclerView recycler;
private ChatListAdapter adapter;
private List<ChatList> chatLists;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -26,15 +39,18 @@ public class MainActivity extends AppCompatActivity
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
context = this;
// Recycler View
recycler = findViewById(R.id.chat_list_rv);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recycler.setLayoutManager(linearLayoutManager);
getChatLists();
adapter = new ChatListAdapter(chatLists);
recycler.setAdapter(adapter);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
......@@ -52,7 +68,6 @@ public class MainActivity extends AppCompatActivity
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
// super.onBackPressed();
this.moveTaskToBack(true);
}
}
......@@ -100,4 +115,70 @@ public class MainActivity extends AppCompatActivity
drawer.closeDrawer(GravityCompat.START);
return true;
}
// Todo: Ganti data dummmy jadi data asli ngambil dari database
private List<ChatList> getChatLists() {
chatLists = new ArrayList<>();
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
chatLists.add(new ChatList(
R.drawable.priagung,
"Priagung Satyagama",
"Woi sini ke sekre 2 temani diriku yang kesepian"
));
chatLists.add(new ChatList(
R.drawable.rama,
"Yusuf Rahmat Pratama",
"Eh, gmn gmn?"
));
return chatLists;
}
}
package com.chatman.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.chatman.R;
import com.chatman.model.ChatList;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.ChatListHolder> {
private List<ChatList> items = new ArrayList<>();
private int itemLayout = R.layout.item_chat_list;
public ChatListAdapter(List<ChatList> items) {
this.items = items;
}
@Override
public ChatListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ChatListHolder(LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false));
}
@Override
public void onBindViewHolder(ChatListHolder holder, int position) {
holder.bind(items.get(position));
}
public void addItems(List<ChatList> items) {
this.items.addAll(items);
notifyDataSetChanged();
}
@Override
public int getItemCount() {
if (items == null) {
return 0;
}
return items.size();
}
public class ChatListHolder extends RecyclerView.ViewHolder {
private TextView chatListName;
private TextView chatListLastMessage;
private ImageView chatListImage;
public ChatListHolder(View itemView) {
super(itemView);
bindView();
}
private void bindView() {
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);
}
public void bind(ChatList item) {
Glide.with(itemView).load(item.getAvatarResource()).into(chatListImage);
chatListLastMessage.setText(item.getLastMessage());
chatListName.setText(item.getName());
}
}
}
\ No newline at end of file
package com.chatman.model;
public class ChatList {
private int avatarResource;
private String name;
private String lastMessage;
// Todo : tambahin atribut KEY atau apalah supaya ntar waktu ditekan, ke fragmentnya bisa dipass KEY itu terus data di dalam fragmentnya diambil berdasarkan KEY tersebut
public ChatList(int avatarResource, String name, String lastMessage) {
this.avatarResource = avatarResource;
this.name = name;
this.lastMessage = lastMessage;
}
public int getAvatarResource() {
return avatarResource;
}
public void setAvatarResource(int avatarResource) {
this.avatarResource = avatarResource;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastMessage() {
return lastMessage;
}
public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
}
}
android/app/src/main/res/drawable/priagung.jpeg

54.3 KiB

android/app/src/main/res/drawable/rama.jpg

56.7 KiB

......@@ -9,7 +9,8 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:theme="@style/AppTheme.AppBarOverlay"
android:elevation="10dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
......@@ -22,12 +23,4 @@
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
......@@ -8,13 +8,15 @@
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<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"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="@dimen/activity_horizontal_margin">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/chat_list_avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
app:civ_border_width="0dp"
app:civ_border_color="#FF000000"/>
<TextView
android:id="@+id/chat_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/chat_list_avatar"
android:text="@string/lorem_ipsum"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="#212121"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
<TextView
android:id="@+id/chat_list_last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/chat_list_name"
android:layout_marginTop="8dp"
android:layout_toEndOf="@id/chat_list_avatar"
android:text="@string/lorem_ipsum"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="#727272"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
</RelativeLayout>
\ No newline at end of file
......@@ -7,6 +7,9 @@
<string name="nav_header_desc">Navigation header</string>
<string name="action_settings">Settings</string>
<string name="lorem_ipsum">Lorem ipsum dolor sit amet, mei duis legimus accusamus ea. Et mei ceteros inimicus. Graeco facilis an eos, doming sensibus duo ad. Omnium recteque duo at, at ius magna persequeris. Sit consequat rationibus ea, pro id admodum volumus tibique, nam diam graecis petentium ad. Ex fugit tantas consetetur eum, vel an legendos persecuti persequeris, aliquid voluptatibus ex eam.</string>
<!--Auth Strings-->
<string name="name">Nama</string>
<string name="email">Email</string>
......
photoshop_assets/priagung.jpeg

54.3 KiB

photoshop_assets/rama.jpg

56.7 KiB

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