mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-11-13 03:22:05 +01:00
Fix name displaying and use AvatarDrawable
This commit is contained in:
parent
7905693fc7
commit
946a66ed38
4 changed files with 15 additions and 8 deletions
|
@ -17,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.ui.avatar.AvatarDrawable;
|
||||
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||||
import org.mercury_im.messenger.ui.util.AbstractRecyclerViewAdapter;
|
||||
import org.mercury_im.messenger.util.ColorUtil;
|
||||
|
@ -42,15 +43,15 @@ public class ChatListRecyclerViewAdapter
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull ChatHolder holder, int position) {
|
||||
DirectChat model = getItemAt(position);
|
||||
holder.nameView.setText(model.getPeer().getAddress() != null ?
|
||||
model.getPeer().getAddress() : model.toString());
|
||||
holder.avatarView.setColorFilter(ColorUtil.consistentColor(model.getPeer().getAddress()));
|
||||
|
||||
String name = model.getPeer().getDisplayName();
|
||||
String address = model.getPeer().getAddress();
|
||||
holder.nameView.setText(name);
|
||||
holder.avatarView.setImageDrawable(new AvatarDrawable(name, address));
|
||||
holder.itemView.setOnClickListener(view -> {
|
||||
|
||||
Intent intent = new Intent(holder.context, ChatActivity.class);
|
||||
intent.putExtra(ChatActivity.EXTRA_JID, model.getPeer().getAddress());
|
||||
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, model.getPeer().getAccount().getId());
|
||||
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, model.getPeer().getAccount().getId().toString());
|
||||
|
||||
holder.context.startActivity(intent);
|
||||
});
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.ui.avatar.AvatarDrawable;
|
||||
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||||
import org.mercury_im.messenger.ui.util.AbstractRecyclerViewAdapter;
|
||||
import org.mercury_im.messenger.util.ColorUtil;
|
||||
|
@ -65,11 +66,11 @@ public class ContactListRecyclerViewAdapter
|
|||
}
|
||||
|
||||
void bind(Peer contact) {
|
||||
String name = contact.getName();
|
||||
String name = contact.getDisplayName();
|
||||
String address = contact.getAddress();
|
||||
nameView.setText(name != null ? name : address);
|
||||
nameView.setText(name);
|
||||
jidView.setText(address);
|
||||
avatarView.setColorFilter(ColorUtil.consistentColor(address));
|
||||
avatarView.setImageDrawable(new AvatarDrawable(name, address));
|
||||
view.setOnClickListener(view -> {
|
||||
|
||||
Intent intent = new Intent(context, ChatActivity.class);
|
||||
|
|
|
@ -44,6 +44,7 @@ public class PeerMapping extends AbstractMapping<Peer, PeerModel> {
|
|||
entity.setId(model.getId());
|
||||
entity.setAccount(accountMapping.toEntity(model.getAccount(), entity.getAccount()));
|
||||
entity.setAddress(model.getAddress());
|
||||
entity.setName(model.getName());
|
||||
|
||||
entity.setSubscriptionDirection(model.getSubscriptionDirection());
|
||||
entity.setSubscriptionPending(model.isSubscriptionPending());
|
||||
|
|
|
@ -41,4 +41,8 @@ public interface Peer {
|
|||
void setSubscriptionApproved(boolean approved);
|
||||
|
||||
boolean isContact();
|
||||
|
||||
default String getDisplayName() {
|
||||
return getName() != null ? getName() : getAddress();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue