diff --git a/app/src/main/java/im/vector/riotredesign/core/glide/MyAppGlideModule.java b/app/src/main/java/im/vector/riotredesign/core/glide/MyAppGlideModule.java index f88d4f80e7..08fed579b1 100644 --- a/app/src/main/java/im/vector/riotredesign/core/glide/MyAppGlideModule.java +++ b/app/src/main/java/im/vector/riotredesign/core/glide/MyAppGlideModule.java @@ -16,8 +16,19 @@ package im.vector.riotredesign.core.glide; +import android.content.Context; +import android.util.Log; + +import com.bumptech.glide.GlideBuilder; import com.bumptech.glide.annotation.GlideModule; import com.bumptech.glide.module.AppGlideModule; @GlideModule -public final class MyAppGlideModule extends AppGlideModule {} \ No newline at end of file +public final class MyAppGlideModule extends AppGlideModule { + + @Override + public void applyOptions(Context context, GlideBuilder builder) { + builder.setLogLevel(Log.ERROR); + } + +} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt b/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt index 275d76136e..373c6fc689 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/AvatarRenderer.kt @@ -19,11 +19,10 @@ package im.vector.riotredesign.features.home import android.content.Context import android.graphics.drawable.Drawable import android.widget.ImageView +import androidx.annotation.AnyThread import androidx.annotation.UiThread -import androidx.annotation.WorkerThread import androidx.core.content.ContextCompat import com.amulyakhare.textdrawable.TextDrawable -import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.DrawableImageViewTarget import com.bumptech.glide.request.target.Target @@ -40,8 +39,11 @@ import im.vector.riotredesign.core.glide.GlideRequests /** * This helper centralise ways to retrieve avatar into ImageView or even generic Target */ + object AvatarRenderer { + private const val THUMBNAIL_SIZE = 250 + @UiThread fun render(roomMember: RoomMember, imageView: ImageView) { render(roomMember.avatarUrl, roomMember.displayName, imageView) @@ -54,7 +56,7 @@ object AvatarRenderer { @UiThread fun render(avatarUrl: String?, name: String?, imageView: ImageView) { - render(imageView.context, GlideApp.with(imageView), avatarUrl, name, imageView.height, DrawableImageViewTarget(imageView)) + render(imageView.context, GlideApp.with(imageView), avatarUrl, name, DrawableImageViewTarget(imageView)) } @UiThread @@ -62,45 +64,18 @@ object AvatarRenderer { glideRequest: GlideRequests, avatarUrl: String?, name: String?, - size: Int, target: Target) { if (name.isNullOrEmpty()) { return } - val placeholder = buildPlaceholderDrawable(context, name) - buildGlideRequest(glideRequest, avatarUrl, size) + val placeholder = getPlaceholderDrawable(context, name) + buildGlideRequest(glideRequest, avatarUrl) .placeholder(placeholder) .into(target) } - @WorkerThread - fun getCachedOrPlaceholder(context: Context, - glideRequest: GlideRequests, - avatarUrl: String?, - text: String, - size: Int): Drawable { - val future = buildGlideRequest(glideRequest, avatarUrl, size).onlyRetrieveFromCache(true).submit() - return try { - future.get() - } catch (exception: Exception) { - buildPlaceholderDrawable(context, text) - } - } - - // PRIVATE API ********************************************************************************* - - private fun buildGlideRequest(glideRequest: GlideRequests, avatarUrl: String?, size: Int): GlideRequest { - val resolvedUrl = Matrix.getInstance().currentSession - .contentUrlResolver() - .resolveThumbnail(avatarUrl, size, size, ContentUrlResolver.ThumbnailMethod.SCALE) - - return glideRequest - .load(resolvedUrl) - .apply(RequestOptions.circleCropTransform()) - .diskCacheStrategy(DiskCacheStrategy.DATA) - } - - private fun buildPlaceholderDrawable(context: Context, text: String): Drawable { + @AnyThread + fun getPlaceholderDrawable(context: Context, text: String): Drawable { val avatarColor = ContextCompat.getColor(context, R.color.pale_teal) return if (text.isEmpty()) { TextDrawable.builder().buildRound("", avatarColor) @@ -113,4 +88,15 @@ object AvatarRenderer { } + // PRIVATE API ********************************************************************************* + + private fun buildGlideRequest(glideRequest: GlideRequests, avatarUrl: String?): GlideRequest { + val resolvedUrl = Matrix.getInstance().currentSession.contentUrlResolver() + .resolveThumbnail(avatarUrl, THUMBNAIL_SIZE, THUMBNAIL_SIZE, ContentUrlResolver.ThumbnailMethod.SCALE) + + return glideRequest + .load(resolvedUrl) + .apply(RequestOptions.circleCropTransform()) + } + } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/html/PillImageSpan.kt b/app/src/main/java/im/vector/riotredesign/features/html/PillImageSpan.kt index 3f48043dee..a51894946f 100644 --- a/app/src/main/java/im/vector/riotredesign/features/html/PillImageSpan.kt +++ b/app/src/main/java/im/vector/riotredesign/features/html/PillImageSpan.kt @@ -37,8 +37,6 @@ import java.lang.ref.WeakReference * It's needed to call [bind] method to start requesting avatar, otherwise only the placeholder icon will be displayed if not already cached. */ -private const val PILL_AVATAR_SIZE = 80 - class PillImageSpan(private val glideRequests: GlideRequests, private val context: Context, private val userId: String, @@ -55,7 +53,7 @@ class PillImageSpan(private val glideRequests: GlideRequests, @UiThread fun bind(textView: TextView) { tv = WeakReference(textView) - AvatarRenderer.render(context, glideRequests, user?.avatarUrl, displayName, PILL_AVATAR_SIZE, target) + AvatarRenderer.render(context, glideRequests, user?.avatarUrl, displayName, target) } // ReplacementSpan ***************************************************************************** @@ -108,7 +106,7 @@ class PillImageSpan(private val glideRequests: GlideRequests, textStartPadding = textPadding setChipMinHeightResource(R.dimen.pill_min_height) setChipIconSizeResource(R.dimen.pill_avatar_size) - chipIcon = AvatarRenderer.getCachedOrPlaceholder(context, glideRequests, user?.avatarUrl, displayName, PILL_AVATAR_SIZE) + chipIcon = AvatarRenderer.getPlaceholderDrawable(context, displayName) setBounds(0, 0, intrinsicWidth, intrinsicHeight) } }