Fixes for merged manga settings

This commit is contained in:
Jobobby04 2022-11-15 00:25:42 -05:00
parent 5afc33becb
commit 1acb7a1a35
6 changed files with 17 additions and 13 deletions

View File

@ -68,6 +68,7 @@ class MangaMergeRepositoryImpl(
downloadChapters = value.downloadChapters?.toLong(), downloadChapters = value.downloadChapters?.toLong(),
infoManga = value.isInfoManga?.toLong(), infoManga = value.isInfoManga?.toLong(),
chapterPriority = value.chapterPriority?.toLong(), chapterPriority = value.chapterPriority?.toLong(),
chapterSortMode = value.chapterSortMode?.toLong(),
) )
} }
} }

View File

@ -8,8 +8,8 @@ import eu.kanade.tachiyomi.util.system.logcat
import exh.merged.sql.models.MergedMangaReference import exh.merged.sql.models.MergedMangaReference
import exh.source.MERGED_SOURCE_ID import exh.source.MERGED_SOURCE_ID
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import logcat.LogPriority import logcat.LogPriority
class GetMergedChapterByMangaId( class GetMergedChapterByMangaId(
@ -19,14 +19,14 @@ class GetMergedChapterByMangaId(
) { ) {
suspend fun await(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): List<Chapter> { suspend fun await(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): List<Chapter> {
return transformMergedChapters(mangaId, getFromDatabase(mangaId), editScanlators, dedupe) return transformMergedChapters(getMergedReferencesById.await(mangaId), getFromDatabase(mangaId), editScanlators, dedupe)
} }
suspend fun subscribe(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): Flow<List<Chapter>> { suspend fun subscribe(mangaId: Long, editScanlators: Boolean = false, dedupe: Boolean = true): Flow<List<Chapter>> {
return try { return try {
chapterRepository.getMergedChapterByMangaIdAsFlow(mangaId) chapterRepository.getMergedChapterByMangaIdAsFlow(mangaId)
.map { .combine(getMergedReferencesById.subscribe(mangaId)) { chapters, references ->
transformMergedChapters(mangaId, it, editScanlators, dedupe) transformMergedChapters(references, chapters, editScanlators, dedupe)
} }
} catch (e: Exception) { } catch (e: Exception) {
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
@ -44,8 +44,7 @@ class GetMergedChapterByMangaId(
} }
// TODO more chapter dedupe // TODO more chapter dedupe
suspend fun transformMergedChapters(mangaId: Long, chapterList: List<Chapter>, editScanlators: Boolean, dedupe: Boolean): List<Chapter> { fun transformMergedChapters(mangaReferences: List<MergedMangaReference>, chapterList: List<Chapter>, editScanlators: Boolean, dedupe: Boolean): List<Chapter> {
val mangaReferences = getMergedReferencesById.await(mangaId)
val chapters = if (editScanlators) { val chapters = if (editScanlators) {
val sources = mangaReferences.map { sourceManager.getOrStub(it.mangaSourceId) to it.mangaId } val sources = mangaReferences.map { sourceManager.getOrStub(it.mangaSourceId) to it.mangaId }
chapterList.map { chapter -> chapterList.map { chapter ->

View File

@ -6,4 +6,5 @@ data class MergeMangaSettingsUpdate(
var getChapterUpdates: Boolean?, var getChapterUpdates: Boolean?,
var chapterPriority: Int?, var chapterPriority: Int?,
var downloadChapters: Boolean?, var downloadChapters: Boolean?,
var chapterSortMode: Int?,
) )

View File

@ -654,11 +654,12 @@ class MangaInfoScreenModel(
updateMergedSettings.awaitAll( updateMergedSettings.awaitAll(
mergedMangaReferences.map { mergedMangaReferences.map {
MergeMangaSettingsUpdate( MergeMangaSettingsUpdate(
it.id!!, id = it.id!!,
it.isInfoManga, isInfoManga = it.isInfoManga,
it.getChapterUpdates, getChapterUpdates = it.getChapterUpdates,
it.chapterPriority, chapterPriority = it.chapterPriority,
it.downloadChapters, downloadChapters = it.downloadChapters,
chapterSortMode = it.chapterSortMode,
) )
}, },
) )

View File

@ -66,7 +66,7 @@ class EditMergedSettingsState(
mergedMangaAdapter?.isHandleDragEnabled = isPriorityOrder mergedMangaAdapter?.isHandleDragEnabled = isPriorityOrder
mergedMangaAdapter?.updateDataSet(mergedMangas.map { it.toModel() }) mergedMangaAdapter?.updateDataSet(mergedMangas.map { it.toModel() }.sortedBy { it.mergedMangaReference.chapterPriority })
} }
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
@ -143,6 +143,7 @@ class EditMergedSettingsState(
fun onPositiveButtonClick() { fun onPositiveButtonClick() {
onPositiveClick(listOfNotNull(mergeReference) + mergedMangas.map { it.second }) onPositiveClick(listOfNotNull(mergeReference) + mergedMangas.map { it.second })
onDismissRequest()
} }
} }

View File

@ -105,7 +105,8 @@ SET
get_chapter_updates = coalesce(:getChapterUpdates, get_chapter_updates), get_chapter_updates = coalesce(:getChapterUpdates, get_chapter_updates),
download_chapters = coalesce(:downloadChapters, download_chapters), download_chapters = coalesce(:downloadChapters, download_chapters),
info_manga = coalesce(:infoManga, info_manga), info_manga = coalesce(:infoManga, info_manga),
chapter_priority = coalesce(:chapterPriority, chapter_priority) chapter_priority = coalesce(:chapterPriority, chapter_priority),
chapter_sort_mode = coalesce(:chapterSortMode, chapter_sort_mode)
WHERE _id = :id; WHERE _id = :id;
deleteById: deleteById: