Music widget: add album art transition

This commit is contained in:
MM20 2024-05-03 11:21:56 +02:00
parent b5aa35ed70
commit b0f9ffd473
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -4,10 +4,17 @@ import android.content.pm.PackageManager
import android.content.res.Resources import android.content.res.Resources
import android.media.session.PlaybackState.CustomAction import android.media.session.PlaybackState.CustomAction
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.SharedTransitionScope
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.graphics.res.animatedVectorResource import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.animation.scaleIn
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.basicMarquee
@ -79,8 +86,8 @@ import de.mm20.launcher2.music.SupportedActions
import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.MissingPermissionBanner import de.mm20.launcher2.ui.component.MissingPermissionBanner
import de.mm20.launcher2.ui.ktx.conditional import de.mm20.launcher2.ui.ktx.conditional
import de.mm20.launcher2.ui.launcher.transitions.HandleEnterHomeTransition
import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransitionParams import de.mm20.launcher2.ui.launcher.transitions.EnterHomeTransitionParams
import de.mm20.launcher2.ui.launcher.transitions.HandleEnterHomeTransition
import de.mm20.launcher2.ui.locals.LocalCardStyle import de.mm20.launcher2.ui.locals.LocalCardStyle
import de.mm20.launcher2.ui.locals.LocalWindowSize import de.mm20.launcher2.ui.locals.LocalWindowSize
import de.mm20.launcher2.widgets.MusicWidget import de.mm20.launcher2.widgets.MusicWidget
@ -228,29 +235,43 @@ fun MusicWidget(widget: MusicWidget) {
} }
} }
} }
Box( AnimatedContent(
modifier = Modifier albumArt,
.padding(top = 16.dp, end = 16.dp) transitionSpec = {
.size(96.dp) if (targetState != null && initialState == null) {
.clip(MaterialTheme.shapes.small) fadeIn() togetherWith fadeOut()
.combinedClickable( } else {
onClick = { (fadeIn(animationSpec = tween(220, delayMillis = 90)) +
viewModel.openPlayer() scaleIn(
}, initialScale = 0.92f,
onLongClick = { animationSpec = tween(220, delayMillis = 90)
viewModel.openPlayerSelector(context) ))
} .togetherWith(fadeOut(animationSpec = tween(90)))
) }
.conditional( }
albumArt == null, ) { art ->
Modifier.background( Box(
MaterialTheme.colorScheme.secondaryContainer, modifier = Modifier
.padding(top = 16.dp, end = 16.dp)
.size(96.dp)
.clip(MaterialTheme.shapes.small)
.combinedClickable(
onClick = {
viewModel.openPlayer()
},
onLongClick = {
viewModel.openPlayerSelector(context)
}
) )
), .conditional(
contentAlignment = Alignment.Center art == null,
) { Modifier.background(
if (albumArt != null) { MaterialTheme.colorScheme.secondaryContainer,
albumArt?.let { art -> )
),
contentAlignment = Alignment.Center
) {
if (art != null) {
val windowSize = LocalWindowSize.current val windowSize = LocalWindowSize.current
var bounds by remember { mutableStateOf(Rect.Zero) } var bounds by remember { mutableStateOf(Rect.Zero) }
Image( Image(
@ -285,14 +306,14 @@ fun MusicWidget(widget: MusicWidget) {
} }
return@HandleEnterHomeTransition null return@HandleEnterHomeTransition null
} }
} else {
Icon(
imageVector = Icons.Rounded.MusicNote,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer,
modifier = Modifier.size(48.dp)
)
} }
} else {
Icon(
imageVector = Icons.Rounded.MusicNote,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer,
modifier = Modifier.size(48.dp)
)
} }
} }
} }