From 581c1c5780496852e33395c18caa429b558f1582 Mon Sep 17 00:00:00 2001 From: NGB-Was-Taken <76197326+NGB-Was-Taken@users.noreply.github.com> Date: Sat, 7 Sep 2024 15:04:50 +0545 Subject: [PATCH] Update download indicator on progress and status change. --- .../kanade/presentation/reader/ChapterListDialog.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/reader/ChapterListDialog.kt b/app/src/main/java/eu/kanade/presentation/reader/ChapterListDialog.kt index eb47115405ac..7d5369c78ebc 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ChapterListDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/ChapterListDialog.kt @@ -22,6 +22,8 @@ import eu.kanade.tachiyomi.util.lang.toRelativeString import exh.metadata.MetadataUtil import exh.source.isEhBasedManga import kotlinx.collections.immutable.ImmutableList +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.map import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.source.local.isLocal @@ -45,6 +47,7 @@ fun ChapterListDialog( val context = LocalContext.current val state = rememberLazyListState(chapters.indexOfFirst { it.isCurrent }.coerceAtLeast(0)) val downloadManager: DownloadManager = remember { Injekt.get() } + val downloadQueueState by downloadManager.queueState.collectAsState() AdaptiveSheet( onDismissRequest = onDismissRequest, @@ -58,7 +61,13 @@ fun ChapterListDialog( items = chapters, key = { "chapter-${it.chapter.id}" }, ) { chapterItem -> - val activeDownload = downloadManager.getQueuedDownloadOrNull(chapterItem.chapter.id) + val activeDownload = downloadQueueState.find { it.chapter.id == chapterItem.chapter.id } + val progress = activeDownload?.let { + downloadManager.progressFlow() + .filter { it.chapter.id == chapterItem.chapter.id } + .map { it.progress } + .collectAsState(0).value + } ?: 0 val downloaded = if (chapterItem.manga.isLocal()) { true } else { @@ -99,7 +108,7 @@ fun ChapterListDialog( selected = false, downloadIndicatorEnabled = false, downloadStateProvider = { downloadState }, - downloadProgressProvider = { activeDownload?.progress ?: 0 }, + downloadProgressProvider = { progress }, chapterSwipeStartAction = LibraryPreferences.ChapterSwipeAction.ToggleBookmark, chapterSwipeEndAction = LibraryPreferences.ChapterSwipeAction.ToggleBookmark, onLongClick = { /*TODO*/ },