mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-11 11:38:56 +01:00
Refactor download states into enum
This commit is contained in:
@@ -172,17 +172,17 @@ class DownloadController :
|
||||
*/
|
||||
private fun onStatusChange(download: Download) {
|
||||
when (download.status) {
|
||||
Download.DOWNLOADING -> {
|
||||
Download.State.DOWNLOADING -> {
|
||||
observeProgress(download)
|
||||
// Initial update of the downloaded pages
|
||||
onUpdateDownloadedPages(download)
|
||||
}
|
||||
Download.DOWNLOADED -> {
|
||||
Download.State.DOWNLOADED -> {
|
||||
unsubscribeProgress(download)
|
||||
onUpdateProgress(download)
|
||||
onUpdateDownloadedPages(download)
|
||||
}
|
||||
Download.ERROR -> unsubscribeProgress(download)
|
||||
Download.State.ERROR -> unsubscribeProgress(download)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -957,7 +957,7 @@ class MangaController :
|
||||
// OVERFLOW MENU DIALOGS
|
||||
|
||||
private fun getUnreadChaptersSorted() = presenter.chapters
|
||||
.filter { !it.read && it.status == Download.NOT_DOWNLOADED }
|
||||
.filter { !it.read && it.status == Download.State.NOT_DOWNLOADED }
|
||||
.distinctBy { it.name }
|
||||
.sortedByDescending { it.source_order }
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ class MangaPresenter(
|
||||
private fun setDownloadedChapters(chapters: List<ChapterItem>) {
|
||||
chapters
|
||||
.filter { downloadManager.isChapterDownloaded(it, manga) }
|
||||
.forEach { it.status = Download.DOWNLOADED }
|
||||
.forEach { it.status = Download.State.DOWNLOADED }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +416,7 @@ class MangaPresenter(
|
||||
*/
|
||||
private fun onDownloadStatusChange(download: Download) {
|
||||
// Assign the download to the model object.
|
||||
if (download.status == Download.QUEUE) {
|
||||
if (download.status == Download.State.QUEUE) {
|
||||
chapters.find { it.id == download.chapter.id }?.let {
|
||||
if (it.download == null) {
|
||||
it.download = download
|
||||
@@ -425,7 +425,7 @@ class MangaPresenter(
|
||||
}
|
||||
|
||||
// Force UI update if downloaded filter active and download finished.
|
||||
if (onlyDownloaded() != State.IGNORE && download.status == Download.DOWNLOADED) {
|
||||
if (onlyDownloaded() != State.IGNORE && download.status == Download.State.DOWNLOADED) {
|
||||
refreshChapters()
|
||||
}
|
||||
}
|
||||
@@ -514,7 +514,7 @@ class MangaPresenter(
|
||||
private fun deleteChaptersInternal(chapters: List<ChapterItem>) {
|
||||
downloadManager.deleteChapters(chapters, manga, source).forEach {
|
||||
if (it is ChapterItem) {
|
||||
it.status = Download.NOT_DOWNLOADED
|
||||
it.status = Download.State.NOT_DOWNLOADED
|
||||
it.download = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.view.isVisible
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.databinding.ChapterDownloadViewBinding
|
||||
|
||||
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
@@ -17,20 +18,12 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
addView(binding.root)
|
||||
}
|
||||
|
||||
fun setState(state: State) {
|
||||
binding.downloadIconBorder.isVisible = state == State.DOWNLOAD || state == State.ERROR
|
||||
binding.downloadIcon.isVisible = state == State.DOWNLOAD || state == State.DOWNLOADING
|
||||
fun setState(state: Download.State) {
|
||||
binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.ERROR
|
||||
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.DOWNLOADING
|
||||
|
||||
binding.downloadProgress.isVisible = state == State.DOWNLOADING || state == State.QUEUED
|
||||
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING || state == Download.State.QUEUE
|
||||
|
||||
binding.downloadedIcon.isVisible = state == State.DOWNLOADED
|
||||
}
|
||||
|
||||
enum class State {
|
||||
DOWNLOAD,
|
||||
QUEUED,
|
||||
DOWNLOADING,
|
||||
ERROR,
|
||||
DOWNLOADED,
|
||||
binding.downloadedIcon.isVisible = state == Download.State.DOWNLOADED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import androidx.core.view.isVisible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.databinding.ChaptersItemBinding
|
||||
import java.util.Date
|
||||
|
||||
@@ -68,16 +67,6 @@ class ChapterHolder(
|
||||
binding.chapterDescription.text = ""
|
||||
}
|
||||
|
||||
notifyStatus(item.status)
|
||||
}
|
||||
|
||||
private fun notifyStatus(status: Int) = with(binding.download) {
|
||||
when (status) {
|
||||
Download.QUEUE -> setState(ChapterDownloadView.State.QUEUED)
|
||||
Download.DOWNLOADING -> setState(ChapterDownloadView.State.DOWNLOADING)
|
||||
Download.DOWNLOADED -> setState(ChapterDownloadView.State.DOWNLOADED)
|
||||
Download.ERROR -> setState(ChapterDownloadView.State.ERROR)
|
||||
else -> setState(ChapterDownloadView.State.DOWNLOAD)
|
||||
}
|
||||
binding.download.setState(item.status)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
||||
AbstractFlexibleItem<ChapterHolder>(),
|
||||
Chapter by chapter {
|
||||
|
||||
private var _status: Int = 0
|
||||
private var _status: Download.State = Download.State.NOT_DOWNLOADED
|
||||
|
||||
var status: Int
|
||||
var status: Download.State
|
||||
get() = download?.status ?: _status
|
||||
set(value) {
|
||||
_status = value
|
||||
@@ -26,7 +26,7 @@ class ChapterItem(val chapter: Chapter, val manga: Manga) :
|
||||
var download: Download? = null
|
||||
|
||||
val isDownloaded: Boolean
|
||||
get() = status == Download.DOWNLOADED
|
||||
get() = status == Download.State.DOWNLOADED
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.chapters_item
|
||||
|
||||
@@ -81,18 +81,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
||||
.into(binding.mangaCover)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates chapter status in view.
|
||||
*
|
||||
* @param status download status
|
||||
*/
|
||||
fun notifyStatus(status: Int) = with(binding.downloadText) {
|
||||
when (status) {
|
||||
Download.QUEUE -> setText(R.string.chapter_queued)
|
||||
Download.DOWNLOADING -> setText(R.string.chapter_downloading)
|
||||
Download.DOWNLOADED -> setText(R.string.chapter_downloaded)
|
||||
Download.ERROR -> setText(R.string.chapter_error)
|
||||
else -> text = ""
|
||||
}
|
||||
fun notifyStatus(state: Download.State) {
|
||||
binding.download.setState(state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
||||
class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionItem) :
|
||||
AbstractSectionableItem<UpdatesHolder, DateSectionItem>(header) {
|
||||
|
||||
private var _status: Int = 0
|
||||
private var _status: Download.State = Download.State.NOT_DOWNLOADED
|
||||
|
||||
var status: Int
|
||||
var status: Download.State
|
||||
get() = download?.status ?: _status
|
||||
set(value) {
|
||||
_status = value
|
||||
@@ -26,7 +26,7 @@ class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionIte
|
||||
var download: Download? = null
|
||||
|
||||
val isDownloaded: Boolean
|
||||
get() = status == Download.DOWNLOADED
|
||||
get() = status == Download.State.DOWNLOADED
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.updates_item
|
||||
|
||||
@@ -108,7 +108,7 @@ class UpdatesPresenter(
|
||||
val chapter = item.chapter
|
||||
|
||||
if (downloadManager.isChapterDownloaded(chapter, manga)) {
|
||||
item.status = Download.DOWNLOADED
|
||||
item.status = Download.State.DOWNLOADED
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class UpdatesPresenter(
|
||||
*/
|
||||
private fun onDownloadStatusChange(download: Download) {
|
||||
// Assign the download to the model object.
|
||||
if (download.status == Download.QUEUE) {
|
||||
if (download.status == Download.State.QUEUE) {
|
||||
val chapter = chapters.find { it.chapter.id == download.chapter.id }
|
||||
if (chapter != null && chapter.download == null) {
|
||||
chapter.download = download
|
||||
@@ -188,7 +188,7 @@ class UpdatesPresenter(
|
||||
|
||||
downloadManager.deleteChapters(chapters, manga, source)
|
||||
items.forEach {
|
||||
it.status = Download.NOT_DOWNLOADED
|
||||
it.status = Download.State.NOT_DOWNLOADED
|
||||
it.download = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user