|
@@ -79,7 +79,7 @@ import eu.kanade.tachiyomi.source.model.Filter as SourceModelFilter
|
|
|
|
|
|
class BrowseSourceScreenModel(
|
|
|
private val sourceId: Long,
|
|
|
- searchQuery: String?,
|
|
|
+ listing: Listing,
|
|
|
private val sourceManager: SourceManager = Injekt.get(),
|
|
|
sourcePreferences: SourcePreferences = Injekt.get(),
|
|
|
private val libraryPreferences: LibraryPreferences = Injekt.get(),
|
|
@@ -95,7 +95,7 @@ class BrowseSourceScreenModel(
|
|
|
private val updateManga: UpdateManga = Injekt.get(),
|
|
|
private val insertTrack: InsertTrack = Injekt.get(),
|
|
|
private val syncChaptersWithTrackServiceTwoWay: SyncChaptersWithTrackServiceTwoWay = Injekt.get(),
|
|
|
-) : StateScreenModel<BrowseSourceScreenModel.State>(State(Filter.valueOf(searchQuery))) {
|
|
|
+) : StateScreenModel<BrowseSourceScreenModel.State>(State(listing)) {
|
|
|
|
|
|
private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLogged } }
|
|
|
|
|
@@ -109,15 +109,15 @@ class BrowseSourceScreenModel(
|
|
|
private var filterSheet: SourceFilterSheet? = null
|
|
|
|
|
|
/**
|
|
|
- * Flow of Pager flow tied to [State.currentFilter]
|
|
|
+ * Flow of Pager flow tied to [State.listing]
|
|
|
*/
|
|
|
- val mangaPagerFlowFlow = state.map { it.currentFilter }
|
|
|
+ val mangaPagerFlowFlow = state.map { it.listing }
|
|
|
.distinctUntilChanged()
|
|
|
- .map { currentFilter ->
|
|
|
+ .map { listing ->
|
|
|
Pager(
|
|
|
PagingConfig(pageSize = 25),
|
|
|
) {
|
|
|
- getRemoteManga.subscribe(sourceId, currentFilter.query ?: "", currentFilter.filters)
|
|
|
+ getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
|
|
|
}.flow
|
|
|
.map { pagingData ->
|
|
|
pagingData.map { sManga ->
|
|
@@ -146,26 +146,21 @@ class BrowseSourceScreenModel(
|
|
|
return if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
|
|
|
}
|
|
|
|
|
|
- fun reset() {
|
|
|
+ fun resetFilters() {
|
|
|
mutableState.update { it.copy(filters = source.getFilterList()) }
|
|
|
}
|
|
|
|
|
|
+ fun setListing(listing: Listing) {
|
|
|
+ mutableState.update { it.copy(listing = listing) }
|
|
|
+ }
|
|
|
+
|
|
|
fun search(query: String? = null, filters: FilterList? = null) {
|
|
|
- Filter.valueOf(query).let {
|
|
|
- if (it !is Filter.UserInput) {
|
|
|
- mutableState.update { state -> state.copy(currentFilter = it) }
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
+ val input = state.value.listing as? Listing.Search
|
|
|
+ ?: Listing.Search(query = null, filters = source.getFilterList())
|
|
|
|
|
|
- val input = if (state.value.currentFilter is Filter.UserInput) {
|
|
|
- state.value.currentFilter as Filter.UserInput
|
|
|
- } else {
|
|
|
- Filter.UserInput()
|
|
|
- }
|
|
|
mutableState.update {
|
|
|
it.copy(
|
|
|
- currentFilter = input.copy(
|
|
|
+ listing = input.copy(
|
|
|
query = query ?: input.query,
|
|
|
filters = filters ?: input.filters,
|
|
|
),
|
|
@@ -204,14 +199,14 @@ class BrowseSourceScreenModel(
|
|
|
}
|
|
|
|
|
|
mutableState.update {
|
|
|
- val filter = if (genreExists) {
|
|
|
- Filter.UserInput(filters = defaultFilters)
|
|
|
+ val listing = if (genreExists) {
|
|
|
+ Listing.Search(query = null, filters = defaultFilters)
|
|
|
} else {
|
|
|
- Filter.UserInput(query = genreName)
|
|
|
+ Listing.Search(query = genreName, filters = defaultFilters)
|
|
|
}
|
|
|
it.copy(
|
|
|
filters = defaultFilters,
|
|
|
- currentFilter = filter,
|
|
|
+ listing = listing,
|
|
|
)
|
|
|
}
|
|
|
}
|
|
@@ -367,7 +362,7 @@ class BrowseSourceScreenModel(
|
|
|
context = context,
|
|
|
onFilterClicked = { search(filters = state.value.filters) },
|
|
|
onResetClicked = {
|
|
|
- reset()
|
|
|
+ resetFilters()
|
|
|
filterSheet?.setFilters(state.value.filterItems)
|
|
|
},
|
|
|
)
|
|
@@ -375,20 +370,10 @@ class BrowseSourceScreenModel(
|
|
|
filterSheet?.setFilters(state.value.filterItems)
|
|
|
}
|
|
|
|
|
|
- sealed class Filter(open val query: String?, open val filters: FilterList) {
|
|
|
- object Popular : Filter(query = GetRemoteManga.QUERY_POPULAR, filters = FilterList())
|
|
|
- object Latest : Filter(query = GetRemoteManga.QUERY_LATEST, filters = FilterList())
|
|
|
- data class UserInput(override val query: String? = null, override val filters: FilterList = FilterList()) : Filter(query = query, filters = filters)
|
|
|
-
|
|
|
- companion object {
|
|
|
- fun valueOf(query: String?): Filter {
|
|
|
- return when (query) {
|
|
|
- GetRemoteManga.QUERY_POPULAR -> Popular
|
|
|
- GetRemoteManga.QUERY_LATEST -> Latest
|
|
|
- else -> UserInput(query = query)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ sealed class Listing(open val query: String?, open val filters: FilterList) {
|
|
|
+ object Popular : Listing(query = GetRemoteManga.QUERY_POPULAR, filters = FilterList())
|
|
|
+ object Latest : Listing(query = GetRemoteManga.QUERY_LATEST, filters = FilterList())
|
|
|
+ data class Search(override val query: String?, override val filters: FilterList) : Listing(query = query, filters = filters)
|
|
|
}
|
|
|
|
|
|
sealed class Dialog {
|
|
@@ -403,13 +388,13 @@ class BrowseSourceScreenModel(
|
|
|
|
|
|
@Immutable
|
|
|
data class State(
|
|
|
- val currentFilter: Filter,
|
|
|
+ val listing: Listing,
|
|
|
val filters: FilterList = FilterList(),
|
|
|
val toolbarQuery: String? = null,
|
|
|
val dialog: Dialog? = null,
|
|
|
) {
|
|
|
val filterItems get() = filters.toItems()
|
|
|
- val isUserQuery get() = currentFilter is Filter.UserInput && !currentFilter.query.isNullOrEmpty()
|
|
|
+ val isUserQuery get() = listing is Listing.Search && !listing.query.isNullOrEmpty()
|
|
|
}
|
|
|
}
|
|
|
|