From 300065b7764b4a077e27255b05ec9d08dc114e2f Mon Sep 17 00:00:00 2001 From: urFate Date: Sat, 28 Dec 2024 17:17:47 +0300 Subject: [PATCH] feat(schedule): favourite animes marking --- .../app/ui/component/general/ScheduleCard.kt | 63 ++++++++++++++----- .../app/ui/screen/explore/ExploreViewModel.kt | 2 + app/src/main/res/values/strings.xml | 1 + .../org/shirabox/core/db/dao/ContentDao.kt | 2 +- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/shirabox/app/ui/component/general/ScheduleCard.kt b/app/src/main/java/org/shirabox/app/ui/component/general/ScheduleCard.kt index 2c790c9..65cac2d 100644 --- a/app/src/main/java/org/shirabox/app/ui/component/general/ScheduleCard.kt +++ b/app/src/main/java/org/shirabox/app/ui/component/general/ScheduleCard.kt @@ -1,5 +1,8 @@ package org.shirabox.app.ui.component.general +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -10,10 +13,14 @@ import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Star import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -22,31 +29,41 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import coil.compose.AsyncImage +import org.shirabox.app.ui.screen.explore.ExploreViewModel import org.shirabox.core.model.ScheduleEntry import org.shirabox.core.util.getDuration +import org.shirabox.app.R @OptIn(ExperimentalLayoutApi::class) @Composable fun ScheduleCard( modifier: Modifier = Modifier, scheduleEntry: ScheduleEntry, + model: ExploreViewModel = hiltViewModel(), onClick: () -> Unit ) { val time = remember(scheduleEntry) { val firstTimeLabel = scheduleEntry.releaseRange.first().getDuration() - val secondTimeLabel = scheduleEntry.releaseRange.getOrNull(1)?.let { - it.getDuration() - } + val secondTimeLabel = scheduleEntry.releaseRange.getOrNull(1)?.getDuration() firstTimeLabel.plus(secondTimeLabel?.let { " - $it" }) } + val cachedContentState = model.cachedContentFlow(scheduleEntry.id).collectAsStateWithLifecycle(null) + + val isFavourite = remember(cachedContentState.value) { + cachedContentState.value?.isFavourite == true + } + Surface( modifier = modifier, shape = RoundedCornerShape(10), @@ -71,24 +88,38 @@ fun ScheduleCard( verticalArrangement = Arrangement.SpaceBetween, horizontalAlignment = Alignment.Start ) { - FlowRow( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.End), - verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically) + Column( + modifier = Modifier.padding(16.dp), + horizontalAlignment = Alignment.End, + verticalArrangement = Arrangement.spacedBy(8.dp) ) { - if(!scheduleEntry.released) { + FlowRow( + modifier = Modifier + .fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.End), + verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically) + ) { + if(!scheduleEntry.released) { + ScheduleCardBadge( + text = time, + color = Color(0xFF6750A4) + ) + } + ScheduleCardBadge( - text = time, - color = Color(0xFF6750A4) + text = stringResource(R.string.schedule_episode, scheduleEntry.nextEpisodeNumber), + color = if (scheduleEntry.released) Color(0xFF7BC251) else Color(0xFF323232) ) } - ScheduleCardBadge( - text = "Серия ${scheduleEntry.nextEpisodeNumber}", - color = if (scheduleEntry.released) Color(0xFF7BC251) else Color(0xFF323232) - ) + AnimatedVisibility(visible = isFavourite, enter = fadeIn(), exit = fadeOut()) { + Icon( + modifier = Modifier.size(22.dp), + imageVector = Icons.Rounded.Star, + contentDescription = "favourite", + tint = Color(0xFFFFD700) + ) + } } Column( diff --git a/app/src/main/java/org/shirabox/app/ui/screen/explore/ExploreViewModel.kt b/app/src/main/java/org/shirabox/app/ui/screen/explore/ExploreViewModel.kt index 768d8f7..38e3739 100644 --- a/app/src/main/java/org/shirabox/app/ui/screen/explore/ExploreViewModel.kt +++ b/app/src/main/java/org/shirabox/app/ui/screen/explore/ExploreViewModel.kt @@ -122,6 +122,8 @@ class ExploreViewModel @Inject constructor(@ApplicationContext context: Context) } } + fun cachedContentFlow(id: Int) = db.contentDao().getContentByShiraboxId(id) + fun refresh(coldStartCheck: Boolean) { viewModelScope.launch(Dispatchers.IO) { /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 85a0458..6501bd7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,6 +45,7 @@ Как работает расписание? В этом разделе ты сможешь узнать, когда на этой неделе выйдет следующая серия любимого аниме. \n\nВремя выхода серий ориентировочное, отображено согласно московскому времени (MSK) и не может соответствовать времени выхода конкретной озвучки. Поэтому стоить проявить терпение! \n\nСерии, которые ещё не успели выйти помечены серым цветом, когда в свою очередь те что уже вышли помечены зелёным. Всё просто! Понятно! + Серия %d