mirror of
https://github.com/mihonapp/mihon.git
synced 2025-02-12 18:18:55 +01:00
Move to ScreenModel
This commit is contained in:
parent
a7e650067e
commit
b61a6adeb7
@ -72,6 +72,7 @@ fun UpcomingScreenContent(
|
|||||||
setSelectedYearMonth = setSelectedYearMonth,
|
setSelectedYearMonth = setSelectedYearMonth,
|
||||||
onClickDay = { onClickDay(it, 0) },
|
onClickDay = { onClickDay(it, 0) },
|
||||||
onClickUpcoming = onClickUpcoming,
|
onClickUpcoming = onClickUpcoming,
|
||||||
|
mangaCountMap = state.mangaCountMap,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
UpcomingScreenSmallImpl(
|
UpcomingScreenSmallImpl(
|
||||||
@ -83,6 +84,7 @@ fun UpcomingScreenContent(
|
|||||||
setSelectedYearMonth = setSelectedYearMonth,
|
setSelectedYearMonth = setSelectedYearMonth,
|
||||||
onClickDay = { onClickDay(it, 1) },
|
onClickDay = { onClickDay(it, 1) },
|
||||||
onClickUpcoming = onClickUpcoming,
|
onClickUpcoming = onClickUpcoming,
|
||||||
|
mangaCountMap = state.mangaCountMap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,6 +146,7 @@ private fun UpcomingScreenSmallImpl(
|
|||||||
setSelectedYearMonth: (YearMonth) -> Unit,
|
setSelectedYearMonth: (YearMonth) -> Unit,
|
||||||
onClickDay: (LocalDate) -> Unit,
|
onClickDay: (LocalDate) -> Unit,
|
||||||
onClickUpcoming: (manga: Manga) -> Unit,
|
onClickUpcoming: (manga: Manga) -> Unit,
|
||||||
|
mangaCountMap: ImmutableMap<LocalDate, Int>,
|
||||||
) {
|
) {
|
||||||
FastScrollLazyColumn(
|
FastScrollLazyColumn(
|
||||||
contentPadding = paddingValues,
|
contentPadding = paddingValues,
|
||||||
@ -175,8 +178,7 @@ private fun UpcomingScreenSmallImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
is UpcomingUIModel.Header -> {
|
is UpcomingUIModel.Header -> {
|
||||||
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
|
val mangaCount = mangaCountMap[item.date] ?: 0
|
||||||
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }
|
|
||||||
|
|
||||||
DateHeading(
|
DateHeading(
|
||||||
date = item.date,
|
date = item.date,
|
||||||
@ -198,6 +200,7 @@ private fun UpcomingScreenLargeImpl(
|
|||||||
setSelectedYearMonth: (YearMonth) -> Unit,
|
setSelectedYearMonth: (YearMonth) -> Unit,
|
||||||
onClickDay: (LocalDate) -> Unit,
|
onClickDay: (LocalDate) -> Unit,
|
||||||
onClickUpcoming: (manga: Manga) -> Unit,
|
onClickUpcoming: (manga: Manga) -> Unit,
|
||||||
|
mangaCountMap: ImmutableMap<LocalDate, Int>,
|
||||||
) {
|
) {
|
||||||
TwoPanelBox(
|
TwoPanelBox(
|
||||||
modifier = Modifier.padding(paddingValues),
|
modifier = Modifier.padding(paddingValues),
|
||||||
@ -229,8 +232,7 @@ private fun UpcomingScreenLargeImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
is UpcomingUIModel.Header -> {
|
is UpcomingUIModel.Header -> {
|
||||||
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
|
val mangaCount = mangaCountMap[item.date] ?: 0
|
||||||
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }
|
|
||||||
|
|
||||||
DateHeading(
|
DateHeading(
|
||||||
date = item.date,
|
date = item.date,
|
||||||
|
@ -28,13 +28,17 @@ class UpcomingScreenModel(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
getUpcomingManga.subscribe().collectLatest {
|
getUpcomingManga.subscribe().collectLatest { mangaList ->
|
||||||
mutableState.update { state ->
|
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(
|
state.copy(
|
||||||
items = upcomingItems,
|
items = upcomingItems,
|
||||||
events = it.toEvents(),
|
events = mangaList.toEvents(),
|
||||||
headerIndexes = upcomingItems.getHeaderIndexes(),
|
headerIndexes = upcomingItems.getHeaderIndexes(),
|
||||||
|
mangaCountMap = mangaCountMap
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,5 +87,6 @@ class UpcomingScreenModel(
|
|||||||
val items: ImmutableList<UpcomingUIModel> = persistentListOf(),
|
val items: ImmutableList<UpcomingUIModel> = persistentListOf(),
|
||||||
val events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
|
val events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
|
||||||
val headerIndexes: ImmutableMap<LocalDate, Int> = persistentMapOf(),
|
val headerIndexes: ImmutableMap<LocalDate, Int> = persistentMapOf(),
|
||||||
|
val mangaCountMap: ImmutableMap<LocalDate, Int> = persistentMapOf(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user