Skip to content

Commit

Permalink
Move to ScreenModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Animeboynz committed Sep 28, 2024
1 parent 04f2609 commit 59fa07a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fun UpcomingScreenContent(
setSelectedYearMonth = setSelectedYearMonth,
onClickDay = { onClickDay(it, 0) },
onClickUpcoming = onClickUpcoming,
mangaCountMap = state.mangaCountMap,
)
} else {
UpcomingScreenSmallImpl(
Expand All @@ -83,6 +84,7 @@ fun UpcomingScreenContent(
setSelectedYearMonth = setSelectedYearMonth,
onClickDay = { onClickDay(it, 1) },
onClickUpcoming = onClickUpcoming,
mangaCountMap = state.mangaCountMap,
)
}
}
Expand Down Expand Up @@ -144,6 +146,7 @@ private fun UpcomingScreenSmallImpl(
setSelectedYearMonth: (YearMonth) -> Unit,
onClickDay: (LocalDate) -> Unit,
onClickUpcoming: (manga: Manga) -> Unit,
mangaCountMap: ImmutableMap<LocalDate, Int>,
) {
FastScrollLazyColumn(
contentPadding = paddingValues,
Expand Down Expand Up @@ -175,8 +178,7 @@ private fun UpcomingScreenSmallImpl(
)
}
is UpcomingUIModel.Header -> {
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }
val mangaCount = mangaCountMap[item.date] ?: 0

DateHeading(
date = item.date,
Expand All @@ -198,6 +200,7 @@ private fun UpcomingScreenLargeImpl(
setSelectedYearMonth: (YearMonth) -> Unit,
onClickDay: (LocalDate) -> Unit,
onClickUpcoming: (manga: Manga) -> Unit,
mangaCountMap: ImmutableMap<LocalDate, Int>,
) {
TwoPanelBox(
modifier = Modifier.padding(paddingValues),
Expand Down Expand Up @@ -229,8 +232,7 @@ private fun UpcomingScreenLargeImpl(
)
}
is UpcomingUIModel.Header -> {
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }
val mangaCount = mangaCountMap[item.date] ?: 0

DateHeading(
date = item.date,
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/mihon/feature/upcoming/UpcomingScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class UpcomingScreenModel(

init {
screenModelScope.launch {
getUpcomingManga.subscribe().collectLatest {
getUpcomingManga.subscribe().collectLatest { mangaList ->
mutableState.update { state ->
val upcomingItems = it.toUpcomingUIModels()
val upcomingItems = mangaList.toUpcomingUIModels()
val mangaCountMap = mangaList.groupBy { it.expectedNextUpdate?.toLocalDate() ?: LocalDate.MAX }
.mapValues { it.value.size }
.toImmutableMap()
state.copy(
items = upcomingItems,
events = it.toEvents(),
events = mangaList.toEvents(),
headerIndexes = upcomingItems.getHeaderIndexes(),
mangaCountMap = mangaCountMap
)
}
}
Expand Down Expand Up @@ -83,5 +87,6 @@ class UpcomingScreenModel(
val items: ImmutableList<UpcomingUIModel> = persistentListOf(),
val events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
val headerIndexes: ImmutableMap<LocalDate, Int> = persistentMapOf(),
val mangaCountMap: ImmutableMap<LocalDate, Int> = persistentMapOf(),
)
}

0 comments on commit 59fa07a

Please sign in to comment.