Refactor download states into enum
This commit is contained in:
@@ -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