Skip to content

Commit

Permalink
Fix race condition in HomeFragment causing a crash when profile pictu…
Browse files Browse the repository at this point in the history
…re loads when the view is already destroyed
  • Loading branch information
nielsvanvelzen committed May 30, 2023
1 parent 5022942 commit 570f9ec
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/org/jellyfin/androidtv/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,24 @@ class HomeFragment : Fragment() {
.circleCrop()
.into(object : CustomViewTarget<ImageButton, Drawable>(binding.switchUsers) {
override fun onLoadFailed(errorDrawable: Drawable?) {
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(errorDrawable)
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(errorDrawable)
}
}

override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
binding.switchUsers.imageTintMode = null
binding.switchUsers.setImageDrawable(resource)
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
binding.switchUsers.imageTintMode = null
binding.switchUsers.setImageDrawable(resource)
}
}

override fun onResourceCleared(placeholder: Drawable?) {
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(placeholder)
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
binding.switchUsers.imageTintMode = PorterDuff.Mode.SRC_IN
binding.switchUsers.setImageDrawable(placeholder)
}
}
})
}
Expand Down

0 comments on commit 570f9ec

Please sign in to comment.