1
1
package org.shirabox.app.ui.component.general
2
2
3
+ import androidx.compose.animation.AnimatedVisibility
4
+ import androidx.compose.animation.fadeIn
5
+ import androidx.compose.animation.fadeOut
3
6
import androidx.compose.foundation.background
4
7
import androidx.compose.foundation.clickable
5
8
import androidx.compose.foundation.layout.Arrangement
@@ -10,10 +13,14 @@ import androidx.compose.foundation.layout.FlowRow
10
13
import androidx.compose.foundation.layout.fillMaxSize
11
14
import androidx.compose.foundation.layout.fillMaxWidth
12
15
import androidx.compose.foundation.layout.padding
16
+ import androidx.compose.foundation.layout.size
13
17
import androidx.compose.foundation.layout.wrapContentSize
14
18
import androidx.compose.foundation.shape.RoundedCornerShape
19
+ import androidx.compose.material.icons.Icons
20
+ import androidx.compose.material.icons.rounded.Star
15
21
import androidx.compose.material3.Card
16
22
import androidx.compose.material3.CardDefaults
23
+ import androidx.compose.material3.Icon
17
24
import androidx.compose.material3.Surface
18
25
import androidx.compose.material3.Text
19
26
import androidx.compose.runtime.Composable
@@ -22,31 +29,41 @@ import androidx.compose.ui.Alignment
22
29
import androidx.compose.ui.Modifier
23
30
import androidx.compose.ui.graphics.Color
24
31
import androidx.compose.ui.layout.ContentScale
32
+ import androidx.compose.ui.res.stringResource
25
33
import androidx.compose.ui.text.font.FontWeight
26
34
import androidx.compose.ui.text.style.TextAlign
27
35
import androidx.compose.ui.text.style.TextOverflow
28
36
import androidx.compose.ui.unit.dp
29
37
import androidx.compose.ui.unit.sp
38
+ import androidx.hilt.navigation.compose.hiltViewModel
39
+ import androidx.lifecycle.compose.collectAsStateWithLifecycle
30
40
import coil.compose.AsyncImage
41
+ import org.shirabox.app.ui.screen.explore.ExploreViewModel
31
42
import org.shirabox.core.model.ScheduleEntry
32
43
import org.shirabox.core.util.getDuration
44
+ import org.shirabox.app.R
33
45
34
46
@OptIn(ExperimentalLayoutApi ::class )
35
47
@Composable
36
48
fun ScheduleCard (
37
49
modifier : Modifier = Modifier ,
38
50
scheduleEntry : ScheduleEntry ,
51
+ model : ExploreViewModel = hiltViewModel(),
39
52
onClick : () -> Unit
40
53
) {
41
54
val time = remember(scheduleEntry) {
42
55
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()
46
57
47
58
firstTimeLabel.plus(secondTimeLabel?.let { " - $it " })
48
59
}
49
60
61
+ val cachedContentState = model.cachedContentFlow(scheduleEntry.id).collectAsStateWithLifecycle(null )
62
+
63
+ val isFavourite = remember(cachedContentState.value) {
64
+ cachedContentState.value?.isFavourite == true
65
+ }
66
+
50
67
Surface (
51
68
modifier = modifier,
52
69
shape = RoundedCornerShape (10 ),
@@ -71,24 +88,38 @@ fun ScheduleCard(
71
88
verticalArrangement = Arrangement .SpaceBetween ,
72
89
horizontalAlignment = Alignment .Start
73
90
) {
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)
80
95
) {
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
+
82
109
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 )
85
112
)
86
113
}
87
114
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
+ }
92
123
}
93
124
94
125
Column (
0 commit comments