Skip to content

Commit

Permalink
switch title language in home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 11, 2024
1 parent 41cdcf5 commit ac2ed4e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.model.User
import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.anilist.type.MediaType
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.trace.TraceRepository
import dev.datlag.aniflow.ui.navigation.Component
import dev.datlag.aniflow.ui.navigation.DialogComponent
Expand All @@ -16,6 +17,7 @@ import kotlinx.coroutines.flow.Flow
interface HomeComponent : Component {
val viewing: Flow<MediaType>
val user: Flow<User?>
val titleLanguage: Flow<TitleLanguage?>

val airing: Flow<AiringTodayRepository.State>
val trending: Flow<CollectionState>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fun HomeScreen(component: HomeComponent) {
val isManga = remember(viewType) {
viewType == MediaType.MANGA
}
val titleLanguage by component.titleLanguage.collectAsStateWithLifecycle(null)

LazyColumn(
state = listState,
Expand All @@ -196,6 +197,7 @@ fun HomeScreen(component: HomeComponent) {
item {
ScheduleOverview(
flow = component.airing,
titleLanguage = titleLanguage,
onMediumClick = component::details
)
}
Expand All @@ -204,13 +206,15 @@ fun HomeScreen(component: HomeComponent) {
DefaultOverview(
title = "Trending",
flow = component.trending,
titleLanguage = titleLanguage,
onMediumClick = component::details
)
}
item {
DefaultOverview(
title = "Popular",
flow = component.popularNow,
titleLanguage = titleLanguage,
onMediumClick = component::details
)
}
Expand All @@ -219,6 +223,7 @@ fun HomeScreen(component: HomeComponent) {
DefaultOverview(
title = "Popular Next",
flow = component.popularNext,
titleLanguage = titleLanguage,
onMediumClick = component::details
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.datlag.aniflow.model.coroutines.Executor
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.other.UserHelper
import dev.datlag.aniflow.settings.Settings
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.trace.TraceRepository
import dev.datlag.aniflow.ui.navigation.DialogComponent
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.SettingsDialogComponent
Expand Down Expand Up @@ -49,6 +50,8 @@ class HomeScreenComponent(
MediaType.ANIME
}
}
override val titleLanguage: Flow<TitleLanguage?> = appSettings.titleLanguage

private val viewTypeExecutor = Executor()

private val userHelper by instance<UserHelper>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.ui.navigation.screen.home.component.default.MediumCard
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import kotlinx.coroutines.flow.Flow
Expand All @@ -26,6 +27,7 @@ import kotlinx.coroutines.flow.Flow
fun DefaultOverview(
title: String,
flow: Flow<CollectionState>,
titleLanguage: TitleLanguage?,
onMediumClick: (Medium) -> Unit,
) {
Column(
Expand Down Expand Up @@ -60,7 +62,7 @@ fun DefaultOverview(
items(current.collection.toList(), key = { it.id }) {
MediumCard(
medium = it,
titleLanguage = null,
titleLanguage = titleLanguage,
modifier = Modifier
.width(200.dp)
.height(280.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.anilist.AiringTodayRepository
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.ui.navigation.screen.home.component.airing.AiringCard
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import kotlinx.coroutines.flow.Flow
Expand All @@ -28,6 +29,7 @@ import kotlinx.coroutines.flow.Flow
@Composable
fun ScheduleOverview(
flow: Flow<AiringTodayRepository.State>,
titleLanguage: TitleLanguage?,
onMediumClick: (Medium) -> Unit
) {
Column(
Expand Down Expand Up @@ -69,7 +71,7 @@ fun ScheduleOverview(
items(current.collection.toList()) {
AiringCard(
airing = it,
titleLanguage = null,
titleLanguage = titleLanguage,
modifier = Modifier
.height(150.dp)
.fillParentMaxWidth(fraction = 0.9F)
Expand Down

0 comments on commit ac2ed4e

Please sign in to comment.