mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix(browse): Update favorite state in real time
This commit is contained in:
parent
2461b93af5
commit
3651c2a853
1 changed files with 36 additions and 4 deletions
|
@ -18,15 +18,31 @@ import eu.kanade.tachiyomi.domain.manga.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
import eu.kanade.tachiyomi.ui.library.LibraryItem
|
||||||
import eu.kanade.tachiyomi.ui.library.setBGAndFG
|
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.MainScope
|
||||||
|
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(
|
class BrowseSourceItem(
|
||||||
val manga: Manga,
|
initialManga: 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!!
|
||||||
|
var manga: Manga = initialManga
|
||||||
|
private set
|
||||||
|
// TODO: Could potentially cause memleak, test it with leakcanary before deploying to stable!
|
||||||
|
private val scope = MainScope()
|
||||||
|
private var job: Job? = null
|
||||||
|
|
||||||
override fun getLayoutRes(): Int {
|
override fun getLayoutRes(): Int {
|
||||||
return if (catalogueAsList.get()) {
|
return if (catalogueAsList.get()) {
|
||||||
R.layout.manga_list_item
|
R.layout.manga_list_item
|
||||||
|
@ -76,18 +92,34 @@ class BrowseSourceItem(
|
||||||
position: Int,
|
position: Int,
|
||||||
payloads: MutableList<Any?>?,
|
payloads: MutableList<Any?>?,
|
||||||
) {
|
) {
|
||||||
holder.onSetValues(manga)
|
if (job == null) holder.onSetValues(manga)
|
||||||
|
job?.cancel()
|
||||||
|
job = scope.launch {
|
||||||
|
getManga.subscribeByUrlAndSource(manga.url, manga.source).collectLatest {
|
||||||
|
manga = it ?: return@collectLatest
|
||||||
|
holder.onSetValues(manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun unbindViewHolder(
|
||||||
|
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?,
|
||||||
|
holder: BrowseSourceHolder?,
|
||||||
|
position: Int
|
||||||
|
) {
|
||||||
|
job?.cancel()
|
||||||
|
job = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other is BrowseSourceItem) {
|
if (other is BrowseSourceItem) {
|
||||||
return manga.id!! == other.manga.id!!
|
return mangaId == other.mangaId
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return manga.id!!.hashCode()
|
return mangaId.hashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue