diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java index bd0cdf410..a28c2f3a3 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java @@ -159,59 +159,57 @@ public class ContactItem extends AbstractFlexibleItem= Build.VERSION_CODES.O) { - holder.binding.avatarDraweeView.getHierarchy().setPlaceholderImage( - DisplayUtils.getRoundedDrawable( - viewThemeUtils.themePlaceholderAvatar(holder.binding.avatarDraweeView, - R.drawable.ic_avatar_group))); - } else { - holder.binding.avatarDraweeView.setImageResource(R.drawable.ic_circular_group); - } + setGenericAvatar(holder, R.drawable.ic_avatar_group, R.drawable.ic_circular_group); } else if (participant.getCalculatedActorType() == Participant.ActorType.EMAILS) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - holder.binding.avatarDraweeView.getHierarchy().setPlaceholderImage( - DisplayUtils.getRoundedDrawable( - viewThemeUtils.themePlaceholderAvatar(holder.binding.avatarDraweeView, - R.drawable.ic_avatar_mail))); - } else { - holder.binding.avatarDraweeView.setImageResource(R.drawable.ic_circular_mail); - } + setGenericAvatar(holder, R.drawable.ic_avatar_mail, R.drawable.ic_circular_mail); } else if ( participant.getCalculatedActorType() == Participant.ActorType.GUESTS || Participant.ParticipantType.GUEST.equals(participant.getType()) || Participant.ParticipantType.GUEST_MODERATOR.equals(participant.getType())) { - String displayName = NextcloudTalkApplication.Companion.getSharedApplication() - .getResources().getString(R.string.nc_guest); + String displayName; if (!TextUtils.isEmpty(participant.getDisplayName())) { displayName = participant.getDisplayName(); + } else { + displayName = NextcloudTalkApplication.Companion.getSharedApplication() + .getResources().getString(R.string.nc_guest); } - DraweeController draweeController = Fresco.newDraweeControllerBuilder() - .setOldController(holder.binding.avatarDraweeView.getController()) - .setAutoPlayAnimations(true) - .setImageRequest(DisplayUtils.getImageRequestForUrl( - ApiUtils.getUrlForGuestAvatar(user.getBaseUrl(), - displayName, - false))) - .build(); - holder.binding.avatarDraweeView.setController(draweeController); - + setUserStyleAvatar(holder, + ApiUtils.getUrlForGuestAvatar(user.getBaseUrl(), displayName, false)); } else if (participant.getCalculatedActorType() == Participant.ActorType.USERS || PARTICIPANT_SOURCE_USERS.equals(participant.getSource())) { - DraweeController draweeController = Fresco.newDraweeControllerBuilder() - .setOldController(holder.binding.avatarDraweeView.getController()) - .setAutoPlayAnimations(true) - .setImageRequest(DisplayUtils.getImageRequestForUrl( - ApiUtils.getUrlForAvatar(user.getBaseUrl(), - participant.getCalculatedActorId(), - false))) - .build(); - holder.binding.avatarDraweeView.setController(draweeController); + setUserStyleAvatar(holder, + ApiUtils.getUrlForAvatar(user.getBaseUrl(), + participant.getCalculatedActorId(), + false)); + } + } + + private void setUserStyleAvatar(ContactItemViewHolder holder, String avatarUrl) { + DraweeController draweeController = Fresco.newDraweeControllerBuilder() + .setOldController(holder.binding.avatarDraweeView.getController()) + .setAutoPlayAnimations(true) + .setImageRequest(DisplayUtils.getImageRequestForUrl(avatarUrl)) + .build(); + holder.binding.avatarDraweeView.setController(draweeController); + } + + private void setGenericAvatar( + ContactItemViewHolder holder, + int roundPlaceholderDrawable, + int fallbackImageResource) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + holder.binding.avatarDraweeView.getHierarchy().setPlaceholderImage( + DisplayUtils.getRoundedDrawable( + viewThemeUtils.themePlaceholderAvatar(holder.binding.avatarDraweeView, + roundPlaceholderDrawable))); + } else { + holder.binding.avatarDraweeView.setImageResource(fallbackImageResource); } }