mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix some animations
This commit is contained in:
parent
84611c24ed
commit
c443ddb6c4
2 changed files with 18 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ import kotlin.time.Duration
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
data class AudioItem(
|
data class AudioItem(
|
||||||
|
val key: Long = keyTracker++,
|
||||||
val id: UUID,
|
val id: UUID,
|
||||||
val albumId: UUID?,
|
val albumId: UUID?,
|
||||||
val artistId: UUID?,
|
val artistId: UUID?,
|
||||||
|
|
@ -18,6 +19,8 @@ data class AudioItem(
|
||||||
val hasLyrics: Boolean,
|
val hasLyrics: Boolean,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
private var keyTracker = 0L
|
||||||
|
|
||||||
fun from(
|
fun from(
|
||||||
item: BaseItem,
|
item: BaseItem,
|
||||||
imageUrl: String?,
|
imageUrl: String?,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.compose.animation.core.animateFloatAsState
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.expandVertically
|
import androidx.compose.animation.expandVertically
|
||||||
import androidx.compose.animation.shrinkVertically
|
import androidx.compose.animation.shrinkVertically
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
|
@ -21,11 +22,11 @@ import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
|
@ -85,14 +86,10 @@ fun NowPlayingOverlay(
|
||||||
animationSpec = tween(durationMillis = 500),
|
animationSpec = tween(durationMillis = 500),
|
||||||
)
|
)
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val hideButtons by remember {
|
var showButtons by remember { mutableStateOf(true) }
|
||||||
derivedStateOf {
|
|
||||||
listState.firstVisibleItemIndex > 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val firstFocusRequester = remember { FocusRequester() }
|
val firstFocusRequester = remember { FocusRequester() }
|
||||||
BackHandler(hideButtons) {
|
BackHandler(!showButtons) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
listState.animateScrollToItem(0)
|
listState.animateScrollToItem(0)
|
||||||
firstFocusRequester.tryRequestFocus()
|
firstFocusRequester.tryRequestFocus()
|
||||||
|
|
@ -120,7 +117,7 @@ fun NowPlayingOverlay(
|
||||||
.fillMaxWidth(.95f),
|
.fillMaxWidth(.95f),
|
||||||
)
|
)
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = !hideButtons,
|
visible = showButtons,
|
||||||
enter = expandVertically(),
|
enter = expandVertically(),
|
||||||
exit = shrinkVertically(),
|
exit = shrinkVertically(),
|
||||||
modifier =
|
modifier =
|
||||||
|
|
@ -144,6 +141,7 @@ fun NowPlayingOverlay(
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.queue),
|
text = stringResource(R.string.queue),
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
)
|
)
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
state = listState,
|
state = listState,
|
||||||
|
|
@ -155,10 +153,16 @@ fun NowPlayingOverlay(
|
||||||
queueHasFocus = it.hasFocus
|
queueHasFocus = it.hasFocus
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
itemsIndexed(queue) { index, song ->
|
itemsIndexed(queue, key = { _, song -> song.key }) { index, song ->
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(
|
||||||
|
color = MaterialTheme.colorScheme.surface.copy(alpha = .75f),
|
||||||
|
shape = RoundedCornerShape(8.dp),
|
||||||
|
).animateItem(),
|
||||||
) {
|
) {
|
||||||
SongListItem(
|
SongListItem(
|
||||||
title = song.title,
|
title = song.title,
|
||||||
|
|
@ -173,6 +177,7 @@ fun NowPlayingOverlay(
|
||||||
Modifier
|
Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.onFocusChanged {
|
.onFocusChanged {
|
||||||
|
if (it.isFocused) showButtons = index < 3
|
||||||
controllerViewState.pulseControls()
|
controllerViewState.pulseControls()
|
||||||
}.ifElse(
|
}.ifElse(
|
||||||
index == 0,
|
index == 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue