mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-17 09:04:53 +02:00
95 lines
2.8 KiB
Java
95 lines
2.8 KiB
Java
|
package org.mercury_im.messenger.ui.chatlist;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.os.Build;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.appcompat.app.AppCompatActivity;
|
||
|
import androidx.core.app.ActivityOptionsCompat;
|
||
|
import androidx.recyclerview.widget.RecyclerView;
|
||
|
|
||
|
import org.jivesoftware.smackx.colors.ConsistentColor;
|
||
|
import org.jxmpp.jid.EntityBareJid;
|
||
|
import org.mercury_im.messenger.R;
|
||
|
import org.mercury_im.messenger.persistence.model.ChatModel;
|
||
|
import org.mercury_im.messenger.persistence.room.model.RoomChatModel;
|
||
|
import org.mercury_im.messenger.persistence.room.model.RoomContactModel;
|
||
|
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||
|
import org.mercury_im.messenger.util.ColorUtil;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
import butterknife.BindView;
|
||
|
import butterknife.ButterKnife;
|
||
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||
|
|
||
|
public class ChatListRecyclerViewAdapter
|
||
|
extends RecyclerView.Adapter<ChatListRecyclerViewAdapter.ChatListItemViewHolder> {
|
||
|
|
||
|
private List<ChatModel> chatModelList;
|
||
|
|
||
|
public ChatListRecyclerViewAdapter() {
|
||
|
this.chatModelList = new ArrayList<>();
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
@Override
|
||
|
public ChatListItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||
|
return new ChatListItemViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext())
|
||
|
.inflate(R.layout.recycler_view_item_chat_list, parent, false));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onBindViewHolder(@NonNull ChatListItemViewHolder holder, int position) {
|
||
|
ChatModel model = chatModelList.get(position);
|
||
|
holder.bind(model);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getItemCount() {
|
||
|
return chatModelList.size();
|
||
|
}
|
||
|
|
||
|
public void setItems(List<ChatModel> chatModels) {
|
||
|
this.chatModelList = chatModels;
|
||
|
notifyDataSetChanged();
|
||
|
}
|
||
|
|
||
|
public class ChatListItemViewHolder extends RecyclerView.ViewHolder {
|
||
|
|
||
|
private View view;
|
||
|
|
||
|
@BindView(R.id.chat_name)
|
||
|
TextView nameView;
|
||
|
|
||
|
@BindView(R.id.chat_message)
|
||
|
TextView chatMessage;
|
||
|
|
||
|
@BindView(R.id.chat_time)
|
||
|
TextView chatTime;
|
||
|
|
||
|
@BindView(R.id.chat_avatar)
|
||
|
CircleImageView avatarView;
|
||
|
|
||
|
Context context;
|
||
|
|
||
|
public ChatListItemViewHolder(Context context, View itemView) {
|
||
|
super(itemView);
|
||
|
this.context = context;
|
||
|
this.view = itemView;
|
||
|
ButterKnife.bind(this, view);
|
||
|
}
|
||
|
|
||
|
void bind(ChatModel chatModel) {
|
||
|
String name = chatModel.getPeerEntityId() + "";
|
||
|
nameView.setText(name);
|
||
|
}
|
||
|
}
|
||
|
}
|