impr: add animation

This commit is contained in:
Sweetbread 2025-04-23 19:55:32 +03:00
parent b6eed728e3
commit 269781586a
Signed by: Sweetbread
GPG Key ID: 17A5CB9A7DD85319

View File

@ -1,7 +1,13 @@
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
package ru.sweetbread.unn.ui.composes package ru.sweetbread.unn.ui.composes
import android.util.Log import android.util.Log
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@ -147,6 +153,8 @@ fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Bo
val now = LocalDateTime.now().atZone(ZoneId.of("Europe/Moscow")).toEpochSecond() val now = LocalDateTime.now().atZone(ZoneId.of("Europe/Moscow")).toEpochSecond()
if (begin > now) if (begin > now)
return -1f return -1f
if (now > end)
return 1f
return (now - begin) / (end - begin).toFloat() return (now - begin) / (end - begin).toFloat()
} }
@ -166,16 +174,22 @@ fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Bo
} }
} }
val backgroundColor by animateColorAsState(
targetValue = if (rel == 1f)
MaterialTheme.colorScheme.surfaceContainer
else if (rel == -1f)
MaterialTheme.colorScheme.secondaryContainer
else
MaterialTheme.colorScheme.primaryContainer,
label = "backgroundTransition"
)
Row ( Row (
modifier modifier
.fillMaxWidth() .fillMaxWidth()
.padding(4.dp) .padding(4.dp)
.clip(RoundedCornerShape(8.dp)) .clip(RoundedCornerShape(8.dp))
.background( .background(backgroundColor)
if (rel != -1f)
MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.surfaceContainer
)
.padding(8.dp) .padding(8.dp)
){ ){
Column (Modifier.weight(1f)) { Column (Modifier.weight(1f)) {
@ -268,14 +282,18 @@ fun ScheduleItem(modifier: Modifier = Modifier, unit: ScheduleUnit, expanded: Bo
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Text(begin.toString(), fontWeight = FontWeight.Bold) Text(begin.toString(), fontWeight = FontWeight.Bold)
if (rel != -1f) AnimatedVisibility ((0f < rel) and (rel < 1f)) {
DividerWithMarker( DividerWithMarker(
Modifier.weight(1f).padding(horizontal = 2.dp), Modifier
.weight(1f)
.padding(horizontal = 2.dp),
positionPercentage = rel, positionPercentage = rel,
color = MaterialTheme.colorScheme.outline, color = MaterialTheme.colorScheme.outline,
thickness = 3.dp, thickness = 3.dp,
markerSize = 8.dp, markerSize = 8.dp,
markerColor = MaterialTheme.colorScheme.primary) markerColor = MaterialTheme.colorScheme.primary
)
}
Text(end.toString()) Text(end.toString())
} }
} }