codacy: shorten long method by extracting common logic

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-08-10 11:27:27 +02:00
parent 5dc248e425
commit a484d2ab85
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -159,59 +159,57 @@ public class ContactItem extends AbstractFlexibleItem<ContactItem.ContactItemVie
participant.getCalculatedActorType() == Participant.ActorType.CIRCLES ||
PARTICIPANT_SOURCE_CIRCLES.equals(participant.getSource())) {
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_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);
}
}