Fix name displaying and use AvatarDrawable

This commit is contained in:
Paul Schaub 2019-12-21 16:47:41 +01:00
parent 7905693fc7
commit 946a66ed38
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 15 additions and 8 deletions

View file

@ -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);
});

View file

@ -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);

View file

@ -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());

View file

@ -41,4 +41,8 @@ public interface Peer {
void setSubscriptionApproved(boolean approved);
boolean isContact();
default String getDisplayName() {
return getName() != null ? getName() : getAddress();
}
}