BrowseSourceState.kt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package eu.kanade.presentation.browse
  2. import androidx.compose.runtime.Stable
  3. import androidx.compose.runtime.derivedStateOf
  4. import androidx.compose.runtime.getValue
  5. import androidx.compose.runtime.mutableStateOf
  6. import androidx.compose.runtime.setValue
  7. import eu.davidea.flexibleadapter.items.IFlexible
  8. import eu.kanade.tachiyomi.source.CatalogueSource
  9. import eu.kanade.tachiyomi.source.model.FilterList
  10. import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
  11. import eu.kanade.tachiyomi.ui.browse.source.browse.toItems
  12. @Stable
  13. interface BrowseSourceState {
  14. val source: CatalogueSource?
  15. var searchQuery: String?
  16. val currentQuery: String
  17. val filters: FilterList
  18. val filterItems: List<IFlexible<*>>
  19. val appliedFilters: FilterList
  20. var dialog: BrowseSourcePresenter.Dialog?
  21. }
  22. fun BrowseSourceState(initialQuery: String?): BrowseSourceState {
  23. return BrowseSourceStateImpl(initialQuery)
  24. }
  25. class BrowseSourceStateImpl(initialQuery: String?) : BrowseSourceState {
  26. override var source: CatalogueSource? by mutableStateOf(null)
  27. override var searchQuery: String? by mutableStateOf(initialQuery)
  28. override var currentQuery: String by mutableStateOf(initialQuery ?: "")
  29. override var filters: FilterList by mutableStateOf(FilterList())
  30. override val filterItems: List<IFlexible<*>> by derivedStateOf { filters.toItems() }
  31. override var appliedFilters by mutableStateOf(FilterList())
  32. override var dialog: BrowseSourcePresenter.Dialog? by mutableStateOf(null)
  33. }