Show download progress in download icons
This commit is contained in:
@@ -705,7 +705,7 @@ class MangaController :
|
||||
}
|
||||
}
|
||||
|
||||
fun onChapterStatusChange(download: Download) {
|
||||
fun onChapterDownloadUpdate(download: Download) {
|
||||
chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let {
|
||||
chaptersAdapter?.updateItem(it)
|
||||
chaptersAdapter?.notifyDataSetChanged()
|
||||
|
||||
@@ -79,7 +79,8 @@ class MangaPresenter(
|
||||
/**
|
||||
* Subscription to observe download status changes.
|
||||
*/
|
||||
private var observeDownloadsSubscription: Subscription? = null
|
||||
private var observeDownloadsStatusSubscription: Subscription? = null
|
||||
private var observeDownloadsPageSubscription: Subscription? = null
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
@@ -293,12 +294,20 @@ class MangaPresenter(
|
||||
// Chapters list - start
|
||||
|
||||
private fun observeDownloads() {
|
||||
observeDownloadsSubscription?.let { remove(it) }
|
||||
observeDownloadsSubscription = downloadManager.queue.getStatusObservable()
|
||||
observeDownloadsStatusSubscription?.let { remove(it) }
|
||||
observeDownloadsStatusSubscription = downloadManager.queue.getStatusObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter { download -> download.manga.id == manga.id }
|
||||
.doOnNext { onDownloadStatusChange(it) }
|
||||
.subscribeLatestCache(MangaController::onChapterStatusChange) { _, error ->
|
||||
.subscribeLatestCache(MangaController::onChapterDownloadUpdate) { _, error ->
|
||||
Timber.e(error)
|
||||
}
|
||||
|
||||
observeDownloadsPageSubscription?.let { remove(it) }
|
||||
observeDownloadsPageSubscription = downloadManager.queue.getProgressObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter { download -> download.manga.id == manga.id }
|
||||
.subscribeLatestCache(MangaController::onChapterDownloadUpdate) { _, error ->
|
||||
Timber.e(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
addView(binding.root)
|
||||
}
|
||||
|
||||
fun setState(state: Download.State) {
|
||||
fun setState(state: Download.State, progress: Int = 0) {
|
||||
binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED
|
||||
|
||||
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.DOWNLOADING
|
||||
@@ -44,7 +44,13 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
}
|
||||
|
||||
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING || state == Download.State.QUEUE
|
||||
// TODO: show actual download progress
|
||||
// Spinner when queued
|
||||
val isDownloading = state == Download.State.DOWNLOADING || (state == Download.State.QUEUE && progress > 0)
|
||||
binding.downloadProgress.isIndeterminate = !isDownloading
|
||||
// Actual progress when downloading or partially downloaded
|
||||
if (isDownloading) {
|
||||
binding.downloadProgress.progress = progress
|
||||
}
|
||||
|
||||
binding.downloadedIcon.isVisible = state == Download.State.DOWNLOADED
|
||||
|
||||
|
||||
@@ -69,6 +69,6 @@ class ChapterHolder(
|
||||
}
|
||||
|
||||
binding.download.isVisible = item.manga.source != LocalSource.ID
|
||||
binding.download.setState(item.status)
|
||||
binding.download.setState(item.status, item.progress)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
|
||||
class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
||||
AbstractFlexibleItem<ChapterHolder>(),
|
||||
@@ -22,6 +23,12 @@ class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
||||
_status = value
|
||||
}
|
||||
|
||||
val progress: Int
|
||||
get() {
|
||||
val pages = download?.pages ?: return 0
|
||||
return pages.map(Page::progress).average().toInt()
|
||||
}
|
||||
|
||||
@Transient
|
||||
var download: Download? = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user