mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Make SourceState similar to MigrateState (#7053)
* make `SourceState` similar to `MigrateState` * Review Changes
This commit is contained in:
@@ -44,7 +44,7 @@ import eu.kanade.presentation.util.horizontalPadding
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
|
||||
import eu.kanade.tachiyomi.ui.browse.source.UiModel
|
||||
import eu.kanade.tachiyomi.ui.browse.source.SourceState
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
|
||||
@Composable
|
||||
@@ -58,13 +58,12 @@ fun SourceScreen(
|
||||
) {
|
||||
val state by presenter.state.collectAsState()
|
||||
|
||||
when {
|
||||
state.isLoading -> LoadingScreen()
|
||||
state.hasError -> Text(text = state.error!!.message!!)
|
||||
state.isEmpty -> EmptyScreen(message = "")
|
||||
else -> SourceList(
|
||||
when (state) {
|
||||
is SourceState.Loading -> LoadingScreen()
|
||||
is SourceState.Error -> Text(text = (state as SourceState.Error).error.message!!)
|
||||
is SourceState.Success -> SourceList(
|
||||
nestedScrollConnection = nestedScrollInterop,
|
||||
list = state.sources,
|
||||
list = (state as SourceState.Success).uiModels,
|
||||
onClickItem = onClickItem,
|
||||
onClickDisable = onClickDisable,
|
||||
onClickLatest = onClickLatest,
|
||||
@@ -76,12 +75,17 @@ fun SourceScreen(
|
||||
@Composable
|
||||
fun SourceList(
|
||||
nestedScrollConnection: NestedScrollConnection,
|
||||
list: List<UiModel>,
|
||||
list: List<SourceUiModel>,
|
||||
onClickItem: (Source) -> Unit,
|
||||
onClickDisable: (Source) -> Unit,
|
||||
onClickLatest: (Source) -> Unit,
|
||||
onClickPin: (Source) -> Unit,
|
||||
) {
|
||||
if (list.isEmpty()) {
|
||||
EmptyScreen(textResource = R.string.source_empty_screen)
|
||||
return
|
||||
}
|
||||
|
||||
val (sourceState, setSourceState) = remember { mutableStateOf<Source?>(null) }
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
@@ -92,25 +96,25 @@ fun SourceList(
|
||||
items = list,
|
||||
contentType = {
|
||||
when (it) {
|
||||
is UiModel.Header -> "header"
|
||||
is UiModel.Item -> "item"
|
||||
is SourceUiModel.Header -> "header"
|
||||
is SourceUiModel.Item -> "item"
|
||||
}
|
||||
},
|
||||
key = {
|
||||
when (it) {
|
||||
is UiModel.Header -> it.hashCode()
|
||||
is UiModel.Item -> it.source.key()
|
||||
is SourceUiModel.Header -> it.hashCode()
|
||||
is SourceUiModel.Item -> it.source.key()
|
||||
}
|
||||
}
|
||||
) { model ->
|
||||
when (model) {
|
||||
is UiModel.Header -> {
|
||||
is SourceUiModel.Header -> {
|
||||
SourceHeader(
|
||||
modifier = Modifier.animateItemPlacement(),
|
||||
language = model.language
|
||||
)
|
||||
}
|
||||
is UiModel.Item -> SourceItem(
|
||||
is SourceUiModel.Item -> SourceItem(
|
||||
modifier = Modifier.animateItemPlacement(),
|
||||
source = model.source,
|
||||
onClickItem = onClickItem,
|
||||
@@ -262,3 +266,8 @@ fun SourceOptionsDialog(
|
||||
confirmButton = {},
|
||||
)
|
||||
}
|
||||
|
||||
sealed class SourceUiModel {
|
||||
data class Item(val source: Source) : SourceUiModel()
|
||||
data class Header(val language: String) : SourceUiModel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user