mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Show download progress in download icons
This commit is contained in:
parent
3cb64669e4
commit
0e2b8b10d1
@ -705,7 +705,7 @@ class MangaController :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onChapterStatusChange(download: Download) {
|
fun onChapterDownloadUpdate(download: Download) {
|
||||||
chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let {
|
chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let {
|
||||||
chaptersAdapter?.updateItem(it)
|
chaptersAdapter?.updateItem(it)
|
||||||
chaptersAdapter?.notifyDataSetChanged()
|
chaptersAdapter?.notifyDataSetChanged()
|
||||||
|
@ -79,7 +79,8 @@ class MangaPresenter(
|
|||||||
/**
|
/**
|
||||||
* Subscription to observe download status changes.
|
* 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?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
@ -293,12 +294,20 @@ class MangaPresenter(
|
|||||||
// Chapters list - start
|
// Chapters list - start
|
||||||
|
|
||||||
private fun observeDownloads() {
|
private fun observeDownloads() {
|
||||||
observeDownloadsSubscription?.let { remove(it) }
|
observeDownloadsStatusSubscription?.let { remove(it) }
|
||||||
observeDownloadsSubscription = downloadManager.queue.getStatusObservable()
|
observeDownloadsStatusSubscription = downloadManager.queue.getStatusObservable()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.filter { download -> download.manga.id == manga.id }
|
.filter { download -> download.manga.id == manga.id }
|
||||||
.doOnNext { onDownloadStatusChange(it) }
|
.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)
|
Timber.e(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
addView(binding.root)
|
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.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED
|
||||||
|
|
||||||
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.DOWNLOADING
|
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
|
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
|
binding.downloadedIcon.isVisible = state == Download.State.DOWNLOADED
|
||||||
|
|
||||||
|
@ -69,6 +69,6 @@ class ChapterHolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.download.isVisible = item.manga.source != LocalSource.ID
|
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.Chapter
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
|
|
||||||
class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
||||||
AbstractFlexibleItem<ChapterHolder>(),
|
AbstractFlexibleItem<ChapterHolder>(),
|
||||||
@ -22,6 +23,12 @@ class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
|||||||
_status = value
|
_status = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val progress: Int
|
||||||
|
get() {
|
||||||
|
val pages = download?.pages ?: return 0
|
||||||
|
return pages.map(Page::progress).average().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var download: Download? = null
|
var download: Download? = null
|
||||||
|
|
||||||
|
@ -229,16 +229,13 @@ class UpdatesController :
|
|||||||
* Update download status of chapter
|
* Update download status of chapter
|
||||||
* @param download [Download] object containing download progress.
|
* @param download [Download] object containing download progress.
|
||||||
*/
|
*/
|
||||||
fun onChapterStatusChange(download: Download) {
|
fun onChapterDownloadUpdate(download: Download) {
|
||||||
getHolder(download)?.notifyStatus(download.status)
|
adapter?.currentItems
|
||||||
}
|
?.filterIsInstance<UpdatesItem>()
|
||||||
|
?.find { it.chapter.id == download.chapter.id }?.let {
|
||||||
/**
|
adapter?.updateItem(it)
|
||||||
* Returns holder belonging to chapter
|
adapter?.notifyDataSetChanged()
|
||||||
* @param download [Download] object containing download progress.
|
}
|
||||||
*/
|
|
||||||
private fun getHolder(download: Download): UpdatesHolder? {
|
|
||||||
return binding.recycler.findViewHolderForItemId(download.chapter.id!!) as? UpdatesHolder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,6 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
|||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import eu.davidea.viewholders.FlexibleViewHolder
|
import eu.davidea.viewholders.FlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||||
import eu.kanade.tachiyomi.databinding.UpdatesItemBinding
|
import eu.kanade.tachiyomi.databinding.UpdatesItemBinding
|
||||||
@ -52,7 +51,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
|||||||
|
|
||||||
// Set chapter status
|
// Set chapter status
|
||||||
binding.download.isVisible = item.manga.source != LocalSource.ID
|
binding.download.isVisible = item.manga.source != LocalSource.ID
|
||||||
notifyStatus(item.status)
|
binding.download.setState(item.status, item.progress)
|
||||||
|
|
||||||
// Set cover
|
// Set cover
|
||||||
GlideApp.with(itemView.context).clear(binding.mangaCover)
|
GlideApp.with(itemView.context).clear(binding.mangaCover)
|
||||||
@ -66,8 +65,4 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
|||||||
.dontAnimate()
|
.dontAnimate()
|
||||||
.into(binding.mangaCover)
|
.into(binding.mangaCover)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun notifyStatus(state: Download.State) {
|
|
||||||
binding.download.setState(state)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
||||||
|
|
||||||
class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionItem) :
|
class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionItem) :
|
||||||
@ -22,6 +23,12 @@ class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionIte
|
|||||||
_status = value
|
_status = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val progress: Int
|
||||||
|
get() {
|
||||||
|
val pages = download?.pages ?: return 0
|
||||||
|
return pages.map(Page::progress).average().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var download: Download? = null
|
var download: Download? = null
|
||||||
|
|
||||||
|
@ -39,8 +39,16 @@ class UpdatesPresenter(
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribeLatestCache(UpdatesController::onNextRecentChapters)
|
.subscribeLatestCache(UpdatesController::onNextRecentChapters)
|
||||||
|
|
||||||
getChapterStatusObservable()
|
downloadManager.queue.getStatusObservable()
|
||||||
.subscribeLatestCache(UpdatesController::onChapterStatusChange) { _, error ->
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext { onDownloadStatusChange(it) }
|
||||||
|
.subscribeLatestCache(UpdatesController::onChapterDownloadUpdate) { _, error ->
|
||||||
|
Timber.e(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadManager.queue.getProgressObservable()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribeLatestCache(UpdatesController::onChapterDownloadUpdate) { _, error ->
|
||||||
Timber.e(error)
|
Timber.e(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,17 +94,6 @@ class UpdatesPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns observable containing chapter status.
|
|
||||||
*
|
|
||||||
* @return download object containing download progress.
|
|
||||||
*/
|
|
||||||
private fun getChapterStatusObservable(): Observable<Download> {
|
|
||||||
return downloadManager.queue.getStatusObservable()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.doOnNext { download -> onDownloadStatusChange(download) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and assigns the list of downloaded chapters.
|
* Finds and assigns the list of downloaded chapters.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user