Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class ChaptersLoader @Inject constructor(
return true
}

@CheckResult
suspend fun loadSingleChapter(chapterId: Long): Boolean {
val pages = loadChapter(chapterId)
return mutex.withLock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class PageLoader @Inject constructor(
return task
}

suspend fun updateCache(page: MangaPage) {
val progress = MutableStateFlow(PROGRESS_UNDEFINED)
loadPageImpl(page, progress, isPrefetch = false, skipCache = true)
}

suspend fun loadPage(page: MangaPage, force: Boolean): Uri {
return loadPageAsync(page, force).await()
}
Expand Down Expand Up @@ -283,7 +288,7 @@ class PageLoader @Inject constructor(
val pageUrl = getPageUrl(page)
check(pageUrl.isNotBlank()) { "Cannot obtain full image url for $page" }
if (!skipCache) {
cache.get(pageUrl)?.let { return it.toUri() }
cache[pageUrl]?.let { return it.toUri() }
}
val uri = pageUrl.toUri()
return when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class ReaderActivity :
applyDoubleModeAuto()
}

override fun onDestroy() {
super.onDestroy()
viewModel.updateReadingProgress()
}

override fun getParentActivityIntent(): Intent? {
val manga = viewModel.getMangaOrNull() ?: return null
return AppRouter.detailsIntent(this, manga)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import io.github.landwarderer.futon.core.util.ext.requireValue
import io.github.landwarderer.futon.details.data.MangaDetails
import io.github.landwarderer.futon.details.domain.DetailsInteractor
import io.github.landwarderer.futon.details.domain.DetailsLoadUseCase
import io.github.landwarderer.futon.details.domain.ProgressUpdateUseCase
import io.github.landwarderer.futon.details.ui.pager.ChaptersPagesViewModel
import io.github.landwarderer.futon.details.ui.pager.EmptyMangaReason
import io.github.landwarderer.futon.download.ui.worker.DownloadWorker
Expand All @@ -69,6 +70,9 @@ import io.github.landwarderer.futon.reader.ui.config.ReaderSettings
import io.github.landwarderer.futon.reader.ui.pager.ReaderUiState
import io.github.landwarderer.futon.scrobbling.discord.ui.DiscordRpc
import io.github.landwarderer.futon.stats.domain.StatsCollector
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.time.Instant
import javax.inject.Inject

Expand All @@ -88,6 +92,7 @@ class ReaderViewModel @Inject constructor(
private val detailsLoadUseCase: DetailsLoadUseCase,
private val historyUpdateUseCase: HistoryUpdateUseCase,
private val detectReaderModeUseCase: DetectReaderModeUseCase,
private val progressUpdateUseCase: ProgressUpdateUseCase,
private val statsCollector: StatsCollector,
private val discordRpc: DiscordRpc,
@LocalStorageChanges localStorageChanges: SharedFlow<LocalManga?>,
Expand Down Expand Up @@ -404,6 +409,20 @@ class ReaderViewModel @Inject constructor(
}
}

fun updateReadingProgress() {
viewModelScope.launch {
withContext(Dispatchers.IO) {
manga.collectLatest {
if (it != null) {
progressUpdateUseCase(it)
}
}

pageLoader.updateCache(getCurrentPage()!!)
}
}
}

private fun loadImpl() {
loadingJob = launchLoadingJob(Dispatchers.IO + EventExceptionHandler(onLoadingError)) {
var exception: Exception? = null
Expand Down
Loading