Make MigrateSourceState
similar to MigrateState
(#7054)
This commit is contained in:
parent
bd45bf7407
commit
aef1dc6eaf
@ -26,6 +26,7 @@ import eu.kanade.presentation.source.components.BaseSourceItem
|
|||||||
import eu.kanade.presentation.theme.header
|
import eu.kanade.presentation.theme.header
|
||||||
import eu.kanade.presentation.util.horizontalPadding
|
import eu.kanade.presentation.util.horizontalPadding
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrateSourceState
|
||||||
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter
|
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -36,17 +37,16 @@ fun MigrateSourceScreen(
|
|||||||
onLongClickItem: (Source) -> Unit,
|
onLongClickItem: (Source) -> Unit,
|
||||||
) {
|
) {
|
||||||
val state by presenter.state.collectAsState()
|
val state by presenter.state.collectAsState()
|
||||||
when {
|
when (state) {
|
||||||
state.isLoading -> LoadingScreen()
|
is MigrateSourceState.Loading -> LoadingScreen()
|
||||||
state.isEmpty -> EmptyScreen(textResource = R.string.information_empty_library)
|
is MigrateSourceState.Error -> Text(text = (state as MigrateSourceState.Error).error.message!!)
|
||||||
else -> {
|
is MigrateSourceState.Success ->
|
||||||
MigrateSourceList(
|
MigrateSourceList(
|
||||||
nestedScrollInterop = nestedScrollInterop,
|
nestedScrollInterop = nestedScrollInterop,
|
||||||
list = state.sources!!,
|
list = (state as MigrateSourceState.Success).sources,
|
||||||
onClickItem = onClickItem,
|
onClickItem = onClickItem,
|
||||||
onLongClickItem = onLongClickItem,
|
onLongClickItem = onLongClickItem,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +57,11 @@ fun MigrateSourceList(
|
|||||||
onClickItem: (Source) -> Unit,
|
onClickItem: (Source) -> Unit,
|
||||||
onLongClickItem: (Source) -> Unit,
|
onLongClickItem: (Source) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
EmptyScreen(textResource = R.string.information_empty_library)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
||||||
contentPadding = WindowInsets.navigationBars.asPaddingValues(),
|
contentPadding = WindowInsets.navigationBars.asPaddingValues(),
|
||||||
|
@ -9,8 +9,8 @@ import eu.kanade.tachiyomi.util.lang.launchIO
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class MigrationSourcesPresenter(
|
|||||||
private val setMigrateSorting: SetMigrateSorting = Injekt.get()
|
private val setMigrateSorting: SetMigrateSorting = Injekt.get()
|
||||||
) : BasePresenter<MigrationSourcesController>() {
|
) : BasePresenter<MigrationSourcesController>() {
|
||||||
|
|
||||||
private val _state: MutableStateFlow<MigrateSourceState> = MutableStateFlow(MigrateSourceState.EMPTY)
|
private val _state: MutableStateFlow<MigrateSourceState> = MutableStateFlow(MigrateSourceState.Loading)
|
||||||
val state: StateFlow<MigrateSourceState> = _state.asStateFlow()
|
val state: StateFlow<MigrateSourceState> = _state.asStateFlow()
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
@ -27,10 +27,11 @@ class MigrationSourcesPresenter(
|
|||||||
|
|
||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
getSourcesWithFavoriteCount.subscribe()
|
getSourcesWithFavoriteCount.subscribe()
|
||||||
|
.catch { exception ->
|
||||||
|
_state.emit(MigrateSourceState.Error(exception))
|
||||||
|
}
|
||||||
.collectLatest { sources ->
|
.collectLatest { sources ->
|
||||||
_state.update { state ->
|
_state.emit(MigrateSourceState.Success(sources))
|
||||||
state.copy(sources = sources)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,17 +45,8 @@ class MigrationSourcesPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class MigrateSourceState(
|
sealed class MigrateSourceState {
|
||||||
val sources: List<Pair<Source, Long>>?
|
object Loading : MigrateSourceState()
|
||||||
) {
|
data class Error(val error: Throwable) : MigrateSourceState()
|
||||||
|
data class Success(val sources: List<Pair<Source, Long>>) : MigrateSourceState()
|
||||||
val isLoading: Boolean
|
|
||||||
get() = sources == null
|
|
||||||
|
|
||||||
val isEmpty: Boolean
|
|
||||||
get() = sources.isNullOrEmpty()
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val EMPTY = MigrateSourceState(null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user