fix crash when clearing glide requests (#1989)

This commit is contained in:
Konrad Pozniak 2020-11-22 19:03:11 +01:00 committed by GitHub
parent 34fb546200
commit 9ea2557148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -38,6 +38,7 @@ import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.viewpager2.widget.MarginPageTransformer import androidx.viewpager2.widget.MarginPageTransformer
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.target.FixedSizeDrawable import com.bumptech.glide.request.target.FixedSizeDrawable
@ -105,6 +106,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) }
private lateinit var glide: RequestManager
private val emojiInitCallback = object : InitCallback() { private val emojiInitCallback = object : InitCallback() {
override fun onInitialized() { override fun onInitialized() {
if (!isDestroyed) { if (!isDestroyed) {
@ -168,6 +171,9 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
} }
window.statusBarColor = Color.TRANSPARENT // don't draw a status bar, the DrawerLayout and the MaterialDrawerLayout have their own window.statusBarColor = Color.TRANSPARENT // don't draw a status bar, the DrawerLayout and the MaterialDrawerLayout have their own
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
glide = Glide.with(this)
composeButton.setOnClickListener { composeButton.setOnClickListener {
val composeIntent = Intent(applicationContext, ComposeActivity::class.java) val composeIntent = Intent(applicationContext, ComposeActivity::class.java)
startActivity(composeIntent) startActivity(composeIntent)
@ -328,13 +334,11 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
DrawerImageLoader.init(object : AbstractDrawerImageLoader() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
if (animateAvatars) { if (animateAvatars) {
Glide.with(imageView.context) glide.load(uri)
.load(uri)
.placeholder(placeholder) .placeholder(placeholder)
.into(imageView) .into(imageView)
} else { } else {
Glide.with(imageView.context) glide.asBitmap()
.asBitmap()
.load(uri) .load(uri)
.placeholder(placeholder) .placeholder(placeholder)
.into(imageView) .into(imageView)
@ -342,7 +346,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
} }
override fun cancel(imageView: ImageView) { override fun cancel(imageView: ImageView) {
Glide.with(imageView.context).clear(imageView) glide.clear(imageView)
} }
override fun placeholder(ctx: Context, tag: String?): Drawable { override fun placeholder(ctx: Context, tag: String?): Drawable {
@ -630,15 +634,13 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
} }
private fun onFetchUserInfoSuccess(me: Account) { private fun onFetchUserInfoSuccess(me: Account) {
Glide.with(this) glide.asBitmap()
.asBitmap()
.load(me.header) .load(me.header)
.into(header.accountHeaderBackground) .into(header.accountHeaderBackground)
val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size) val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size)
Glide.with(this) glide.asDrawable()
.asDrawable()
.override(navIconSize) .override(navIconSize)
.load(me.avatar) .load(me.avatar)
.transform( .transform(