Reduce profile avatar disk reads.

This commit is contained in:
Cody Henthorne
2022-07-13 14:48:25 -04:00
parent 2f17963b2b
commit 819f7a170f
16 changed files with 81 additions and 59 deletions

View File

@@ -44,7 +44,7 @@ public final class AvatarUtil {
ContactPhoto photo;
if (recipient.isSelf()) {
photo = new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar());
photo = new ProfileContactPhoto(Recipient.self());
} else if (recipient.getContactPhoto() == null) {
target.setImageDrawable(null);
target.setBackgroundColor(ContextCompat.getColor(target.getContext(), R.color.black));
@@ -150,7 +150,7 @@ public final class AvatarUtil {
private static <T> GlideRequest<T> request(@NonNull GlideRequest<T> glideRequest, @NonNull Context context, @NonNull Recipient recipient, boolean loadSelf, int targetSize) {
final ContactPhoto photo;
if (Recipient.self().equals(recipient) && loadSelf) {
photo = new ProfileContactPhoto(recipient, recipient.getProfileAvatar());
photo = new ProfileContactPhoto(recipient);
} else {
photo = recipient.getContactPhoto();
}

View File

@@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.contacts.avatars.FallbackPhoto80dp;
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.SystemContactPhoto;
import org.thoughtcrime.securesms.conversation.colors.AvatarColor;
import org.thoughtcrime.securesms.database.model.ProfileAvatarFileDetails;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.recipients.Recipient;
@@ -41,13 +42,15 @@ public final class ConversationShortcutPhoto implements Key {
*/
private static final long VERSION = 1L;
private final Recipient recipient;
private final String avatarObject;
private final Recipient recipient;
private final String avatarObject;
private final ProfileAvatarFileDetails profileAvatarFileDetails;
@WorkerThread
public ConversationShortcutPhoto(@NonNull Recipient recipient) {
this.recipient = recipient.resolve();
this.avatarObject = Util.firstNonNull(recipient.getProfileAvatar(), "");
this.recipient = recipient.resolve();
this.avatarObject = Util.firstNonNull(recipient.getProfileAvatar(), "");
this.profileAvatarFileDetails = recipient.getProfileAvatarFileDetails();
}
@Override
@@ -55,7 +58,7 @@ public final class ConversationShortcutPhoto implements Key {
messageDigest.update(recipient.getDisplayName(ApplicationDependencies.getApplication()).getBytes());
messageDigest.update(avatarObject.getBytes());
messageDigest.update(isSystemContactPhoto() ? (byte) 1 : (byte) 0);
messageDigest.update(ByteUtil.longToByteArray(getFileLastModified()));
messageDigest.update(profileAvatarFileDetails.getDiskCacheKeyBytes());
messageDigest.update(ByteUtil.longToByteArray(VERSION));
}
@@ -67,22 +70,18 @@ public final class ConversationShortcutPhoto implements Key {
return Objects.equals(recipient, that.recipient) &&
Objects.equals(avatarObject, that.avatarObject) &&
isSystemContactPhoto() == that.isSystemContactPhoto() &&
getFileLastModified() == that.getFileLastModified();
Objects.equals(profileAvatarFileDetails, that.profileAvatarFileDetails);
}
@Override
public int hashCode() {
return Objects.hash(recipient, avatarObject, isSystemContactPhoto(), getFileLastModified());
return Objects.hash(recipient, avatarObject, isSystemContactPhoto(), profileAvatarFileDetails);
}
private boolean isSystemContactPhoto() {
return recipient.getContactPhoto() instanceof SystemContactPhoto;
}
private long getFileLastModified() {
return AvatarHelper.getLastModified(ApplicationDependencies.getApplication(), recipient.getId());
}
public static final class Loader implements ModelLoader<ConversationShortcutPhoto, Bitmap> {
private final Context context;