fix loading Gif avatars into the main appbar (#2268)
* fix loading Gif avatars into the main appbar and respect the animateAvatars setting closes #2259 * fix formatting
This commit is contained in:
parent
b62ccd918f
commit
6b7d3ef613
|
@ -19,7 +19,10 @@ import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.Animatable
|
||||||
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -710,34 +713,70 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
|
||||||
private fun loadDrawerAvatar(avatarUrl: String, showPlaceholder: Boolean) {
|
private fun loadDrawerAvatar(avatarUrl: String, showPlaceholder: Boolean) {
|
||||||
val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size)
|
val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size)
|
||||||
|
|
||||||
glide.asDrawable()
|
val animateAvatars = preferences.getBoolean("animateGifAvatars", false)
|
||||||
.load(avatarUrl)
|
|
||||||
.transform(
|
|
||||||
RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp))
|
|
||||||
)
|
|
||||||
.apply {
|
|
||||||
if (showPlaceholder) {
|
|
||||||
placeholder(R.drawable.avatar_default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.into(object : CustomTarget<Drawable>(navIconSize, navIconSize) {
|
|
||||||
|
|
||||||
override fun onLoadStarted(placeholder: Drawable?) {
|
if (animateAvatars) {
|
||||||
if (placeholder != null) {
|
glide.asDrawable()
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
.load(avatarUrl)
|
||||||
|
.transform(
|
||||||
|
RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp))
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
if (showPlaceholder) {
|
||||||
|
placeholder(R.drawable.avatar_default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.into(object : CustomTarget<Drawable>(navIconSize, navIconSize) {
|
||||||
|
|
||||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
override fun onLoadStarted(placeholder: Drawable?) {
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(resource, navIconSize, navIconSize)
|
if (placeholder != null) {
|
||||||
}
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||||
if (placeholder != null) {
|
if (resource is Animatable) {
|
||||||
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
resource.start()
|
||||||
|
}
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(resource, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
if (placeholder != null) {
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
glide.asBitmap()
|
||||||
|
.load(avatarUrl)
|
||||||
|
.transform(
|
||||||
|
RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp))
|
||||||
|
)
|
||||||
|
.apply {
|
||||||
|
if (showPlaceholder) {
|
||||||
|
placeholder(R.drawable.avatar_default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
.into(object : CustomTarget<Bitmap>(navIconSize, navIconSize) {
|
||||||
|
|
||||||
|
override fun onLoadStarted(placeholder: Drawable?) {
|
||||||
|
if (placeholder != null) {
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(BitmapDrawable(resources, resource), navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
if (placeholder != null) {
|
||||||
|
binding.mainToolbar.navigationIcon = FixedSizeDrawable(placeholder, navIconSize, navIconSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchAnnouncements() {
|
private fun fetchAnnouncements() {
|
||||||
|
|
Loading…
Reference in New Issue