Skip to content

Commit 300065b

Browse files
committedDec 28, 2024·
feat(schedule): favourite animes marking
1 parent 9f5d37a commit 300065b

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed
 

‎app/src/main/java/org/shirabox/app/ui/component/general/ScheduleCard.kt

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.shirabox.app.ui.component.general
22

3+
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.animation.fadeIn
5+
import androidx.compose.animation.fadeOut
36
import androidx.compose.foundation.background
47
import androidx.compose.foundation.clickable
58
import androidx.compose.foundation.layout.Arrangement
@@ -10,10 +13,14 @@ import androidx.compose.foundation.layout.FlowRow
1013
import androidx.compose.foundation.layout.fillMaxSize
1114
import androidx.compose.foundation.layout.fillMaxWidth
1215
import androidx.compose.foundation.layout.padding
16+
import androidx.compose.foundation.layout.size
1317
import androidx.compose.foundation.layout.wrapContentSize
1418
import androidx.compose.foundation.shape.RoundedCornerShape
19+
import androidx.compose.material.icons.Icons
20+
import androidx.compose.material.icons.rounded.Star
1521
import androidx.compose.material3.Card
1622
import androidx.compose.material3.CardDefaults
23+
import androidx.compose.material3.Icon
1724
import androidx.compose.material3.Surface
1825
import androidx.compose.material3.Text
1926
import androidx.compose.runtime.Composable
@@ -22,31 +29,41 @@ import androidx.compose.ui.Alignment
2229
import androidx.compose.ui.Modifier
2330
import androidx.compose.ui.graphics.Color
2431
import androidx.compose.ui.layout.ContentScale
32+
import androidx.compose.ui.res.stringResource
2533
import androidx.compose.ui.text.font.FontWeight
2634
import androidx.compose.ui.text.style.TextAlign
2735
import androidx.compose.ui.text.style.TextOverflow
2836
import androidx.compose.ui.unit.dp
2937
import androidx.compose.ui.unit.sp
38+
import androidx.hilt.navigation.compose.hiltViewModel
39+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3040
import coil.compose.AsyncImage
41+
import org.shirabox.app.ui.screen.explore.ExploreViewModel
3142
import org.shirabox.core.model.ScheduleEntry
3243
import org.shirabox.core.util.getDuration
44+
import org.shirabox.app.R
3345

3446
@OptIn(ExperimentalLayoutApi::class)
3547
@Composable
3648
fun ScheduleCard(
3749
modifier: Modifier = Modifier,
3850
scheduleEntry: ScheduleEntry,
51+
model: ExploreViewModel = hiltViewModel(),
3952
onClick: () -> Unit
4053
) {
4154
val time = remember(scheduleEntry) {
4255
val firstTimeLabel = scheduleEntry.releaseRange.first().getDuration()
43-
val secondTimeLabel = scheduleEntry.releaseRange.getOrNull(1)?.let {
44-
it.getDuration()
45-
}
56+
val secondTimeLabel = scheduleEntry.releaseRange.getOrNull(1)?.getDuration()
4657

4758
firstTimeLabel.plus(secondTimeLabel?.let { " - $it" })
4859
}
4960

61+
val cachedContentState = model.cachedContentFlow(scheduleEntry.id).collectAsStateWithLifecycle(null)
62+
63+
val isFavourite = remember(cachedContentState.value) {
64+
cachedContentState.value?.isFavourite == true
65+
}
66+
5067
Surface(
5168
modifier = modifier,
5269
shape = RoundedCornerShape(10),
@@ -71,24 +88,38 @@ fun ScheduleCard(
7188
verticalArrangement = Arrangement.SpaceBetween,
7289
horizontalAlignment = Alignment.Start
7390
) {
74-
FlowRow(
75-
modifier = Modifier
76-
.fillMaxWidth()
77-
.padding(16.dp),
78-
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.End),
79-
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
91+
Column(
92+
modifier = Modifier.padding(16.dp),
93+
horizontalAlignment = Alignment.End,
94+
verticalArrangement = Arrangement.spacedBy(8.dp)
8095
) {
81-
if(!scheduleEntry.released) {
96+
FlowRow(
97+
modifier = Modifier
98+
.fillMaxWidth(),
99+
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.End),
100+
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
101+
) {
102+
if(!scheduleEntry.released) {
103+
ScheduleCardBadge(
104+
text = time,
105+
color = Color(0xFF6750A4)
106+
)
107+
}
108+
82109
ScheduleCardBadge(
83-
text = time,
84-
color = Color(0xFF6750A4)
110+
text = stringResource(R.string.schedule_episode, scheduleEntry.nextEpisodeNumber),
111+
color = if (scheduleEntry.released) Color(0xFF7BC251) else Color(0xFF323232)
85112
)
86113
}
87114

88-
ScheduleCardBadge(
89-
text = "Серия ${scheduleEntry.nextEpisodeNumber}",
90-
color = if (scheduleEntry.released) Color(0xFF7BC251) else Color(0xFF323232)
91-
)
115+
AnimatedVisibility(visible = isFavourite, enter = fadeIn(), exit = fadeOut()) {
116+
Icon(
117+
modifier = Modifier.size(22.dp),
118+
imageVector = Icons.Rounded.Star,
119+
contentDescription = "favourite",
120+
tint = Color(0xFFFFD700)
121+
)
122+
}
92123
}
93124

94125
Column(

‎app/src/main/java/org/shirabox/app/ui/screen/explore/ExploreViewModel.kt

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class ExploreViewModel @Inject constructor(@ApplicationContext context: Context)
122122
}
123123
}
124124

125+
fun cachedContentFlow(id: Int) = db.contentDao().getContentByShiraboxId(id)
126+
125127
fun refresh(coldStartCheck: Boolean) {
126128
viewModelScope.launch(Dispatchers.IO) {
127129
/**

‎app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<string name="schedule_dialog_title">Как работает расписание?</string>
4646
<string name="schedule_dialog_text">В этом разделе ты сможешь узнать, когда на этой неделе выйдет следующая серия любимого аниме. \n\nВремя выхода серий ориентировочное, отображено согласно московскому времени (MSK) и не может соответствовать времени выхода конкретной озвучки. Поэтому стоить проявить терпение! \n\nСерии, которые ещё не успели выйти помечены серым цветом, когда в свою очередь те что уже вышли помечены зелёным. Всё просто!</string>
4747
<string name="schedule_dialog_confirm">Понятно!</string>
48+
<string name="schedule_episode">Серия %d</string>
4849

4950
<!--
5051
Favourites Screen

‎core/src/main/java/org/shirabox/core/db/dao/ContentDao.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface ContentDao {
3535
fun getContentByUid(uid: Long): ContentEntity
3636

3737
@Query("SELECT * FROM content WHERE shirabox_id IS :shiraboxId")
38-
fun getContentByShiraboxId(shiraboxId: Int): ContentEntity
38+
fun getContentByShiraboxId(shiraboxId: Int): Flow<ContentEntity>
3939

4040
@Insert(onConflict = OnConflictStrategy.ABORT)
4141
fun insertContents(vararg contents: ContentEntity): List<Long>

0 commit comments

Comments
 (0)
Please sign in to comment.