Skip to content

Commit

Permalink
Update download indicator on progress and status change.
Browse files Browse the repository at this point in the history
  • Loading branch information
NGB-Was-Taken committed Oct 14, 2024
1 parent fb3f1b1 commit 581c1c5
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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*/ },
Expand Down

0 comments on commit 581c1c5

Please sign in to comment.