mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
refactor(browse): Setup flow from presenter
This commit is contained in:
parent
5fad2c0154
commit
fcaff92db1
4 changed files with 14 additions and 12 deletions
|
@ -20,22 +20,20 @@ import eu.kanade.tachiyomi.ui.library.setBGAndFG
|
|||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
||||
// FIXME: Migrate to compose
|
||||
class BrowseSourceItem(
|
||||
initialManga: Manga,
|
||||
private val mangaFlow: Flow<Manga?>,
|
||||
private val catalogueAsList: Preference<Boolean>,
|
||||
private val catalogueListType: Preference<Int>,
|
||||
private val outlineOnCovers: Preference<Boolean>,
|
||||
) :
|
||||
AbstractFlexibleItem<BrowseSourceHolder>() {
|
||||
|
||||
private val getManga: GetManga by injectLazy()
|
||||
|
||||
val mangaId: Long = initialManga.id!!
|
||||
var manga: Manga = initialManga
|
||||
private set
|
||||
|
@ -94,7 +92,7 @@ class BrowseSourceItem(
|
|||
if (job == null) holder.onSetValues(manga)
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
getManga.subscribeByUrlAndSource(manga.url, manga.source).collectLatest {
|
||||
mangaFlow.collectLatest {
|
||||
manga = it ?: return@collectLatest
|
||||
holder.onSetValues(manga)
|
||||
}
|
||||
|
|
|
@ -185,6 +185,7 @@ open class BrowseSourcePresenter(
|
|||
first to second.map {
|
||||
BrowseSourceItem(
|
||||
it,
|
||||
getManga.subscribeByUrlAndSource(it.url, it.source),
|
||||
browseAsList,
|
||||
sourceListType,
|
||||
outlineCovers,
|
||||
|
|
|
@ -9,18 +9,16 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
||||
// FIXME: Migrate to compose
|
||||
class GlobalSearchMangaItem(
|
||||
initialManga: Manga
|
||||
initialManga: Manga,
|
||||
private val mangaFlow: Flow<Manga?>,
|
||||
) : AbstractFlexibleItem<GlobalSearchMangaHolder>() {
|
||||
|
||||
private val getManga: GetManga by injectLazy()
|
||||
|
||||
val mangaId: Long? = initialManga.id
|
||||
var manga: Manga = initialManga
|
||||
private set
|
||||
|
@ -44,7 +42,7 @@ class GlobalSearchMangaItem(
|
|||
if (job == null) holder.bind(manga)
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
getManga.subscribeByUrlAndSource(manga.url, manga.source).collectLatest {
|
||||
mangaFlow.collectLatest {
|
||||
manga = it ?: return@collectLatest
|
||||
holder.bind(manga)
|
||||
}
|
||||
|
|
|
@ -192,7 +192,12 @@ open class GlobalSearchPresenter(
|
|||
}
|
||||
val result = createCatalogueSearchItem(
|
||||
source,
|
||||
mangas.map { GlobalSearchMangaItem(it) },
|
||||
mangas.map {
|
||||
GlobalSearchMangaItem(
|
||||
it,
|
||||
getManga.subscribeByUrlAndSource(it.url, it.source),
|
||||
)
|
||||
},
|
||||
)
|
||||
items = items
|
||||
.map { item -> if (item.source == result.source) result else item }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue