@@ -4,6 +4,9 @@ import io.theficos.ereader.core.model.DocumentIdentity
44import io.theficos.ereader.data.library.LibraryItemResponse
55import io.theficos.ereader.data.sync.ProgressItemDto
66
7+ /* * Live progress of a restore run: [done] of [total] candidate books processed. */
8+ data class RestoreProgress (val done : Int , val total : Int )
9+
710/* * Outcome counters for one restore run, rendered as a snackbar summary. */
811data class RestoreSummary (
912 val requested : Int ,
@@ -48,7 +51,7 @@ class RestoreInProgressUseCase(
4851 private val applyPositions : suspend (List <ProgressItemDto >) -> Unit ,
4952 private val minPercentExclusive : Double = 0.0 ,
5053) {
51- suspend fun run (): RestoreSummary {
54+ suspend fun run (onProgress : (done: Int , total: Int ) -> Unit = { _, _ -> } ): RestoreSummary {
5255 val mirrorByHash = fetchLibraryItems().associateBy { it.contentHash }
5356 val inProgress = fetchInProgress().filter {
5457 it.finishedAt == null && it.abandonedAt == null && it.percent > minPercentExclusive
@@ -59,11 +62,13 @@ class RestoreInProgressUseCase(
5962 RestoreCandidate (progress = p, opdsHref = href, title = item.title, authors = item.authors)
6063 }
6164
65+ onProgress(0 , candidates.size)
66+
6267 var downloaded = 0
6368 var skippedExisting = 0
6469 var skippedUnfetchable = 0
6570 var failed = 0
66- for (c in candidates) {
71+ candidates.forEachIndexed { index, c ->
6772 when {
6873 ! isHttp(c.opdsHref) -> skippedUnfetchable++
6974 isPresent(c.identity) -> skippedExisting++
@@ -74,6 +79,7 @@ class RestoreInProgressUseCase(
7479 failed++
7580 }
7681 }
82+ onProgress(index + 1 , candidates.size)
7783 }
7884
7985 // Restore positions for every in-progress item; items whose document
0 commit comments