Fix memory leak with PlayPauseButton
Fix a memory leak in PlayPauseButton that occured from not clearing an animation listener when done with it.
This commit is contained in:
parent
2203018947
commit
cccf6ba9f8
4 changed files with 15 additions and 13 deletions
|
@ -52,7 +52,7 @@ fun ImageView.bindGenreImage(genre: Genre) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom extension function similar to the stock coil load extensions, but handles whether
|
* Custom extension function similar to the stock coil load extensions, but handles whether
|
||||||
* to even show images and custom fetchers.
|
* to show images and custom fetchers.
|
||||||
*/
|
*/
|
||||||
inline fun <reified T : Any> ImageView.load(
|
inline fun <reified T : Any> ImageView.load(
|
||||||
data: T,
|
data: T,
|
||||||
|
@ -80,9 +80,9 @@ inline fun <reified T : Any> ImageView.load(
|
||||||
// --- OTHER FUNCTIONS ---
|
// --- OTHER FUNCTIONS ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a bitmap for a [song]. [onDone] will be called when the bitmap is loaded.
|
* Get a bitmap for a [song]. [onDone] will be called with the loaded bitmap, or null if loading
|
||||||
|
* failed/shouldn't occur.
|
||||||
* **This not meant for UIs, instead use the Binding Adapters.**
|
* **This not meant for UIs, instead use the Binding Adapters.**
|
||||||
* @param onDone What to do with the bitmap when the loading is finished. Bitmap will be null if loading failed/shouldn't occur.
|
|
||||||
*/
|
*/
|
||||||
fun loadBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
fun loadBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
||||||
val settingsManager = SettingsManager.getInstance()
|
val settingsManager = SettingsManager.getInstance()
|
||||||
|
|
|
@ -80,11 +80,11 @@ class CompactPlaybackFragment : Fragment() {
|
||||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||||
if (it) {
|
if (it) {
|
||||||
binding.playbackPlayPause.showPause(playbackModel.canAnimate)
|
binding.playbackPlayPause.showPause(playbackModel.canAnimate)
|
||||||
playbackModel.enableAnimation()
|
|
||||||
} else {
|
} else {
|
||||||
binding.playbackPlayPause.showPlay(playbackModel.canAnimate)
|
binding.playbackPlayPause.showPlay(playbackModel.canAnimate)
|
||||||
playbackModel.enableAnimation()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playbackModel.enableAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,6 @@ class PlayPauseButton @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hack that fixes an issue where a seam will display on the play button on certain display
|
|
||||||
* sizes due to floating point precision problems (Gotta love IEEE 754)
|
|
||||||
* This is done by detecting when the animation has ended and then reverting this
|
|
||||||
* view to the normal static image. Not possible below API 23 though.
|
|
||||||
*/
|
|
||||||
@RequiresApi(Build.VERSION_CODES.M)
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
private fun fixSeams() {
|
private fun fixSeams() {
|
||||||
iconPauseToPlay.registerAnimationCallback(object : Animatable2.AnimationCallback() {
|
iconPauseToPlay.registerAnimationCallback(object : Animatable2.AnimationCallback() {
|
||||||
|
@ -59,4 +53,12 @@ class PlayPauseButton @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
iconPauseToPlay.clearAnimationCallbacks()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,12 +193,12 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
if (it) {
|
if (it) {
|
||||||
binding.playbackPlayPause.showPause(playbackModel.canAnimate)
|
binding.playbackPlayPause.showPause(playbackModel.canAnimate)
|
||||||
binding.playbackPlayPause.backgroundTintList = accentColor
|
binding.playbackPlayPause.backgroundTintList = accentColor
|
||||||
playbackModel.enableAnimation()
|
|
||||||
} else {
|
} else {
|
||||||
binding.playbackPlayPause.showPlay(playbackModel.canAnimate)
|
binding.playbackPlayPause.showPlay(playbackModel.canAnimate)
|
||||||
binding.playbackPlayPause.backgroundTintList = controlColor
|
binding.playbackPlayPause.backgroundTintList = controlColor
|
||||||
playbackModel.enableAnimation()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playbackModel.enableAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue