2022-08-31 14:41:35 -04:00
|
|
|
package eu.kanade.presentation.browse
|
|
|
|
|
|
|
|
import androidx.compose.runtime.Stable
|
|
|
|
import androidx.compose.runtime.derivedStateOf
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
import eu.davidea.flexibleadapter.items.IFlexible
|
|
|
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
|
|
|
import eu.kanade.tachiyomi.source.model.FilterList
|
|
|
|
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
|
2022-09-04 11:15:13 -04:00
|
|
|
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter.Filter
|
2022-08-31 14:41:35 -04:00
|
|
|
import eu.kanade.tachiyomi.ui.browse.source.browse.toItems
|
|
|
|
|
|
|
|
@Stable
|
|
|
|
interface BrowseSourceState {
|
|
|
|
val source: CatalogueSource?
|
|
|
|
var searchQuery: String?
|
2022-09-04 11:15:13 -04:00
|
|
|
val currentFilter: Filter
|
2022-09-03 10:16:30 -04:00
|
|
|
val isUserQuery: Boolean
|
2022-08-31 14:41:35 -04:00
|
|
|
val filters: FilterList
|
|
|
|
val filterItems: List<IFlexible<*>>
|
|
|
|
var dialog: BrowseSourcePresenter.Dialog?
|
|
|
|
}
|
|
|
|
|
|
|
|
fun BrowseSourceState(initialQuery: String?): BrowseSourceState {
|
2022-09-04 11:15:13 -04:00
|
|
|
return when (val filter = Filter.valueOf(initialQuery ?: "")) {
|
|
|
|
Filter.Latest, Filter.Popular -> BrowseSourceStateImpl(initialCurrentFilter = filter)
|
|
|
|
is Filter.UserInput -> BrowseSourceStateImpl(initialQuery = initialQuery, initialCurrentFilter = filter)
|
2022-09-03 10:16:30 -04:00
|
|
|
}
|
2022-08-31 14:41:35 -04:00
|
|
|
}
|
|
|
|
|
2022-09-04 11:15:13 -04:00
|
|
|
class BrowseSourceStateImpl(initialQuery: String? = null, initialCurrentFilter: Filter) : BrowseSourceState {
|
2022-08-31 14:41:35 -04:00
|
|
|
override var source: CatalogueSource? by mutableStateOf(null)
|
|
|
|
override var searchQuery: String? by mutableStateOf(initialQuery)
|
2022-09-04 11:15:13 -04:00
|
|
|
override var currentFilter: Filter by mutableStateOf(initialCurrentFilter)
|
|
|
|
override val isUserQuery: Boolean by derivedStateOf { currentFilter is Filter.UserInput && currentFilter.query.isNotEmpty() }
|
2022-08-31 14:41:35 -04:00
|
|
|
override var filters: FilterList by mutableStateOf(FilterList())
|
|
|
|
override val filterItems: List<IFlexible<*>> by derivedStateOf { filters.toItems() }
|
|
|
|
override var dialog: BrowseSourcePresenter.Dialog? by mutableStateOf(null)
|
|
|
|
}
|