use avatar version of conversations to avoid unnecessary reloading/flickering

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-04-30 16:44:50 +02:00
parent 0b5f38f232
commit d560a4a2a9
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 23 additions and 14 deletions

View File

@ -181,7 +181,7 @@ class ConversationItem(
ConversationType.ROOM_GROUP_CALL, ConversationType.ROOM_GROUP_CALL,
ConversationType.FORMER_ONE_TO_ONE, ConversationType.FORMER_ONE_TO_ONE,
ConversationType.ROOM_PUBLIC_CALL -> ConversationType.ROOM_PUBLIC_CALL ->
holder.binding.dialogAvatar.loadConversationAvatar(user, model, isInitialLoad) holder.binding.dialogAvatar.loadConversationAvatar(user, model)
else -> holder.binding.dialogAvatar.visibility = View.GONE else -> holder.binding.dialogAvatar.visibility = View.GONE
} }

View File

@ -1000,10 +1000,11 @@ class ChatActivity :
true true
) )
} else if (isGroupConversation() || isPublicConversation()) { } else if (isGroupConversation() || isPublicConversation()) {
url = ApiUtils.getUrlForConversationAvatar( url = ApiUtils.getUrlForConversationAvatarWithVersion(
1, 1,
conversationUser!!.baseUrl, conversationUser!!.baseUrl,
currentConversation!!.token currentConversation!!.token,
currentConversation!!.avatarVersion
) )
} }

View File

@ -807,7 +807,7 @@ class ConversationInfoActivity :
} }
Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> { Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> {
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, true) binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!)
} }
Conversation.ConversationType.ROOM_SYSTEM -> { Conversation.ConversationType.ROOM_SYSTEM -> {

View File

@ -359,7 +359,7 @@ class ConversationInfoEditActivity :
} }
Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> { Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> {
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, true) binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!)
} }
Conversation.ConversationType.ROOM_SYSTEM -> { Conversation.ConversationType.ROOM_SYSTEM -> {

View File

@ -54,14 +54,14 @@ private const val TAG = "ImageViewExtensions"
fun ImageView.loadConversationAvatar( fun ImageView.loadConversationAvatar(
user: User, user: User,
conversation: Conversation, conversation: Conversation
replace: Boolean
): io.reactivex.disposables ): io.reactivex.disposables
.Disposable { .Disposable {
val imageRequestUri = ApiUtils.getUrlForConversationAvatar( val imageRequestUri = ApiUtils.getUrlForConversationAvatarWithVersion(
1, 1,
user.baseUrl, user.baseUrl,
conversation.token conversation.token,
conversation.avatarVersion
) )
// these placeholders are only used when the request fails completely. The server also return default avatars // these placeholders are only used when the request fails completely. The server also return default avatars
@ -77,7 +77,7 @@ fun ImageView.loadConversationAvatar(
else -> ContextCompat.getDrawable(context, R.drawable.account_circle_96dp) else -> ContextCompat.getDrawable(context, R.drawable.account_circle_96dp)
} }
return loadAvatarInternal(user, imageRequestUri, replace, placeholder) return loadAvatarInternal(user, imageRequestUri, false, placeholder)
} }
fun ImageView.loadUserAvatar( fun ImageView.loadUserAvatar(
@ -100,17 +100,17 @@ fun ImageView.loadUserAvatar(
private fun ImageView.loadAvatarInternal( private fun ImageView.loadAvatarInternal(
user: User?, user: User?,
url: String, url: String,
replace: Boolean, ignoreCache: Boolean,
placeholder: Drawable? placeholder: Drawable?
): io.reactivex.disposables ): io.reactivex.disposables
.Disposable { .Disposable {
val cachePolicy = if (replace) { val cachePolicy = if (ignoreCache) {
CachePolicy.WRITE_ONLY CachePolicy.WRITE_ONLY
} else { } else {
CachePolicy.ENABLED CachePolicy.ENABLED
} }
if (replace && this.result is SuccessResult) { if (ignoreCache && this.result is SuccessResult) {
val result = this.result as SuccessResult val result = this.result as SuccessResult
val memoryCacheKey = result.memoryCacheKey val memoryCacheKey = result.memoryCacheKey
val memoryCache = context.imageLoader.memoryCache val memoryCache = context.imageLoader.memoryCache

View File

@ -143,7 +143,10 @@ data class Conversation(
var statusClearAt: Long? = 0, var statusClearAt: Long? = 0,
@JsonField(name = ["callRecording"]) @JsonField(name = ["callRecording"])
var callRecording: Int = 0 var callRecording: Int = 0,
@JsonField(name = ["avatarVersion"])
var avatarVersion: String? = null
) : Parcelable { ) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'

View File

@ -379,6 +379,11 @@ public class ApiUtils {
return getUrlForRoom(version, baseUrl, token) + "/avatar"; return getUrlForRoom(version, baseUrl, token) + "/avatar";
} }
public static String getUrlForConversationAvatarWithVersion(int version, String baseUrl, String token,
String avatarVersion) {
return getUrlForRoom(version, baseUrl, token) + "/avatar?avatarVersion=" + avatarVersion;
}
public static String getCredentials(String username, String token) { public static String getCredentials(String username, String token) {
if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) { if (TextUtils.isEmpty(username) && TextUtils.isEmpty(token)) {
return null; return null;