Skip to content

Commit

Permalink
feat(schedule): favourite animes marking
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed Dec 28, 2024
1 parent 9f5d37a commit 300065b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/**
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="schedule_dialog_title">Как работает расписание?</string>
<string name="schedule_dialog_text">В этом разделе ты сможешь узнать, когда на этой неделе выйдет следующая серия любимого аниме. \n\nВремя выхода серий ориентировочное, отображено согласно московскому времени (MSK) и не может соответствовать времени выхода конкретной озвучки. Поэтому стоить проявить терпение! \n\nСерии, которые ещё не успели выйти помечены серым цветом, когда в свою очередь те что уже вышли помечены зелёным. Всё просто!</string>
<string name="schedule_dialog_confirm">Понятно!</string>
<string name="schedule_episode">Серия %d</string>

<!--
Favourites Screen
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/shirabox/core/db/dao/ContentDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ContentDao {
fun getContentByUid(uid: Long): ContentEntity

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

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

0 comments on commit 300065b

Please sign in to comment.