Refactor FilterOwner
parent
183a61272e
commit
71b14a3aa8
@ -1,32 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.filter.ui
|
package org.koitharu.kotatsu.filter.ui
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
interface FilterOwner {
|
||||||
import androidx.fragment.app.FragmentActivity
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.values
|
|
||||||
import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
|
||||||
import org.koitharu.kotatsu.list.ui.model.ListModel
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
|
||||||
|
|
||||||
interface FilterOwner : OnFilterChangedListener {
|
val filter: MangaFilter
|
||||||
|
|
||||||
val filterItems: StateFlow<List<ListModel>>
|
|
||||||
|
|
||||||
val header: StateFlow<FilterHeaderModel>
|
|
||||||
|
|
||||||
fun applyFilter(tags: Set<MangaTag>)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun from(activity: FragmentActivity): FilterOwner {
|
|
||||||
for (f in activity.supportFragmentManager.fragments) {
|
|
||||||
return find(f) ?: continue
|
|
||||||
}
|
|
||||||
error("Cannot find FilterOwner")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun find(fragment: Fragment): FilterOwner? {
|
|
||||||
return fragment.viewModelStore.values.firstNotNullOfOrNull { it as? FilterOwner }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package org.koitharu.kotatsu.filter.ui
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
|
||||||
|
interface MangaFilter : OnFilterChangedListener {
|
||||||
|
|
||||||
|
val filterItems: StateFlow<List<ListModel>>
|
||||||
|
|
||||||
|
val header: StateFlow<FilterHeaderModel>
|
||||||
|
|
||||||
|
fun applyFilter(tags: Set<MangaTag>)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue