Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent MainActivity from leaking through the DrawerImageLoader singleton #4153

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import androidx.preference.PreferenceManager
import androidx.viewpager2.widget.MarginPageTransformer
import at.connyduck.calladapter.networkresult.fold
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.target.FixedSizeDrawable
Expand Down Expand Up @@ -174,8 +173,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje

private val preferences by unsafeLazy { PreferenceManager.getDefaultSharedPreferences(this) }

private lateinit var glide: RequestManager

// We need to know if the emoji pack has been changed
private var selectedEmojiPack: String? = null

Expand All @@ -187,7 +184,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje

private var directMessageTab: TabLayout.Tab? = null

@Suppress("DEPRECATION")
@SuppressLint("RestrictedApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -266,8 +262,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
window.statusBarColor = Color.TRANSPARENT // don't draw a status bar, the DrawerLayout and the MaterialDrawerLayout have their own
setContentView(binding.root)

glide = Glide.with(this)

binding.composeButton.setOnClickListener {
val composeIntent = Intent(applicationContext, ComposeActivity::class.java)
startActivity(composeIntent)
Expand Down Expand Up @@ -562,19 +556,21 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
if (animateAvatars) {
glide.load(uri)
Glide.with(imageView)
.load(uri)
.placeholder(placeholder)
.into(imageView)
} else {
glide.asBitmap()
Glide.with(imageView)
.asBitmap()
.load(uri)
.placeholder(placeholder)
.into(imageView)
}
}

override fun cancel(imageView: ImageView) {
glide.clear(imageView)
Glide.with(imageView).clear(imageView)
}

override fun placeholder(ctx: Context, tag: String?): Drawable {
Expand Down Expand Up @@ -979,7 +975,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
}

private fun onFetchUserInfoSuccess(me: Account) {
glide.asBitmap()
Glide.with(header.accountHeaderBackground)
.asBitmap()
.load(me.header)
.into(header.accountHeaderBackground)

Expand Down Expand Up @@ -1021,7 +1018,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
val navIconSize = resources.getDimensionPixelSize(R.dimen.avatar_toolbar_nav_icon_size)

if (animateAvatars) {
glide.asDrawable().load(avatarUrl).transform(RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)))
Glide.with(this)
.asDrawable()
.load(avatarUrl)
.transform(RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)))
.apply {
if (showPlaceholder) placeholder(R.drawable.avatar_default)
}
Expand All @@ -1048,7 +1048,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
}
})
} else {
glide.asBitmap().load(avatarUrl).transform(RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)))
Glide.with(this)
.asBitmap()
.load(avatarUrl)
.transform(RoundedCorners(resources.getDimensionPixelSize(R.dimen.avatar_radius_36dp)))
.apply {
if (showPlaceholder) placeholder(R.drawable.avatar_default)
}
Expand Down