Fix album cover jank (#1658)
* fix album cover jank * reduce album resolution
This commit is contained in:
@@ -229,21 +229,7 @@ fun MusicWidget(widget: MusicWidget) {
|
||||
}
|
||||
}
|
||||
}
|
||||
AnimatedContent(
|
||||
albumArt,
|
||||
transitionSpec = {
|
||||
if (targetState != null && initialState == null) {
|
||||
fadeIn() togetherWith fadeOut()
|
||||
} else {
|
||||
(fadeIn(animationSpec = tween(220, delayMillis = 90)) +
|
||||
scaleIn(
|
||||
initialScale = 0.92f,
|
||||
animationSpec = tween(220, delayMillis = 90)
|
||||
))
|
||||
.togetherWith(fadeOut(animationSpec = tween(90)))
|
||||
}
|
||||
}
|
||||
) { art ->
|
||||
AnimatedContent(albumArt) { art ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(top = 16.dp, end = 16.dp)
|
||||
|
||||
@@ -14,6 +14,7 @@ import de.mm20.launcher2.music.SupportedActions
|
||||
import de.mm20.launcher2.permissions.PermissionGroup
|
||||
import de.mm20.launcher2.permissions.PermissionsManager
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@@ -23,7 +24,7 @@ class MusicWidgetVM: ViewModel(), KoinComponent {
|
||||
|
||||
val title: Flow<String?> = musicService.title
|
||||
val artist: Flow<String?> = musicService.artist
|
||||
val albumArt: Flow<Bitmap?> = musicService.albumArt
|
||||
val albumArt: Flow<Bitmap?> = musicService.albumArt.debounce { if (it == null) 500 else 0L }
|
||||
val playbackState: Flow<PlaybackState> = musicService.playbackState
|
||||
val duration: Flow<Long?> = musicService.duration
|
||||
val position: Flow<Long?> = musicService.position
|
||||
|
||||
@@ -320,6 +320,7 @@ internal class MusicServiceImpl(
|
||||
|
||||
override val albumArt: Flow<Bitmap?> = channelFlow {
|
||||
val size = context.resources.getDimensionPixelSize(R.dimen.album_art_size)
|
||||
var lastBitmap: Bitmap? = null
|
||||
currentMetadata.collectLatest { metadata ->
|
||||
if (metadata == null) {
|
||||
val isNull = preferences.getString(PREFS_KEY_ALBUM_ART, "null") == "null"
|
||||
@@ -345,6 +346,9 @@ internal class MusicServiceImpl(
|
||||
?.let { loadBitmapFromUri(Uri.parse(it), size) }
|
||||
?: metadata.getString(MediaMetadata.METADATA_KEY_ART_URI)
|
||||
?.let { loadBitmapFromUri(Uri.parse(it), size) }
|
||||
|
||||
if (lastBitmap != null && lastBitmap!!.sameAs(bitmap))
|
||||
return@collectLatest
|
||||
withContext(Dispatchers.IO) {
|
||||
if (bitmap == null) {
|
||||
preferences.edit {
|
||||
@@ -359,6 +363,7 @@ internal class MusicServiceImpl(
|
||||
}
|
||||
}
|
||||
send(bitmap)
|
||||
lastBitmap = bitmap
|
||||
}
|
||||
}.shareIn(scope, SharingStarted.WhileSubscribed(), 1)
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<dimen name="album_art_size">144dp</dimen>
|
||||
<dimen name="album_art_size">96dp</dimen>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user