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.getCalculatedActorType() == Participant.ActorType.CIRCLES ||
PARTICIPANT_SOURCE_CIRCLES.equals(participant.getSource())) { PARTICIPANT_SOURCE_CIRCLES.equals(participant.getSource())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setGenericAvatar(holder, R.drawable.ic_avatar_group, R.drawable.ic_circular_group);
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);
}
} else if (participant.getCalculatedActorType() == Participant.ActorType.EMAILS) { } else if (participant.getCalculatedActorType() == Participant.ActorType.EMAILS) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setGenericAvatar(holder, R.drawable.ic_avatar_mail, R.drawable.ic_circular_mail);
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);
}
} else if ( } else if (
participant.getCalculatedActorType() == Participant.ActorType.GUESTS || participant.getCalculatedActorType() == Participant.ActorType.GUESTS ||
Participant.ParticipantType.GUEST.equals(participant.getType()) || Participant.ParticipantType.GUEST.equals(participant.getType()) ||
Participant.ParticipantType.GUEST_MODERATOR.equals(participant.getType())) { Participant.ParticipantType.GUEST_MODERATOR.equals(participant.getType())) {
String displayName = NextcloudTalkApplication.Companion.getSharedApplication() String displayName;
.getResources().getString(R.string.nc_guest);
if (!TextUtils.isEmpty(participant.getDisplayName())) { if (!TextUtils.isEmpty(participant.getDisplayName())) {
displayName = participant.getDisplayName(); displayName = participant.getDisplayName();
} else {
displayName = NextcloudTalkApplication.Companion.getSharedApplication()
.getResources().getString(R.string.nc_guest);
} }
DraweeController draweeController = Fresco.newDraweeControllerBuilder() setUserStyleAvatar(holder,
.setOldController(holder.binding.avatarDraweeView.getController()) ApiUtils.getUrlForGuestAvatar(user.getBaseUrl(), displayName, false));
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForGuestAvatar(user.getBaseUrl(),
displayName,
false)))
.build();
holder.binding.avatarDraweeView.setController(draweeController);
} else if (participant.getCalculatedActorType() == Participant.ActorType.USERS || } else if (participant.getCalculatedActorType() == Participant.ActorType.USERS ||
PARTICIPANT_SOURCE_USERS.equals(participant.getSource())) { PARTICIPANT_SOURCE_USERS.equals(participant.getSource())) {
DraweeController draweeController = Fresco.newDraweeControllerBuilder() setUserStyleAvatar(holder,
.setOldController(holder.binding.avatarDraweeView.getController()) ApiUtils.getUrlForAvatar(user.getBaseUrl(),
.setAutoPlayAnimations(true) participant.getCalculatedActorId(),
.setImageRequest(DisplayUtils.getImageRequestForUrl( false));
ApiUtils.getUrlForAvatar(user.getBaseUrl(), }
participant.getCalculatedActorId(), }
false)))
.build(); private void setUserStyleAvatar(ContactItemViewHolder holder, String avatarUrl) {
holder.binding.avatarDraweeView.setController(draweeController); 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);
} }
} }