mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +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 eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import yokai.domain.manga.interactor.GetManga
|
|
||||||
|
|
||||||
// FIXME: Migrate to compose
|
// FIXME: Migrate to compose
|
||||||
class BrowseSourceItem(
|
class BrowseSourceItem(
|
||||||
initialManga: Manga,
|
initialManga: Manga,
|
||||||
|
private val mangaFlow: Flow<Manga?>,
|
||||||
private val catalogueAsList: Preference<Boolean>,
|
private val catalogueAsList: Preference<Boolean>,
|
||||||
private val catalogueListType: Preference<Int>,
|
private val catalogueListType: Preference<Int>,
|
||||||
private val outlineOnCovers: Preference<Boolean>,
|
private val outlineOnCovers: Preference<Boolean>,
|
||||||
) :
|
) :
|
||||||
AbstractFlexibleItem<BrowseSourceHolder>() {
|
AbstractFlexibleItem<BrowseSourceHolder>() {
|
||||||
|
|
||||||
private val getManga: GetManga by injectLazy()
|
|
||||||
|
|
||||||
val mangaId: Long = initialManga.id!!
|
val mangaId: Long = initialManga.id!!
|
||||||
var manga: Manga = initialManga
|
var manga: Manga = initialManga
|
||||||
private set
|
private set
|
||||||
|
@ -94,7 +92,7 @@ class BrowseSourceItem(
|
||||||
if (job == null) holder.onSetValues(manga)
|
if (job == null) holder.onSetValues(manga)
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = scope.launch {
|
job = scope.launch {
|
||||||
getManga.subscribeByUrlAndSource(manga.url, manga.source).collectLatest {
|
mangaFlow.collectLatest {
|
||||||
manga = it ?: return@collectLatest
|
manga = it ?: return@collectLatest
|
||||||
holder.onSetValues(manga)
|
holder.onSetValues(manga)
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ open class BrowseSourcePresenter(
|
||||||
first to second.map {
|
first to second.map {
|
||||||
BrowseSourceItem(
|
BrowseSourceItem(
|
||||||
it,
|
it,
|
||||||
|
getManga.subscribeByUrlAndSource(it.url, it.source),
|
||||||
browseAsList,
|
browseAsList,
|
||||||
sourceListType,
|
sourceListType,
|
||||||
outlineCovers,
|
outlineCovers,
|
||||||
|
|
|
@ -9,18 +9,16 @@ import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import yokai.domain.manga.interactor.GetManga
|
|
||||||
|
|
||||||
// FIXME: Migrate to compose
|
// FIXME: Migrate to compose
|
||||||
class GlobalSearchMangaItem(
|
class GlobalSearchMangaItem(
|
||||||
initialManga: Manga
|
initialManga: Manga,
|
||||||
|
private val mangaFlow: Flow<Manga?>,
|
||||||
) : AbstractFlexibleItem<GlobalSearchMangaHolder>() {
|
) : AbstractFlexibleItem<GlobalSearchMangaHolder>() {
|
||||||
|
|
||||||
private val getManga: GetManga by injectLazy()
|
|
||||||
|
|
||||||
val mangaId: Long? = initialManga.id
|
val mangaId: Long? = initialManga.id
|
||||||
var manga: Manga = initialManga
|
var manga: Manga = initialManga
|
||||||
private set
|
private set
|
||||||
|
@ -44,7 +42,7 @@ class GlobalSearchMangaItem(
|
||||||
if (job == null) holder.bind(manga)
|
if (job == null) holder.bind(manga)
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = scope.launch {
|
job = scope.launch {
|
||||||
getManga.subscribeByUrlAndSource(manga.url, manga.source).collectLatest {
|
mangaFlow.collectLatest {
|
||||||
manga = it ?: return@collectLatest
|
manga = it ?: return@collectLatest
|
||||||
holder.bind(manga)
|
holder.bind(manga)
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,12 @@ open class GlobalSearchPresenter(
|
||||||
}
|
}
|
||||||
val result = createCatalogueSearchItem(
|
val result = createCatalogueSearchItem(
|
||||||
source,
|
source,
|
||||||
mangas.map { GlobalSearchMangaItem(it) },
|
mangas.map {
|
||||||
|
GlobalSearchMangaItem(
|
||||||
|
it,
|
||||||
|
getManga.subscribeByUrlAndSource(it.url, it.source),
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
items = items
|
items = items
|
||||||
.map { item -> if (item.source == result.source) result else item }
|
.map { item -> if (item.source == result.source) result else item }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue