Music widget: add album art transition
This commit is contained in:
parent
b5aa35ed70
commit
b0f9ffd473
@ -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,6 +235,21 @@ 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 ->
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 16.dp, end = 16.dp)
|
.padding(top = 16.dp, end = 16.dp)
|
||||||
@ -242,15 +264,14 @@ fun MusicWidget(widget: MusicWidget) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.conditional(
|
.conditional(
|
||||||
albumArt == null,
|
art == null,
|
||||||
Modifier.background(
|
Modifier.background(
|
||||||
MaterialTheme.colorScheme.secondaryContainer,
|
MaterialTheme.colorScheme.secondaryContainer,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
if (albumArt != null) {
|
if (art != null) {
|
||||||
albumArt?.let { art ->
|
|
||||||
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,7 +306,6 @@ fun MusicWidget(widget: MusicWidget) {
|
|||||||
}
|
}
|
||||||
return@HandleEnterHomeTransition null
|
return@HandleEnterHomeTransition null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Rounded.MusicNote,
|
imageVector = Icons.Rounded.MusicNote,
|
||||||
@ -297,6 +317,7 @@ fun MusicWidget(widget: MusicWidget) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user