mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Improve AvatarImage to update on recipient changes.
This commit is contained in:
@@ -9,12 +9,18 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.lifecycle.map
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||
import org.thoughtcrime.securesms.database.model.ProfileAvatarFileDetails
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.NameUtil
|
||||
|
||||
@Composable
|
||||
fun AvatarImage(
|
||||
@@ -22,6 +28,9 @@ fun AvatarImage(
|
||||
modifier: Modifier = Modifier,
|
||||
useProfile: Boolean = true
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val state = recipient.live().liveData.map { AvatarImageState(NameUtil.getAbbreviation(it.getDisplayName(context)), it, AvatarHelper.getAvatarFileDetails(context, it.id)) }.observeAsState().value ?: return
|
||||
|
||||
if (LocalInspectionMode.current) {
|
||||
Spacer(
|
||||
modifier = modifier
|
||||
@@ -33,10 +42,16 @@ fun AvatarImage(
|
||||
modifier = modifier.background(color = Color.Transparent, shape = CircleShape)
|
||||
) {
|
||||
if (useProfile) {
|
||||
it.setAvatarUsingProfile(recipient)
|
||||
it.setAvatarUsingProfile(state.self)
|
||||
} else {
|
||||
it.setAvatar(recipient)
|
||||
it.setAvatar(state.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class AvatarImageState(
|
||||
val displayName: String?,
|
||||
val self: Recipient,
|
||||
val avatarFileDetails: ProfileAvatarFileDetails
|
||||
)
|
||||
|
||||
@@ -62,13 +62,13 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
|
||||
private final RequestListener<Drawable> redownloadRequestListener = new RedownloadRequestListener();
|
||||
|
||||
private int size;
|
||||
private boolean inverted;
|
||||
private OnClickListener listener;
|
||||
private boolean blurred;
|
||||
private ChatColors chatColors;
|
||||
private String initials;
|
||||
private FixedSizeTarget fixedSizeTarget;
|
||||
private int size;
|
||||
private boolean inverted;
|
||||
private OnClickListener listener;
|
||||
private boolean blurred;
|
||||
private ChatColors chatColors;
|
||||
private String initials;
|
||||
private FixedSizeTarget fixedSizeTarget;
|
||||
|
||||
private @Nullable RecipientContactPhoto recipientContactPhoto;
|
||||
private @NonNull Drawable unknownRecipientDrawable;
|
||||
|
||||
Reference in New Issue
Block a user