mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-14 14:32:49 +01:00
parent
139663acfc
commit
a88422752b
@ -18,6 +18,7 @@ import eu.kanade.domain.manga.interactor.GetExcludedScanlators
|
|||||||
import eu.kanade.domain.manga.interactor.SetExcludedScanlators
|
import eu.kanade.domain.manga.interactor.SetExcludedScanlators
|
||||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||||
import eu.kanade.domain.manga.model.chaptersFiltered
|
import eu.kanade.domain.manga.model.chaptersFiltered
|
||||||
|
import eu.kanade.domain.manga.model.copyFrom
|
||||||
import eu.kanade.domain.manga.model.downloadedFilter
|
import eu.kanade.domain.manga.model.downloadedFilter
|
||||||
import eu.kanade.domain.manga.model.toSManga
|
import eu.kanade.domain.manga.model.toSManga
|
||||||
import eu.kanade.domain.track.interactor.AddTracks
|
import eu.kanade.domain.track.interactor.AddTracks
|
||||||
@ -227,12 +228,19 @@ class MangaScreenModel(
|
|||||||
|
|
||||||
// Fetch info-chapters when needed
|
// Fetch info-chapters when needed
|
||||||
if (screenModelScope.isActive) {
|
if (screenModelScope.isActive) {
|
||||||
|
if (source?.isLocal() == true) {
|
||||||
|
// `fetchChaptersFromSource` should be called before `fetchMangaFromSource`
|
||||||
|
// because `LocalSource.getChapterList` has side effects since 82bdf63
|
||||||
|
if (needRefreshChapter) fetchChaptersFromSource()
|
||||||
|
if (needRefreshInfo) fetchMangaFromSource()
|
||||||
|
} else {
|
||||||
val fetchFromSourceTasks = listOf(
|
val fetchFromSourceTasks = listOf(
|
||||||
async { if (needRefreshInfo) fetchMangaFromSource() },
|
async { if (needRefreshInfo) fetchMangaFromSource() },
|
||||||
async { if (needRefreshChapter) fetchChaptersFromSource() },
|
async { if (needRefreshChapter) fetchChaptersFromSource() },
|
||||||
)
|
)
|
||||||
fetchFromSourceTasks.awaitAll()
|
fetchFromSourceTasks.awaitAll()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initial loading finished
|
// Initial loading finished
|
||||||
updateSuccessState { it.copy(isRefreshingData = false) }
|
updateSuccessState { it.copy(isRefreshingData = false) }
|
||||||
@ -242,11 +250,18 @@ class MangaScreenModel(
|
|||||||
fun fetchAllFromSource(manualFetch: Boolean = true) {
|
fun fetchAllFromSource(manualFetch: Boolean = true) {
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
updateSuccessState { it.copy(isRefreshingData = true) }
|
updateSuccessState { it.copy(isRefreshingData = true) }
|
||||||
|
if (source?.isLocal() == true) {
|
||||||
|
// `fetchChaptersFromSource` should be called before `fetchMangaFromSource`
|
||||||
|
// because `LocalSource.getChapterList` has side effects since 82bdf63
|
||||||
|
fetchChaptersFromSource(manualFetch)
|
||||||
|
fetchMangaFromSource(manualFetch)
|
||||||
|
} else {
|
||||||
val fetchFromSourceTasks = listOf(
|
val fetchFromSourceTasks = listOf(
|
||||||
async { fetchMangaFromSource(manualFetch) },
|
async { fetchMangaFromSource(manualFetch) },
|
||||||
async { fetchChaptersFromSource(manualFetch) },
|
async { fetchChaptersFromSource(manualFetch) },
|
||||||
)
|
)
|
||||||
fetchFromSourceTasks.awaitAll()
|
fetchFromSourceTasks.awaitAll()
|
||||||
|
}
|
||||||
updateSuccessState { it.copy(isRefreshingData = false) }
|
updateSuccessState { it.copy(isRefreshingData = false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,7 +552,13 @@ class MangaScreenModel(
|
|||||||
val state = successState ?: return
|
val state = successState ?: return
|
||||||
try {
|
try {
|
||||||
withIOContext {
|
withIOContext {
|
||||||
val chapters = state.source.getChapterList(state.manga.toSManga())
|
val manga = state.manga.toSManga()
|
||||||
|
val chapters = state.source.getChapterList(manga)
|
||||||
|
|
||||||
|
// `LocalSource.getChapterList` has side effects since 82bdf63
|
||||||
|
if (state.source.isLocal()) {
|
||||||
|
updateSuccessState { it.copy(manga = it.manga.copyFrom(manga)) }
|
||||||
|
}
|
||||||
|
|
||||||
val newChapters = syncChaptersWithSource.await(
|
val newChapters = syncChaptersWithSource.await(
|
||||||
chapters,
|
chapters,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package tachiyomi.source.local
|
package tachiyomi.source.local
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
@ -285,7 +286,8 @@ actual class LocalSource(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the cover from the first chapter found if not available
|
// Copy the cover from the first chapter found if not available
|
||||||
if (manga.thumbnail_url.isNullOrBlank()) {
|
val cover = UniFile.fromUri(context, manga.thumbnail_url?.toUri())
|
||||||
|
if (cover?.let { ImageUtil.isImage(it.name) { it.openInputStream() } } != true) {
|
||||||
chapters.lastOrNull()?.let { chapter ->
|
chapters.lastOrNull()?.let { chapter ->
|
||||||
updateCover(chapter, manga)
|
updateCover(chapter, manga)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user