Fix merged manga chapters and merged manga filtered scanlators

This commit is contained in:
Jobobby04
2023-12-27 16:30:56 -05:00
parent d82b2919f8
commit 25f94e4500
5 changed files with 65 additions and 6 deletions
@@ -21,4 +21,16 @@ class GetAvailableScanlators(
return repository.getScanlatorsByMangaIdAsFlow(mangaId)
.map { it.cleanupAvailableScanlators() }
}
// SY -->
suspend fun awaitMerge(mangaId: Long): Set<String> {
return repository.getScanlatorsByMergeId(mangaId)
.cleanupAvailableScanlators()
}
fun subscribeMerge(mangaId: Long): Flow<Set<String>> {
return repository.getScanlatorsByMergeIdAsFlow(mangaId)
.map { it.cleanupAvailableScanlators() }
}
// SY <--
}
@@ -71,7 +71,10 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
@@ -341,6 +344,20 @@ class MangaScreenModel(
screenModelScope.launchIO {
getAvailableScanlators.subscribe(mangaId)
.distinctUntilChanged()
// SY -->
.combine(
state.map { (it as? State.Success)?.manga }
.distinctUntilChangedBy { it?.source }
.flatMapConcat {
if (it?.source == MERGED_SOURCE_ID) {
getAvailableScanlators.subscribeMerge(mangaId)
} else {
flowOf(emptySet())
}
}
) { mangaScanlators, mergeScanlators ->
mangaScanlators + mergeScanlators
} // SY <--
.collectLatest { availableScanlators ->
updateSuccessState {
it.copy(availableScanlators = availableScanlators.toImmutableSet())
@@ -381,7 +398,13 @@ class MangaScreenModel(
source = source,
isFromSource = isFromSource,
chapters = chapters,
availableScanlators = getAvailableScanlators.await(mangaId).toImmutableSet(),
// SY -->
availableScanlators = if (manga.source == MERGED_SOURCE_ID) {
getAvailableScanlators.awaitMerge(mangaId)
} else {
getAvailableScanlators.await(mangaId)
}.toImmutableSet(),
// SY <--
excludedScanlators = getExcludedScanlators.await(mangaId).toImmutableSet(),
isRefreshingData = needRefreshInfo || needRefreshChapter,
dialog = null,