mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Update MyStoryItem on profile change.
This commit is contained in:
@@ -46,7 +46,7 @@ import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment;
|
||||
import org.thoughtcrime.securesms.util.AvatarUtil;
|
||||
import org.thoughtcrime.securesms.util.NameUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -67,6 +67,7 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
private OnClickListener listener;
|
||||
private boolean blurred;
|
||||
private ChatColors chatColors;
|
||||
private String initials;
|
||||
private FixedSizeTarget fixedSizeTarget;
|
||||
|
||||
private @Nullable RecipientContactPhoto recipientContactPhoto;
|
||||
@@ -100,6 +101,7 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
unknownRecipientDrawable = new FallbackAvatarDrawable(context, new FallbackAvatar.Resource.Person(AvatarColor.UNKNOWN)).circleCrop();
|
||||
blurred = false;
|
||||
chatColors = null;
|
||||
initials = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,12 +125,7 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
* Shows self as the actual profile picture.
|
||||
*/
|
||||
public void setRecipient(@NonNull Recipient recipient, boolean quickContactEnabled) {
|
||||
if (recipient.isSelf()) {
|
||||
setAvatar(Glide.with(this), null, quickContactEnabled);
|
||||
AvatarUtil.loadIconIntoImageView(recipient, this);
|
||||
} else {
|
||||
setAvatar(Glide.with(this), recipient, quickContactEnabled);
|
||||
}
|
||||
setAvatar(Glide.with(this), recipient, quickContactEnabled, recipient.isSelf());
|
||||
}
|
||||
|
||||
public AvatarOptions.Builder buildOptions() {
|
||||
@@ -177,10 +174,12 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
|
||||
boolean shouldBlur = recipient.getShouldBlurAvatar();
|
||||
ChatColors chatColors = recipient.getChatColors();
|
||||
String initials = NameUtil.getAbbreviation(recipient.getDisplayName(getContext()));
|
||||
|
||||
if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors)) {
|
||||
if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors) || !Objects.equals(initials, this.initials)) {
|
||||
requestManager.clear(this);
|
||||
this.chatColors = chatColors;
|
||||
this.chatColors = chatColors;
|
||||
this.initials = initials;
|
||||
recipientContactPhoto = photo;
|
||||
|
||||
FallbackAvatarProvider activeFallbackPhotoProvider = this.fallbackAvatarProvider;
|
||||
@@ -189,7 +188,7 @@ public final class AvatarImageView extends AppCompatImageView {
|
||||
@Override
|
||||
public @NonNull FallbackAvatar getFallbackAvatar(@NonNull Recipient recipient) {
|
||||
if (recipient.isSelf()) {
|
||||
return new FallbackAvatar.Resource.Person(recipient.getAvatarColor());
|
||||
return FallbackAvatar.forTextOrDefault(recipient.getDisplayName(getContext()), recipient.getAvatarColor());
|
||||
}
|
||||
|
||||
return FallbackAvatarProvider.super.getFallbackAvatar(recipient);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.stories.landing
|
||||
|
||||
import android.view.View
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.Observer
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.avatar.view.AvatarView
|
||||
import org.thoughtcrime.securesms.components.settings.PreferenceModel
|
||||
@@ -19,6 +21,7 @@ object MyStoriesItem {
|
||||
}
|
||||
|
||||
class Model(
|
||||
val lifecycleOwner: LifecycleOwner,
|
||||
val onClick: () -> Unit
|
||||
) : PreferenceModel<Model>() {
|
||||
override fun areItemsTheSame(newItem: Model): Boolean = true
|
||||
@@ -28,9 +31,39 @@ object MyStoriesItem {
|
||||
|
||||
private val avatarView: AvatarView = itemView.findViewById(R.id.avatar)
|
||||
|
||||
private var recipient: Recipient? = null
|
||||
|
||||
private val recipientObserver = object : Observer<Recipient> {
|
||||
override fun onChanged(recipient: Recipient) {
|
||||
onRecipientChanged(recipient)
|
||||
}
|
||||
}
|
||||
|
||||
override fun bind(model: Model) {
|
||||
itemView.setOnClickListener { model.onClick() }
|
||||
avatarView.displayProfileAvatar(Recipient.self())
|
||||
observeRecipient(model.lifecycleOwner, Recipient.self())
|
||||
}
|
||||
|
||||
private fun onRecipientChanged(recipient: Recipient) {
|
||||
avatarView.displayProfileAvatar(recipient)
|
||||
}
|
||||
|
||||
private fun observeRecipient(lifecycleOwner: LifecycleOwner?, recipient: Recipient?) {
|
||||
this.recipient?.live()?.liveData?.removeObserver(recipientObserver)
|
||||
|
||||
this.recipient = recipient
|
||||
|
||||
lifecycleOwner?.let {
|
||||
this.recipient?.live()?.liveData?.observe(lifecycleOwner, recipientObserver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewRecycled() {
|
||||
unbindRecipient()
|
||||
}
|
||||
|
||||
private fun unbindRecipient() {
|
||||
observeRecipient(null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +251,7 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
|
||||
if (state.displayMyStoryItem) {
|
||||
customPref(
|
||||
MyStoriesItem.Model(
|
||||
lifecycleOwner = viewLifecycleOwner,
|
||||
onClick = {
|
||||
cameraFab.performClick()
|
||||
}
|
||||
|
||||
@@ -66,10 +66,20 @@ object StoriesLandingItem {
|
||||
data == newItem.data &&
|
||||
!hasStatusChange(newItem) &&
|
||||
!hasThumbChange(newItem) &&
|
||||
!hasSelfProfileChange(newItem) &&
|
||||
(data.sendingCount == newItem.data.sendingCount && data.failureCount == newItem.data.failureCount) &&
|
||||
data.storyViewState == newItem.data.storyViewState
|
||||
}
|
||||
|
||||
private fun hasSelfProfileChange(newItem: Model): Boolean {
|
||||
if (!data.storyRecipient.isMyStory || !newItem.data.storyRecipient.isMyStory) {
|
||||
return false
|
||||
}
|
||||
val old = data.individualRecipient
|
||||
val new = Recipient.self()
|
||||
return old.hasAvatar != new.hasAvatar || old.profileAvatarFileDetails != new.profileAvatarFileDetails || old.profileName.toString() != new.profileName.toString()
|
||||
}
|
||||
|
||||
override fun getChangePayload(newItem: Model): Any? {
|
||||
return if (isSameRecord(newItem) && hasStatusChange(newItem)) {
|
||||
STATUS_CHANGE
|
||||
|
||||
Reference in New Issue
Block a user