mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-30 13:26:12 +00:00
Swap profile megaphone icon and use user avatar if present.
This commit is contained in:
committed by
Greyson Parrelli
parent
624837fcf1
commit
707a2aca0a
@@ -56,9 +56,9 @@ public class BasicMegaphoneView extends FrameLayout {
|
||||
this.megaphone = megaphone;
|
||||
this.megaphoneListener = megaphoneListener;
|
||||
|
||||
if (megaphone.getImage() != 0) {
|
||||
if (megaphone.getImageRequest() != null) {
|
||||
image.setVisibility(VISIBLE);
|
||||
image.setImageResource(megaphone.getImage());
|
||||
megaphone.getImageRequest().into(image);
|
||||
} else {
|
||||
image.setVisibility(GONE);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,34 @@
|
||||
package org.thoughtcrime.securesms.megaphone;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.megaphone.Megaphones.Event;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequest;
|
||||
|
||||
/**
|
||||
* For guidance on creating megaphones, see {@link Megaphones}.
|
||||
*/
|
||||
public class Megaphone {
|
||||
|
||||
private final Event event;
|
||||
private final Style style;
|
||||
private final boolean mandatory;
|
||||
private final boolean canSnooze;
|
||||
private final int titleRes;
|
||||
private final int bodyRes;
|
||||
private final int imageRes;
|
||||
private final int buttonTextRes;
|
||||
private final EventListener buttonListener;
|
||||
private final EventListener snoozeListener;
|
||||
private final EventListener onVisibleListener;
|
||||
private final Event event;
|
||||
private final Style style;
|
||||
private final boolean mandatory;
|
||||
private final boolean canSnooze;
|
||||
private final int titleRes;
|
||||
private final int bodyRes;
|
||||
private final GlideRequest<Drawable> imageRequest;
|
||||
private final int buttonTextRes;
|
||||
private final EventListener buttonListener;
|
||||
private final EventListener snoozeListener;
|
||||
private final EventListener onVisibleListener;
|
||||
|
||||
private Megaphone(@NonNull Builder builder) {
|
||||
this.event = builder.event;
|
||||
@@ -31,7 +37,7 @@ public class Megaphone {
|
||||
this.canSnooze = builder.canSnooze;
|
||||
this.titleRes = builder.titleRes;
|
||||
this.bodyRes = builder.bodyRes;
|
||||
this.imageRes = builder.imageRes;
|
||||
this.imageRequest = builder.imageRequest;
|
||||
this.buttonTextRes = builder.buttonTextRes;
|
||||
this.buttonListener = builder.buttonListener;
|
||||
this.snoozeListener = builder.snoozeListener;
|
||||
@@ -62,8 +68,8 @@ public class Megaphone {
|
||||
return bodyRes;
|
||||
}
|
||||
|
||||
public @DrawableRes int getImage() {
|
||||
return imageRes;
|
||||
public @Nullable GlideRequest<Drawable> getImageRequest() {
|
||||
return imageRequest;
|
||||
}
|
||||
|
||||
public @StringRes int getButtonText() {
|
||||
@@ -91,15 +97,15 @@ public class Megaphone {
|
||||
private final Event event;
|
||||
private final Style style;
|
||||
|
||||
private boolean mandatory;
|
||||
private boolean canSnooze;
|
||||
private int titleRes;
|
||||
private int bodyRes;
|
||||
private int imageRes;
|
||||
private int buttonTextRes;
|
||||
private EventListener buttonListener;
|
||||
private EventListener snoozeListener;
|
||||
private EventListener onVisibleListener;
|
||||
private boolean mandatory;
|
||||
private boolean canSnooze;
|
||||
private int titleRes;
|
||||
private int bodyRes;
|
||||
private GlideRequest<Drawable> imageRequest;
|
||||
private int buttonTextRes;
|
||||
private EventListener buttonListener;
|
||||
private EventListener snoozeListener;
|
||||
private EventListener onVisibleListener;
|
||||
|
||||
|
||||
public Builder(@NonNull Event event, @NonNull Style style) {
|
||||
@@ -135,7 +141,12 @@ public class Megaphone {
|
||||
}
|
||||
|
||||
public @NonNull Builder setImage(@DrawableRes int imageRes) {
|
||||
this.imageRes = imageRes;
|
||||
setImageRequest(GlideApp.with(ApplicationDependencies.getApplication()).load(imageRes));
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NonNull Builder setImageRequest(@Nullable GlideRequest<Drawable> imageRequest) {
|
||||
this.imageRequest = imageRequest;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestMegaphoneActivity;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity;
|
||||
import org.thoughtcrime.securesms.util.AvatarUtil;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
@@ -207,7 +208,7 @@ public final class Megaphones {
|
||||
|
||||
Megaphone.Builder builder = new Megaphone.Builder(Event.PROFILE_NAMES_FOR_ALL, Megaphone.Style.BASIC)
|
||||
.enableSnooze(null)
|
||||
.setImage(R.drawable.profile_megaphone);
|
||||
.setImageRequest(AvatarUtil.getSelfAvatarOrFallbackIcon(context, R.drawable.ic_profilename_64));
|
||||
|
||||
if (TextSecurePreferences.getProfileName(ApplicationDependencies.getApplication()) == ProfileName.EMPTY) {
|
||||
return builder.setTitle(R.string.ProfileNamesMegaphone__add_a_profile_name)
|
||||
|
||||
@@ -55,9 +55,9 @@ public class PopupMegaphoneView extends FrameLayout {
|
||||
this.megaphone = megaphone;
|
||||
this.megaphoneListener = megaphoneListener;
|
||||
|
||||
if (megaphone.getImage() != 0) {
|
||||
if (megaphone.getImageRequest() != null) {
|
||||
image.setVisibility(VISIBLE);
|
||||
image.setImageResource(megaphone.getImage());
|
||||
megaphone.getImageRequest().into(image);
|
||||
} else {
|
||||
image.setVisibility(GONE);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
@@ -43,6 +44,15 @@ public final class AvatarUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static GlideRequest<Drawable> getSelfAvatarOrFallbackIcon(@NonNull Context context, @DrawableRes int fallbackIcon) {
|
||||
return GlideApp.with(context)
|
||||
.asDrawable()
|
||||
.load(new ProfileContactPhoto(Recipient.self().getId(), String.valueOf(TextSecurePreferences.getProfileAvatarId(context))))
|
||||
.error(fallbackIcon)
|
||||
.circleCrop()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
||||
}
|
||||
|
||||
private static <T> GlideRequest<T> request(@NonNull GlideRequest<T> glideRequest, @NonNull Context context, @NonNull Recipient recipient) {
|
||||
return glideRequest.load(new ProfileContactPhoto(recipient.getId(), String.valueOf(TextSecurePreferences.getProfileAvatarId(context))))
|
||||
.error(getFallback(context, recipient))
|
||||
|
||||
Reference in New Issue
Block a user