mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Properly show history state (#7052)
* Make `HistoryState` similar to `MigrateState` * Review Changes * Also cache the transformation Co-authored-by: Andreas <andreas.everos@gmail.com> * Fix States Co-authored-by: Andreas <andreas.everos@gmail.com>
This commit is contained in:
@@ -17,7 +17,6 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -37,17 +36,19 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.paging.LoadState
|
||||
import androidx.paging.compose.LazyPagingItems
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.paging.compose.items
|
||||
import eu.kanade.domain.history.model.HistoryWithRelations
|
||||
import eu.kanade.presentation.components.EmptyScreen
|
||||
import eu.kanade.presentation.components.LoadingScreen
|
||||
import eu.kanade.presentation.components.MangaCover
|
||||
import eu.kanade.presentation.util.horizontalPadding
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.recent.history.HistoryPresenter
|
||||
import eu.kanade.tachiyomi.ui.recent.history.UiModel
|
||||
import eu.kanade.tachiyomi.ui.recent.history.HistoryState
|
||||
import eu.kanade.tachiyomi.util.lang.toRelativeString
|
||||
import eu.kanade.tachiyomi.util.lang.toTimestampString
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@@ -66,37 +67,37 @@ fun HistoryScreen(
|
||||
onClickDelete: (HistoryWithRelations, Boolean) -> Unit,
|
||||
) {
|
||||
val state by presenter.state.collectAsState()
|
||||
val history = state.list?.collectAsLazyPagingItems()
|
||||
when {
|
||||
history == null -> {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
history.itemCount == 0 -> {
|
||||
EmptyScreen(
|
||||
textResource = R.string.information_no_recent_manga
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
when (state) {
|
||||
is HistoryState.Loading -> LoadingScreen()
|
||||
is HistoryState.Error -> Text(text = (state as HistoryState.Error).error.message!!)
|
||||
is HistoryState.Success ->
|
||||
HistoryContent(
|
||||
nestedScroll = nestedScrollInterop,
|
||||
history = history,
|
||||
history = (state as HistoryState.Success).uiModels.collectAsLazyPagingItems(),
|
||||
onClickCover = onClickCover,
|
||||
onClickResume = onClickResume,
|
||||
onClickDelete = onClickDelete,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HistoryContent(
|
||||
history: LazyPagingItems<UiModel>,
|
||||
history: LazyPagingItems<HistoryUiModel>,
|
||||
onClickCover: (HistoryWithRelations) -> Unit,
|
||||
onClickResume: (HistoryWithRelations) -> Unit,
|
||||
onClickDelete: (HistoryWithRelations, Boolean) -> Unit,
|
||||
preferences: PreferencesHelper = Injekt.get(),
|
||||
nestedScroll: NestedScrollConnection
|
||||
) {
|
||||
if (history.loadState.refresh is LoadState.Loading) {
|
||||
LoadingScreen()
|
||||
return
|
||||
} else if (history.loadState.refresh is LoadState.NotLoading && history.itemCount == 0) {
|
||||
EmptyScreen(textResource = R.string.information_no_recent_manga)
|
||||
return
|
||||
}
|
||||
|
||||
val relativeTime: Int = remember { preferences.relativeTime().get() }
|
||||
val dateFormat: DateFormat = remember { preferences.dateFormat() }
|
||||
|
||||
@@ -111,7 +112,7 @@ fun HistoryContent(
|
||||
) {
|
||||
items(history) { item ->
|
||||
when (item) {
|
||||
is UiModel.Header -> {
|
||||
is HistoryUiModel.Header -> {
|
||||
HistoryHeader(
|
||||
modifier = Modifier
|
||||
.animateItemPlacement(),
|
||||
@@ -120,7 +121,7 @@ fun HistoryContent(
|
||||
dateFormat = dateFormat
|
||||
)
|
||||
}
|
||||
is UiModel.Item -> {
|
||||
is HistoryUiModel.Item -> {
|
||||
val value = item.item
|
||||
HistoryItem(
|
||||
modifier = Modifier.animateItemPlacement(),
|
||||
@@ -282,3 +283,8 @@ private val chapterFormatter = DecimalFormat(
|
||||
"#.###",
|
||||
DecimalFormatSymbols().apply { decimalSeparator = '.' },
|
||||
)
|
||||
|
||||
sealed class HistoryUiModel {
|
||||
data class Header(val date: Date) : HistoryUiModel()
|
||||
data class Item(val item: HistoryWithRelations) : HistoryUiModel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user