Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local source cover updating #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import eu.kanade.domain.manga.interactor.GetExcludedScanlators
import eu.kanade.domain.manga.interactor.SetExcludedScanlators
import eu.kanade.domain.manga.interactor.UpdateManga
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.toSManga
import eu.kanade.domain.track.interactor.AddTracks
Expand Down Expand Up @@ -227,11 +228,18 @@ class MangaScreenModel(

// Fetch info-chapters when needed
if (screenModelScope.isActive) {
val fetchFromSourceTasks = listOf(
async { if (needRefreshInfo) fetchMangaFromSource() },
async { if (needRefreshChapter) fetchChaptersFromSource() },
)
fetchFromSourceTasks.awaitAll()
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(
async { if (needRefreshInfo) fetchMangaFromSource() },
async { if (needRefreshChapter) fetchChaptersFromSource() },
)
fetchFromSourceTasks.awaitAll()
}
}

// Initial loading finished
Expand All @@ -242,11 +250,18 @@ class MangaScreenModel(
fun fetchAllFromSource(manualFetch: Boolean = true) {
screenModelScope.launch {
updateSuccessState { it.copy(isRefreshingData = true) }
val fetchFromSourceTasks = listOf(
async { fetchMangaFromSource(manualFetch) },
async { fetchChaptersFromSource(manualFetch) },
)
fetchFromSourceTasks.awaitAll()
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(
async { fetchMangaFromSource(manualFetch) },
async { fetchChaptersFromSource(manualFetch) },
)
fetchFromSourceTasks.awaitAll()
}
updateSuccessState { it.copy(isRefreshingData = false) }
}
}
Expand Down Expand Up @@ -537,7 +552,13 @@ class MangaScreenModel(
val state = successState ?: return
try {
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(
chapters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tachiyomi.source.local

import android.content.Context
import androidx.core.net.toUri
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source
Expand Down Expand Up @@ -285,7 +286,8 @@ actual class LocalSource(
}

// 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 ->
updateCover(chapter, manga)
}
Expand Down