Minor cleanup
This commit is contained in:
+5
-5
@@ -54,20 +54,20 @@ class ExtensionFilterScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ExtensionFilterEvent {
|
||||
data object FailedFetchingLanguages : ExtensionFilterEvent()
|
||||
sealed interface ExtensionFilterEvent {
|
||||
data object FailedFetchingLanguages : ExtensionFilterEvent
|
||||
}
|
||||
|
||||
sealed class ExtensionFilterState {
|
||||
sealed interface ExtensionFilterState {
|
||||
|
||||
@Immutable
|
||||
data object Loading : ExtensionFilterState()
|
||||
data object Loading : ExtensionFilterState
|
||||
|
||||
@Immutable
|
||||
data class Success(
|
||||
val languages: List<String>,
|
||||
val enabledLanguages: Set<String> = emptySet(),
|
||||
) : ExtensionFilterState() {
|
||||
) : ExtensionFilterState {
|
||||
|
||||
val isEmpty: Boolean
|
||||
get() = languages.isEmpty()
|
||||
|
||||
+12
-10
@@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.extension
|
||||
|
||||
import android.app.Application
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.runtime.Immutable
|
||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
import cafe.adriel.voyager.core.model.coroutineScope
|
||||
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
||||
@@ -35,7 +36,7 @@ class ExtensionsScreenModel(
|
||||
preferences: SourcePreferences = Injekt.get(),
|
||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||
private val getExtensions: GetExtensionsByType = Injekt.get(),
|
||||
) : StateScreenModel<ExtensionsState>(ExtensionsState()) {
|
||||
) : StateScreenModel<ExtensionsScreenModel.State>(State()) {
|
||||
|
||||
private var _currentDownloads = MutableStateFlow<Map<String, InstallStep>>(hashMapOf())
|
||||
|
||||
@@ -190,16 +191,17 @@ class ExtensionsScreenModel(
|
||||
fun trustSignature(signatureHash: String) {
|
||||
extensionManager.trustSignature(signatureHash)
|
||||
}
|
||||
}
|
||||
|
||||
data class ExtensionsState(
|
||||
val isLoading: Boolean = true,
|
||||
val isRefreshing: Boolean = false,
|
||||
val items: ItemGroups = mutableMapOf(),
|
||||
val updates: Int = 0,
|
||||
val searchQuery: String? = null,
|
||||
) {
|
||||
val isEmpty = items.isEmpty()
|
||||
@Immutable
|
||||
data class State(
|
||||
val isLoading: Boolean = true,
|
||||
val isRefreshing: Boolean = false,
|
||||
val items: ItemGroups = mutableMapOf(),
|
||||
val updates: Int = 0,
|
||||
val searchQuery: String? = null,
|
||||
) {
|
||||
val isEmpty = items.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
typealias ItemGroups = MutableMap<ExtensionUiModel.Header, List<ExtensionUiModel.Item>>
|
||||
|
||||
+16
-16
@@ -38,7 +38,7 @@ class ExtensionDetailsScreenModel(
|
||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||
private val getExtensionSources: GetExtensionSources = Injekt.get(),
|
||||
private val toggleSource: ToggleSource = Injekt.get(),
|
||||
) : StateScreenModel<ExtensionDetailsState>(ExtensionDetailsState()) {
|
||||
) : StateScreenModel<ExtensionDetailsScreenModel.State>(State()) {
|
||||
|
||||
private val _events: Channel<ExtensionDetailsEvent> = Channel()
|
||||
val events: Flow<ExtensionDetailsEvent> = _events.receiveAsFlow()
|
||||
@@ -160,21 +160,21 @@ class ExtensionDetailsScreenModel(
|
||||
url + "/src/" + pkgName.replace(".", "/") + path
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class State(
|
||||
val extension: Extension.Installed? = null,
|
||||
private val _sources: List<ExtensionSourceItem>? = null,
|
||||
) {
|
||||
|
||||
val sources: List<ExtensionSourceItem>
|
||||
get() = _sources.orEmpty()
|
||||
|
||||
val isLoading: Boolean
|
||||
get() = extension == null || _sources == null
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ExtensionDetailsEvent {
|
||||
data object Uninstalled : ExtensionDetailsEvent()
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class ExtensionDetailsState(
|
||||
val extension: Extension.Installed? = null,
|
||||
private val _sources: List<ExtensionSourceItem>? = null,
|
||||
) {
|
||||
|
||||
val sources: List<ExtensionSourceItem>
|
||||
get() = _sources.orEmpty()
|
||||
|
||||
val isLoading: Boolean
|
||||
get() = extension == null || _sources == null
|
||||
sealed interface ExtensionDetailsEvent {
|
||||
data object Uninstalled : ExtensionDetailsEvent
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import tachiyomi.presentation.core.screens.LoadingScreen
|
||||
|
||||
data class MigrationMangaScreen(
|
||||
data class MigrateMangaScreen(
|
||||
private val sourceId: Long,
|
||||
) : Screen() {
|
||||
|
||||
@@ -25,7 +25,7 @@ data class MigrationMangaScreen(
|
||||
override fun Content() {
|
||||
val context = LocalContext.current
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
val screenModel = rememberScreenModel { MigrationMangaScreenModel(sourceId) }
|
||||
val screenModel = rememberScreenModel { MigrateMangaScreenModel(sourceId) }
|
||||
|
||||
val state by screenModel.state.collectAsState()
|
||||
|
||||
+20
-20
@@ -20,11 +20,11 @@ import tachiyomi.domain.source.service.SourceManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class MigrationMangaScreenModel(
|
||||
class MigrateMangaScreenModel(
|
||||
private val sourceId: Long,
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val getFavorites: GetFavorites = Injekt.get(),
|
||||
) : StateScreenModel<MigrateMangaState>(MigrateMangaState()) {
|
||||
) : StateScreenModel<MigrateMangaScreenModel.State>(State()) {
|
||||
|
||||
private val _events: Channel<MigrationMangaEvent> = Channel()
|
||||
val events: Flow<MigrationMangaEvent> = _events.receiveAsFlow()
|
||||
@@ -51,24 +51,24 @@ class MigrationMangaScreenModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class State(
|
||||
val source: Source? = null,
|
||||
private val titleList: List<Manga>? = null,
|
||||
) {
|
||||
|
||||
val titles: List<Manga>
|
||||
get() = titleList.orEmpty()
|
||||
|
||||
val isLoading: Boolean
|
||||
get() = source == null || titleList == null
|
||||
|
||||
val isEmpty: Boolean
|
||||
get() = titles.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
sealed class MigrationMangaEvent {
|
||||
data object FailedFetchingFavorites : MigrationMangaEvent()
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class MigrateMangaState(
|
||||
val source: Source? = null,
|
||||
private val titleList: List<Manga>? = null,
|
||||
) {
|
||||
|
||||
val titles: List<Manga>
|
||||
get() = titleList.orEmpty()
|
||||
|
||||
val isLoading: Boolean
|
||||
get() = source == null || titleList == null
|
||||
|
||||
val isEmpty: Boolean
|
||||
get() = titles.isEmpty()
|
||||
sealed interface MigrationMangaEvent {
|
||||
data object FailedFetchingFavorites : MigrationMangaEvent
|
||||
}
|
||||
+2
-2
@@ -37,7 +37,7 @@ class MigrateSearchScreenDialogScreenModel(
|
||||
val dialog: Dialog? = null,
|
||||
)
|
||||
|
||||
sealed class Dialog {
|
||||
data class Migrate(val manga: Manga) : Dialog()
|
||||
sealed interface Dialog {
|
||||
data class Migrate(val manga: Manga) : Dialog
|
||||
}
|
||||
}
|
||||
|
||||
+14
-12
@@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.migration.sources
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
import cafe.adriel.voyager.core.model.coroutineScope
|
||||
import eu.kanade.domain.source.interactor.GetSourcesWithFavoriteCount
|
||||
@@ -23,7 +24,7 @@ class MigrateSourceScreenModel(
|
||||
preferences: SourcePreferences = Injekt.get(),
|
||||
private val getSourcesWithFavoriteCount: GetSourcesWithFavoriteCount = Injekt.get(),
|
||||
private val setMigrateSorting: SetMigrateSorting = Injekt.get(),
|
||||
) : StateScreenModel<MigrateSourceState>(MigrateSourceState()) {
|
||||
) : StateScreenModel<MigrateSourceScreenModel.State>(State()) {
|
||||
|
||||
private val _channel = Channel<Event>(Int.MAX_VALUE)
|
||||
val channel = _channel.receiveAsFlow()
|
||||
@@ -76,16 +77,17 @@ class MigrateSourceScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Event {
|
||||
data object FailedFetchingSourcesWithCount : Event()
|
||||
@Immutable
|
||||
data class State(
|
||||
val isLoading: Boolean = true,
|
||||
val items: List<Pair<Source, Long>> = emptyList(),
|
||||
val sortingMode: SetMigrateSorting.Mode = SetMigrateSorting.Mode.ALPHABETICAL,
|
||||
val sortingDirection: SetMigrateSorting.Direction = SetMigrateSorting.Direction.ASCENDING,
|
||||
) {
|
||||
val isEmpty = items.isEmpty()
|
||||
}
|
||||
|
||||
sealed interface Event {
|
||||
data object FailedFetchingSourcesWithCount : Event
|
||||
}
|
||||
}
|
||||
|
||||
data class MigrateSourceState(
|
||||
val isLoading: Boolean = true,
|
||||
val items: List<Pair<Source, Long>> = emptyList(),
|
||||
val sortingMode: SetMigrateSorting.Mode = SetMigrateSorting.Mode.ALPHABETICAL,
|
||||
val sortingDirection: SetMigrateSorting.Direction = SetMigrateSorting.Direction.ASCENDING,
|
||||
) {
|
||||
val isEmpty = items.isEmpty()
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import eu.kanade.presentation.browse.MigrateSourceScreen
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.TabContent
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrationMangaScreen
|
||||
import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrateMangaScreen
|
||||
|
||||
@Composable
|
||||
fun Screen.migrateSourceTab(): TabContent {
|
||||
@@ -40,7 +40,7 @@ fun Screen.migrateSourceTab(): TabContent {
|
||||
state = state,
|
||||
contentPadding = contentPadding,
|
||||
onClickItem = { source ->
|
||||
navigator.push(MigrationMangaScreen(source.id))
|
||||
navigator.push(MigrateMangaScreen(source.id))
|
||||
},
|
||||
onToggleSortingDirection = screenModel::toggleSortingDirection,
|
||||
onToggleSortingMode = screenModel::toggleSortingMode,
|
||||
|
||||
@@ -22,12 +22,12 @@ class SourcesFilterScreen : Screen() {
|
||||
val screenModel = rememberScreenModel { SourcesFilterScreenModel() }
|
||||
val state by screenModel.state.collectAsState()
|
||||
|
||||
if (state is SourcesFilterState.Loading) {
|
||||
if (state is SourcesFilterScreenModel.State.Loading) {
|
||||
LoadingScreen()
|
||||
return
|
||||
}
|
||||
|
||||
if (state is SourcesFilterState.Error) {
|
||||
if (state is SourcesFilterScreenModel.State.Error) {
|
||||
val context = LocalContext.current
|
||||
LaunchedEffect(Unit) {
|
||||
context.toast(R.string.internal_error)
|
||||
@@ -36,7 +36,7 @@ class SourcesFilterScreen : Screen() {
|
||||
return
|
||||
}
|
||||
|
||||
val successState = state as SourcesFilterState.Success
|
||||
val successState = state as SourcesFilterScreenModel.State.Success
|
||||
|
||||
SourcesFilterScreen(
|
||||
navigateUp = navigator::pop,
|
||||
|
||||
+20
-16
@@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||
import cafe.adriel.voyager.core.model.coroutineScope
|
||||
import eu.kanade.domain.source.interactor.GetLanguagesWithSources
|
||||
@@ -21,7 +22,7 @@ class SourcesFilterScreenModel(
|
||||
private val getLanguagesWithSources: GetLanguagesWithSources = Injekt.get(),
|
||||
private val toggleSource: ToggleSource = Injekt.get(),
|
||||
private val toggleLanguage: ToggleLanguage = Injekt.get(),
|
||||
) : StateScreenModel<SourcesFilterState>(SourcesFilterState.Loading) {
|
||||
) : StateScreenModel<SourcesFilterScreenModel.State>(State.Loading) {
|
||||
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
@@ -32,14 +33,14 @@ class SourcesFilterScreenModel(
|
||||
) { a, b, c -> Triple(a, b, c) }
|
||||
.catch { throwable ->
|
||||
mutableState.update {
|
||||
SourcesFilterState.Error(
|
||||
State.Error(
|
||||
throwable = throwable,
|
||||
)
|
||||
}
|
||||
}
|
||||
.collectLatest { (languagesWithSources, enabledLanguages, disabledSources) ->
|
||||
mutableState.update {
|
||||
SourcesFilterState.Success(
|
||||
State.Success(
|
||||
items = languagesWithSources,
|
||||
enabledLanguages = enabledLanguages,
|
||||
disabledSources = disabledSources,
|
||||
@@ -56,23 +57,26 @@ class SourcesFilterScreenModel(
|
||||
fun toggleLanguage(language: String) {
|
||||
toggleLanguage.await(language)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SourcesFilterState {
|
||||
sealed interface State {
|
||||
|
||||
data object Loading : SourcesFilterState()
|
||||
@Immutable
|
||||
data object Loading : State
|
||||
|
||||
data class Error(
|
||||
val throwable: Throwable,
|
||||
) : SourcesFilterState()
|
||||
@Immutable
|
||||
data class Error(
|
||||
val throwable: Throwable,
|
||||
) : State
|
||||
|
||||
data class Success(
|
||||
val items: SortedMap<String, List<Source>>,
|
||||
val enabledLanguages: Set<String>,
|
||||
val disabledSources: Set<String>,
|
||||
) : SourcesFilterState() {
|
||||
@Immutable
|
||||
data class Success(
|
||||
val items: SortedMap<String, List<Source>>,
|
||||
val enabledLanguages: Set<String>,
|
||||
val disabledSources: Set<String>,
|
||||
) : State {
|
||||
|
||||
val isEmpty: Boolean
|
||||
get() = items.isEmpty()
|
||||
val isEmpty: Boolean
|
||||
get() = items.isEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ class SourcesScreenModel(
|
||||
mutableState.update { it.copy(dialog = null) }
|
||||
}
|
||||
|
||||
sealed class Event {
|
||||
data object FailedFetchingSources : Event()
|
||||
sealed interface Event {
|
||||
data object FailedFetchingSources : Event
|
||||
}
|
||||
|
||||
data class Dialog(val source: Source)
|
||||
|
||||
+6
-6
@@ -365,15 +365,15 @@ class BrowseSourceScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Dialog {
|
||||
data object Filter : Dialog()
|
||||
data class RemoveManga(val manga: Manga) : Dialog()
|
||||
data class AddDuplicateManga(val manga: Manga, val duplicate: Manga) : Dialog()
|
||||
sealed interface Dialog {
|
||||
data object Filter : Dialog
|
||||
data class RemoveManga(val manga: Manga) : Dialog
|
||||
data class AddDuplicateManga(val manga: Manga, val duplicate: Manga) : Dialog
|
||||
data class ChangeMangaCategory(
|
||||
val manga: Manga,
|
||||
val initialSelection: List<CheckboxState.State<Category>>,
|
||||
) : Dialog()
|
||||
data class Migrate(val newManga: Manga) : Dialog()
|
||||
) : Dialog
|
||||
data class Migrate(val newManga: Manga) : Dialog
|
||||
}
|
||||
|
||||
@Immutable
|
||||
|
||||
+4
-4
@@ -190,16 +190,16 @@ enum class SourceFilter {
|
||||
PinnedOnly,
|
||||
}
|
||||
|
||||
sealed class SearchItemResult {
|
||||
data object Loading : SearchItemResult()
|
||||
sealed interface SearchItemResult {
|
||||
data object Loading : SearchItemResult
|
||||
|
||||
data class Error(
|
||||
val throwable: Throwable,
|
||||
) : SearchItemResult()
|
||||
) : SearchItemResult
|
||||
|
||||
data class Success(
|
||||
val result: List<Manga>,
|
||||
) : SearchItemResult() {
|
||||
) : SearchItemResult {
|
||||
val isEmpty: Boolean
|
||||
get() = result.isEmpty()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user