mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 05:59:17 +01:00
Using an enum to represent download states
no need for the value int in upsteam, since enums can compare already Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
8cadb283f8
commit
22f2ef18b1
@ -111,8 +111,8 @@ class Downloader(
|
|||||||
notifier.paused = false
|
notifier.paused = false
|
||||||
if (!subscriptions.hasSubscriptions()) initializeSubscriptions()
|
if (!subscriptions.hasSubscriptions()) initializeSubscriptions()
|
||||||
|
|
||||||
val pending = queue.filter { it.status != Download.DOWNLOADED }
|
val pending = queue.filter { it.status != Download.State.DOWNLOADED }
|
||||||
pending.forEach { if (it.status != Download.QUEUE) it.status = Download.QUEUE }
|
pending.forEach { if (it.status != Download.State.QUEUE) it.status = Download.State.QUEUE }
|
||||||
|
|
||||||
downloadsRelay.call(pending)
|
downloadsRelay.call(pending)
|
||||||
return pending.isNotEmpty()
|
return pending.isNotEmpty()
|
||||||
@ -124,8 +124,8 @@ class Downloader(
|
|||||||
fun stop(reason: String? = null) {
|
fun stop(reason: String? = null) {
|
||||||
destroySubscriptions()
|
destroySubscriptions()
|
||||||
queue
|
queue
|
||||||
.filter { it.status == Download.DOWNLOADING }
|
.filter { it.status == Download.State.DOWNLOADING }
|
||||||
.forEach { it.status = Download.ERROR }
|
.forEach { it.status = Download.State.ERROR }
|
||||||
|
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
notifier.onWarning(reason)
|
notifier.onWarning(reason)
|
||||||
@ -149,8 +149,8 @@ class Downloader(
|
|||||||
fun pause() {
|
fun pause() {
|
||||||
destroySubscriptions()
|
destroySubscriptions()
|
||||||
queue
|
queue
|
||||||
.filter { it.status == Download.DOWNLOADING }
|
.filter { it.status == Download.State.DOWNLOADING }
|
||||||
.forEach { it.status = Download.QUEUE }
|
.forEach { it.status = Download.State.QUEUE }
|
||||||
notifier.paused = true
|
notifier.paused = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +170,8 @@ class Downloader(
|
|||||||
// Needed to update the chapter view
|
// Needed to update the chapter view
|
||||||
if (isNotification) {
|
if (isNotification) {
|
||||||
queue
|
queue
|
||||||
.filter { it.status == Download.QUEUE }
|
.filter { it.status == Download.State.QUEUE }
|
||||||
.forEach { it.status = Download.NOT_DOWNLOADED }
|
.forEach { it.status = Download.State.NOT_DOWNLOADED }
|
||||||
}
|
}
|
||||||
queue.clear()
|
queue.clear()
|
||||||
notifier.dismiss()
|
notifier.dismiss()
|
||||||
@ -185,8 +185,8 @@ class Downloader(
|
|||||||
fun clearQueue(manga: Manga, isNotification: Boolean = false) {
|
fun clearQueue(manga: Manga, isNotification: Boolean = false) {
|
||||||
// Needed to update the chapter view
|
// Needed to update the chapter view
|
||||||
if (isNotification) {
|
if (isNotification) {
|
||||||
queue.filter { it.status == Download.QUEUE && it.manga.id == manga.id }
|
queue.filter { it.status == Download.State.QUEUE && it.manga.id == manga.id }
|
||||||
.forEach { it.status = Download.NOT_DOWNLOADED }
|
.forEach { it.status = Download.State.NOT_DOWNLOADED }
|
||||||
}
|
}
|
||||||
queue.remove(manga)
|
queue.remove(manga)
|
||||||
if (queue.isEmpty()) {
|
if (queue.isEmpty()) {
|
||||||
@ -294,7 +294,7 @@ class Downloader(
|
|||||||
|
|
||||||
val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
|
val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
|
||||||
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
|
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
|
||||||
download.status = Download.ERROR
|
download.status = Download.State.ERROR
|
||||||
notifier.onError(context.getString(R.string.couldnt_download_low_space), download.chapter.name)
|
notifier.onError(context.getString(R.string.couldnt_download_low_space), download.chapter.name)
|
||||||
return@defer Observable.just(download)
|
return@defer Observable.just(download)
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ class Downloader(
|
|||||||
?.forEach { it.delete() }
|
?.forEach { it.delete() }
|
||||||
|
|
||||||
download.downloadedImages = 0
|
download.downloadedImages = 0
|
||||||
download.status = Download.DOWNLOADING
|
download.status = Download.State.DOWNLOADING
|
||||||
}
|
}
|
||||||
// Get all the URLs to the source images, fetch pages if necessary
|
// Get all the URLs to the source images, fetch pages if necessary
|
||||||
.flatMap { download.source.fetchAllImageUrlsFromPageList(it) }
|
.flatMap { download.source.fetchAllImageUrlsFromPageList(it) }
|
||||||
@ -338,7 +338,7 @@ class Downloader(
|
|||||||
.doOnNext { ensureSuccessfulDownload(download, mangaDir, tmpDir, chapterDirname) }
|
.doOnNext { ensureSuccessfulDownload(download, mangaDir, tmpDir, chapterDirname) }
|
||||||
// If the page list threw, it will resume here
|
// If the page list threw, it will resume here
|
||||||
.onErrorReturn { error ->
|
.onErrorReturn { error ->
|
||||||
download.status = Download.ERROR
|
download.status = Download.State.ERROR
|
||||||
notifier.onError(error.message, download.chapter.name)
|
notifier.onError(error.message, download.chapter.name)
|
||||||
download
|
download
|
||||||
}
|
}
|
||||||
@ -491,13 +491,13 @@ class Downloader(
|
|||||||
val downloadedImages = tmpDir.listFiles().orEmpty().filterNot { it.name!!.endsWith(".tmp") }
|
val downloadedImages = tmpDir.listFiles().orEmpty().filterNot { it.name!!.endsWith(".tmp") }
|
||||||
|
|
||||||
download.status = if (downloadedImages.size == download.pages!!.size) {
|
download.status = if (downloadedImages.size == download.pages!!.size) {
|
||||||
Download.DOWNLOADED
|
Download.State.DOWNLOADED
|
||||||
} else {
|
} else {
|
||||||
Download.ERROR
|
Download.State.ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only rename the directory if it's downloaded.
|
// Only rename the directory if it's downloaded.
|
||||||
if (download.status == Download.DOWNLOADED) {
|
if (download.status == Download.State.DOWNLOADED) {
|
||||||
tmpDir.renameTo(dirname)
|
tmpDir.renameTo(dirname)
|
||||||
cache.addChapter(dirname, mangaDir, download.manga)
|
cache.addChapter(dirname, mangaDir, download.manga)
|
||||||
|
|
||||||
@ -510,7 +510,7 @@ class Downloader(
|
|||||||
*/
|
*/
|
||||||
private fun completeDownload(download: Download) {
|
private fun completeDownload(download: Download) {
|
||||||
// Delete successful downloads from queue
|
// Delete successful downloads from queue
|
||||||
if (download.status == Download.DOWNLOADED) {
|
if (download.status == Download.State.DOWNLOADED) {
|
||||||
// remove downloaded chapter from queue
|
// remove downloaded chapter from queue
|
||||||
queue.remove(download)
|
queue.remove(download)
|
||||||
}
|
}
|
||||||
@ -527,7 +527,7 @@ class Downloader(
|
|||||||
* Returns true if all the queued downloads are in DOWNLOADED or ERROR state.
|
* Returns true if all the queued downloads are in DOWNLOADED or ERROR state.
|
||||||
*/
|
*/
|
||||||
private fun areAllDownloadsFinished(): Boolean {
|
private fun areAllDownloadsFinished(): Boolean {
|
||||||
return queue.none { it.status <= Download.DOWNLOADING }
|
return queue.none { it.status <= Download.State.DOWNLOADING }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -18,7 +18,7 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) {
|
|||||||
var downloadedImages: Int = 0
|
var downloadedImages: Int = 0
|
||||||
|
|
||||||
@Volatile @Transient
|
@Volatile @Transient
|
||||||
var status: Int = 0
|
var status: State = State.default
|
||||||
set(status) {
|
set(status) {
|
||||||
field = status
|
field = status
|
||||||
statusSubject?.onNext(this)
|
statusSubject?.onNext(this)
|
||||||
@ -49,12 +49,17 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) {
|
|||||||
statusCallback = f
|
statusCallback = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
CHECKED,
|
||||||
|
NOT_DOWNLOADED,
|
||||||
|
QUEUE,
|
||||||
|
DOWNLOADING,
|
||||||
|
DOWNLOADED,
|
||||||
|
ERROR
|
||||||
|
;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CHECKED = -1
|
val default = NOT_DOWNLOADED
|
||||||
const val NOT_DOWNLOADED = 0
|
}
|
||||||
const val QUEUE = 1
|
|
||||||
const val DOWNLOADING = 2
|
|
||||||
const val DOWNLOADED = 3
|
|
||||||
const val ERROR = 4
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class DownloadQueue(
|
|||||||
downloads.forEach { download ->
|
downloads.forEach { download ->
|
||||||
download.setStatusSubject(statusSubject)
|
download.setStatusSubject(statusSubject)
|
||||||
download.setStatusCallback(::setPagesFor)
|
download.setStatusCallback(::setPagesFor)
|
||||||
download.status = Download.QUEUE
|
download.status = Download.State.QUEUE
|
||||||
}
|
}
|
||||||
queue.addAll(downloads)
|
queue.addAll(downloads)
|
||||||
store.addAll(downloads)
|
store.addAll(downloads)
|
||||||
@ -36,8 +36,8 @@ class DownloadQueue(
|
|||||||
store.remove(download)
|
store.remove(download)
|
||||||
download.setStatusSubject(null)
|
download.setStatusSubject(null)
|
||||||
download.setStatusCallback(null)
|
download.setStatusCallback(null)
|
||||||
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
if (download.status == Download.State.DOWNLOADING || download.status == Download.State.QUEUE) {
|
||||||
download.status = Download.NOT_DOWNLOADED
|
download.status = Download.State.NOT_DOWNLOADED
|
||||||
}
|
}
|
||||||
downloadListeners.forEach { it.updateDownload(download) }
|
downloadListeners.forEach { it.updateDownload(download) }
|
||||||
if (removed) {
|
if (removed) {
|
||||||
@ -65,8 +65,8 @@ class DownloadQueue(
|
|||||||
queue.forEach { download ->
|
queue.forEach { download ->
|
||||||
download.setStatusSubject(null)
|
download.setStatusSubject(null)
|
||||||
download.setStatusCallback(null)
|
download.setStatusCallback(null)
|
||||||
if (download.status == Download.DOWNLOADING || download.status == Download.QUEUE) {
|
if (download.status == Download.State.DOWNLOADING || download.status == Download.State.QUEUE) {
|
||||||
download.status = Download.NOT_DOWNLOADED
|
download.status = Download.State.NOT_DOWNLOADED
|
||||||
}
|
}
|
||||||
downloadListeners.forEach { it.updateDownload(download) }
|
downloadListeners.forEach { it.updateDownload(download) }
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class DownloadQueue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setPagesFor(download: Download) {
|
private fun setPagesFor(download: Download) {
|
||||||
if (download.status == Download.DOWNLOADING) {
|
if (download.status == Download.State.DOWNLOADING) {
|
||||||
if (download.pages != null) {
|
if (download.pages != null) {
|
||||||
for (page in download.pages!!)
|
for (page in download.pages!!)
|
||||||
page.setStatusCallback {
|
page.setStatusCallback {
|
||||||
@ -84,9 +84,9 @@ class DownloadQueue(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
callListeners(download)
|
callListeners(download)
|
||||||
} else if (download.status == Download.DOWNLOADED || download.status == Download.ERROR) {
|
} else if (download.status == Download.State.DOWNLOADED || download.status == Download.State.ERROR) {
|
||||||
setPagesSubject(download.pages, null)
|
setPagesSubject(download.pages, null)
|
||||||
if (download.status == Download.ERROR) {
|
if (download.status == Download.State.ERROR) {
|
||||||
callListeners(download)
|
callListeners(download)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,19 +76,19 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
binding = DownloadButtonBinding.bind(this)
|
binding = DownloadButtonBinding.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setDownloadStatus(state: Int, progress: Int = 0, animated: Boolean = false) {
|
fun setDownloadStatus(state: Download.State, progress: Int = 0, animated: Boolean = false) {
|
||||||
if (state != Download.DOWNLOADING) {
|
if (state != Download.State.DOWNLOADING) {
|
||||||
iconAnimation?.cancel()
|
iconAnimation?.cancel()
|
||||||
binding.downloadIcon.alpha = 1f
|
binding.downloadIcon.alpha = 1f
|
||||||
isAnimating = false
|
isAnimating = false
|
||||||
}
|
}
|
||||||
binding.downloadIcon.setImageDrawable(
|
binding.downloadIcon.setImageDrawable(
|
||||||
if (state == Download.CHECKED) {
|
if (state == Download.State.CHECKED) {
|
||||||
checkDrawable
|
checkDrawable
|
||||||
} else downloadDrawable
|
} else downloadDrawable
|
||||||
)
|
)
|
||||||
when (state) {
|
when (state) {
|
||||||
Download.CHECKED -> {
|
Download.State.CHECKED -> {
|
||||||
binding.downloadProgress.isVisible = false
|
binding.downloadProgress.isVisible = false
|
||||||
binding.downloadBorder.isVisible = true
|
binding.downloadBorder.isVisible = true
|
||||||
binding.downloadProgressIndeterminate.isVisible = false
|
binding.downloadProgressIndeterminate.isVisible = false
|
||||||
@ -96,7 +96,7 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
binding.downloadBorder.drawable.setTint(activeColor)
|
binding.downloadBorder.drawable.setTint(activeColor)
|
||||||
binding.downloadIcon.drawable.setTint(Color.WHITE)
|
binding.downloadIcon.drawable.setTint(Color.WHITE)
|
||||||
}
|
}
|
||||||
Download.NOT_DOWNLOADED -> {
|
Download.State.NOT_DOWNLOADED -> {
|
||||||
binding.downloadBorder.isVisible = true
|
binding.downloadBorder.isVisible = true
|
||||||
binding.downloadProgress.isVisible = false
|
binding.downloadProgress.isVisible = false
|
||||||
binding.downloadProgressIndeterminate.isVisible = false
|
binding.downloadProgressIndeterminate.isVisible = false
|
||||||
@ -104,14 +104,14 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
binding.downloadBorder.drawable.setTint(activeColor)
|
binding.downloadBorder.drawable.setTint(activeColor)
|
||||||
binding.downloadIcon.drawable.setTint(activeColor)
|
binding.downloadIcon.drawable.setTint(activeColor)
|
||||||
}
|
}
|
||||||
Download.QUEUE -> {
|
Download.State.QUEUE -> {
|
||||||
binding.downloadBorder.isVisible = false
|
binding.downloadBorder.isVisible = false
|
||||||
binding.downloadProgress.isVisible = false
|
binding.downloadProgress.isVisible = false
|
||||||
binding.downloadProgressIndeterminate.isVisible = true
|
binding.downloadProgressIndeterminate.isVisible = true
|
||||||
binding.downloadProgress.isIndeterminate = true
|
binding.downloadProgress.isIndeterminate = true
|
||||||
binding.downloadIcon.drawable.setTint(disabledColor)
|
binding.downloadIcon.drawable.setTint(disabledColor)
|
||||||
}
|
}
|
||||||
Download.DOWNLOADING -> {
|
Download.State.DOWNLOADING -> {
|
||||||
binding.downloadBorder.isVisible = true
|
binding.downloadBorder.isVisible = true
|
||||||
binding.downloadProgress.isVisible = true
|
binding.downloadProgress.isVisible = true
|
||||||
binding.downloadProgressIndeterminate.isVisible = false
|
binding.downloadProgressIndeterminate.isVisible = false
|
||||||
@ -131,7 +131,7 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
isAnimating = true
|
isAnimating = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Download.DOWNLOADED -> {
|
Download.State.DOWNLOADED -> {
|
||||||
binding.downloadProgress.isVisible = false
|
binding.downloadProgress.isVisible = false
|
||||||
binding.downloadBorder.isVisible = true
|
binding.downloadBorder.isVisible = true
|
||||||
binding.downloadProgressIndeterminate.isVisible = false
|
binding.downloadProgressIndeterminate.isVisible = false
|
||||||
@ -159,7 +159,7 @@ class DownloadButton @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
binding.downloadIcon.drawable.setTint(downloadedTextColor)
|
binding.downloadIcon.drawable.setTint(downloadedTextColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Download.ERROR -> {
|
Download.State.ERROR -> {
|
||||||
binding.downloadProgress.isVisible = false
|
binding.downloadProgress.isVisible = false
|
||||||
binding.downloadBorder.isVisible = true
|
binding.downloadBorder.isVisible = true
|
||||||
binding.downloadProgressIndeterminate.isVisible = false
|
binding.downloadProgressIndeterminate.isVisible = false
|
||||||
|
@ -629,7 +629,7 @@ class MangaDetailsController :
|
|||||||
(binding.recycler.findViewHolderForAdapterPosition(position) as? BaseFlexibleViewHolder)
|
(binding.recycler.findViewHolderForAdapterPosition(position) as? BaseFlexibleViewHolder)
|
||||||
?.toggleActivation()
|
?.toggleActivation()
|
||||||
(binding.recycler.findViewHolderForAdapterPosition(position) as? ChapterHolder)
|
(binding.recycler.findViewHolderForAdapterPosition(position) as? ChapterHolder)
|
||||||
?.notifyStatus(Download.CHECKED, false, 0)
|
?.notifyStatus(Download.State.CHECKED, false, 0)
|
||||||
startingRangeChapterPos = position
|
startingRangeChapterPos = position
|
||||||
actionMode?.invalidate()
|
actionMode?.invalidate()
|
||||||
} else {
|
} else {
|
||||||
@ -1148,10 +1148,10 @@ class MangaDetailsController :
|
|||||||
onItemClick(null, position)
|
onItemClick(null, position)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (chapter.status != Download.NOT_DOWNLOADED && chapter.status != Download.ERROR) {
|
if (chapter.status != Download.State.NOT_DOWNLOADED && chapter.status != Download.State.ERROR) {
|
||||||
presenter.deleteChapter(chapter)
|
presenter.deleteChapter(chapter)
|
||||||
} else {
|
} else {
|
||||||
if (chapter.status == Download.ERROR) {
|
if (chapter.status == Download.State.ERROR) {
|
||||||
DownloadService.start(view.context)
|
DownloadService.start(view.context)
|
||||||
} else {
|
} else {
|
||||||
downloadChapters(listOf(chapter))
|
downloadChapters(listOf(chapter))
|
||||||
@ -1352,7 +1352,7 @@ class MangaDetailsController :
|
|||||||
if (startingRangeChapterPos != null && rangeMode == RangeMode.Download) {
|
if (startingRangeChapterPos != null && rangeMode == RangeMode.Download) {
|
||||||
val item = adapter?.getItem(startingRangeChapterPos!!) as? ChapterItem
|
val item = adapter?.getItem(startingRangeChapterPos!!) as? ChapterItem
|
||||||
(binding.recycler.findViewHolderForAdapterPosition(startingRangeChapterPos!!) as? ChapterHolder)?.notifyStatus(
|
(binding.recycler.findViewHolderForAdapterPosition(startingRangeChapterPos!!) as? ChapterHolder)?.notifyStatus(
|
||||||
item?.status ?: Download.NOT_DOWNLOADED,
|
item?.status ?: Download.State.NOT_DOWNLOADED,
|
||||||
false,
|
false,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
@ -162,10 +162,10 @@ class MangaDetailsPresenter(
|
|||||||
private fun setDownloadedChapters(chapters: List<ChapterItem>) {
|
private fun setDownloadedChapters(chapters: List<ChapterItem>) {
|
||||||
for (chapter in chapters) {
|
for (chapter in chapters) {
|
||||||
if (downloadManager.isChapterDownloaded(chapter, manga)) {
|
if (downloadManager.isChapterDownloaded(chapter, manga)) {
|
||||||
chapter.status = Download.DOWNLOADED
|
chapter.status = Download.State.DOWNLOADED
|
||||||
} else if (downloadManager.hasQueue()) {
|
} else if (downloadManager.hasQueue()) {
|
||||||
chapter.status = downloadManager.queue.find { it.chapter.id == chapter.id }
|
chapter.status = downloadManager.queue.find { it.chapter.id == chapter.id }
|
||||||
?.status ?: 0
|
?.status ?: Download.State.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ class MangaDetailsPresenter(
|
|||||||
fun hasDownloads(): Boolean = allChapters.any { it.isDownloaded }
|
fun hasDownloads(): Boolean = allChapters.any { it.isDownloaded }
|
||||||
|
|
||||||
fun getUnreadChaptersSorted() =
|
fun getUnreadChaptersSorted() =
|
||||||
allChapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name }
|
allChapters.filter { !it.read && it.status == Download.State.NOT_DOWNLOADED }.distinctBy { it.name }
|
||||||
.sortedByDescending { it.source_order }
|
.sortedByDescending { it.source_order }
|
||||||
|
|
||||||
fun startDownloadingNow(chapter: Chapter) {
|
fun startDownloadingNow(chapter: Chapter) {
|
||||||
@ -289,7 +289,7 @@ class MangaDetailsPresenter(
|
|||||||
fun deleteChapter(chapter: ChapterItem) {
|
fun deleteChapter(chapter: ChapterItem) {
|
||||||
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
||||||
this.chapters.find { it.id == chapter.id }?.apply {
|
this.chapters.find { it.id == chapter.id }?.apply {
|
||||||
status = Download.QUEUE
|
status = Download.State.QUEUE
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ class MangaDetailsPresenter(
|
|||||||
}
|
}
|
||||||
chapters.forEach { chapter ->
|
chapters.forEach { chapter ->
|
||||||
this.chapters.find { it.id == chapter.id }?.apply {
|
this.chapters.find { it.id == chapter.id }?.apply {
|
||||||
status = Download.QUEUE
|
status = Download.State.QUEUE
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ open class BaseChapterHolder(
|
|||||||
val chapter = adapter.getItem(flexibleAdapterPosition) as? BaseChapterItem<*, *> ?: return
|
val chapter = adapter.getItem(flexibleAdapterPosition) as? BaseChapterItem<*, *> ?: return
|
||||||
val downloadButton = itemView.findViewById<View>(R.id.download_button) ?: return
|
val downloadButton = itemView.findViewById<View>(R.id.download_button) ?: return
|
||||||
|
|
||||||
if (chapter.status == Download.NOT_DOWNLOADED || chapter.status == Download.ERROR) {
|
if (chapter.status == Download.State.NOT_DOWNLOADED || chapter.status == Download.State.ERROR) {
|
||||||
adapter.baseDelegate.downloadChapter(flexibleAdapterPosition)
|
adapter.baseDelegate.downloadChapter(flexibleAdapterPosition)
|
||||||
} else {
|
} else {
|
||||||
downloadButton.post {
|
downloadButton.post {
|
||||||
@ -29,10 +29,10 @@ open class BaseChapterHolder(
|
|||||||
// Inflate our menu resource into the PopupMenu's Menu
|
// Inflate our menu resource into the PopupMenu's Menu
|
||||||
popup.menuInflater.inflate(R.menu.chapter_download, popup.menu)
|
popup.menuInflater.inflate(R.menu.chapter_download, popup.menu)
|
||||||
|
|
||||||
popup.menu.findItem(R.id.action_start).isVisible = chapter.status == Download.QUEUE
|
popup.menu.findItem(R.id.action_start).isVisible = chapter.status == Download.State.QUEUE
|
||||||
|
|
||||||
// Hide download and show delete if the chapter is downloaded
|
// Hide download and show delete if the chapter is downloaded
|
||||||
if (chapter.status != Download.DOWNLOADED) popup.menu.findItem(R.id.action_delete).title = downloadButton.context.getString(
|
if (chapter.status != Download.State.DOWNLOADED) popup.menu.findItem(R.id.action_delete).title = downloadButton.context.getString(
|
||||||
R.string.cancel
|
R.string.cancel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ abstract class BaseChapterItem<T : BaseChapterHolder, H : AbstractHeaderItem<*>>
|
|||||||
AbstractSectionableItem<T, H?>(header),
|
AbstractSectionableItem<T, H?>(header),
|
||||||
Chapter by chapter {
|
Chapter by chapter {
|
||||||
|
|
||||||
private var _status: Int = 0
|
private var _status: Download.State = Download.State.default
|
||||||
|
|
||||||
val progress: Int
|
val progress: Int
|
||||||
get() {
|
get() {
|
||||||
@ -22,14 +22,14 @@ abstract class BaseChapterItem<T : BaseChapterHolder, H : AbstractHeaderItem<*>>
|
|||||||
return pages.map(Page::progress).average().toInt()
|
return pages.map(Page::progress).average().toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
var status: Int
|
var status: Download.State
|
||||||
get() = download?.status ?: _status
|
get() = download?.status ?: _status
|
||||||
set(value) { _status = value }
|
set(value) { _status = value }
|
||||||
|
|
||||||
@Transient var download: Download? = null
|
@Transient var download: Download? = null
|
||||||
|
|
||||||
val isDownloaded: Boolean
|
val isDownloaded: Boolean
|
||||||
get() = status == Download.DOWNLOADED
|
get() = status == Download.State.DOWNLOADED
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
|
@ -91,7 +91,7 @@ class ChapterHolder(
|
|||||||
binding.chapterScanlator.text = statuses.joinToString(" • ")
|
binding.chapterScanlator.text = statuses.joinToString(" • ")
|
||||||
|
|
||||||
val status = when {
|
val status = when {
|
||||||
adapter.isSelected(flexibleAdapterPosition) -> Download.CHECKED
|
adapter.isSelected(flexibleAdapterPosition) -> Download.State.CHECKED
|
||||||
else -> item.status
|
else -> item.status
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class ChapterHolder(
|
|||||||
if (binding.frontView.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) }
|
if (binding.frontView.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun notifyStatus(status: Int, locked: Boolean, progress: Int, animated: Boolean = false) = with(binding.downloadButton.downloadButton) {
|
fun notifyStatus(status: Download.State, locked: Boolean, progress: Int, animated: Boolean = false) = with(binding.downloadButton.downloadButton) {
|
||||||
if (locked) {
|
if (locked) {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
return
|
return
|
||||||
|
@ -142,7 +142,7 @@ class RecentMangaHolder(
|
|||||||
}
|
}
|
||||||
if (!item.mch.manga.isLocal()) {
|
if (!item.mch.manga.isLocal()) {
|
||||||
notifyStatus(
|
notifyStatus(
|
||||||
if (adapter.isSelected(flexibleAdapterPosition)) Download.CHECKED else item.status,
|
if (adapter.isSelected(flexibleAdapterPosition)) Download.State.CHECKED else item.status,
|
||||||
item.progress,
|
item.progress,
|
||||||
item.chapter.read
|
item.chapter.read
|
||||||
)
|
)
|
||||||
@ -160,7 +160,7 @@ class RecentMangaHolder(
|
|||||||
return item.mch.history.id != null
|
return item.mch.history.id != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun notifyStatus(status: Int, progress: Int, isRead: Boolean, animated: Boolean = false) {
|
fun notifyStatus(status: Download.State, progress: Int, isRead: Boolean, animated: Boolean = false) {
|
||||||
binding.downloadButton.downloadButton.setDownloadStatus(status, progress, animated)
|
binding.downloadButton.downloadButton.setDownloadStatus(status, progress, animated)
|
||||||
val isChapterRead =
|
val isChapterRead =
|
||||||
if (adapter.showDownloads == RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded) isRead else false
|
if (adapter.showDownloads == RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded) isRead else false
|
||||||
@ -168,7 +168,7 @@ class RecentMangaHolder(
|
|||||||
when (adapter.showDownloads) {
|
when (adapter.showDownloads) {
|
||||||
RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded,
|
RecentMangaAdapter.ShowRecentsDLs.UnreadOrDownloaded,
|
||||||
RecentMangaAdapter.ShowRecentsDLs.OnlyDownloaded ->
|
RecentMangaAdapter.ShowRecentsDLs.OnlyDownloaded ->
|
||||||
status !in Download.CHECKED..Download.NOT_DOWNLOADED || !isChapterRead
|
status !in Download.State.CHECKED..Download.State.NOT_DOWNLOADED || !isChapterRead
|
||||||
else -> binding.downloadButton.downloadButton.isVisible
|
else -> binding.downloadButton.downloadButton.isVisible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,10 +523,10 @@ class RecentsController(bundle: Bundle? = null) :
|
|||||||
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
||||||
val chapter = item.chapter
|
val chapter = item.chapter
|
||||||
val manga = item.mch.manga
|
val manga = item.mch.manga
|
||||||
if (item.status != Download.NOT_DOWNLOADED && item.status != Download.ERROR) {
|
if (item.status != Download.State.NOT_DOWNLOADED && item.status != Download.State.ERROR) {
|
||||||
presenter.deleteChapter(chapter, manga)
|
presenter.deleteChapter(chapter, manga)
|
||||||
} else {
|
} else {
|
||||||
if (item.status == Download.ERROR) DownloadService.start(view.context)
|
if (item.status == Download.State.ERROR) DownloadService.start(view.context)
|
||||||
else presenter.downloadChapter(manga, chapter)
|
else presenter.downloadChapter(manga, chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,10 +353,10 @@ class RecentsPresenter(
|
|||||||
private fun setDownloadedChapters(chapters: List<RecentMangaItem>) {
|
private fun setDownloadedChapters(chapters: List<RecentMangaItem>) {
|
||||||
for (item in chapters.filter { it.chapter.id != null }) {
|
for (item in chapters.filter { it.chapter.id != null }) {
|
||||||
if (downloadManager.isChapterDownloaded(item.chapter, item.mch.manga)) {
|
if (downloadManager.isChapterDownloaded(item.chapter, item.mch.manga)) {
|
||||||
item.status = Download.DOWNLOADED
|
item.status = Download.State.DOWNLOADED
|
||||||
} else if (downloadManager.hasQueue()) {
|
} else if (downloadManager.hasQueue()) {
|
||||||
item.status = downloadManager.queue.find { it.chapter.id == item.chapter.id }
|
item.status = downloadManager.queue.find { it.chapter.id == item.chapter.id }
|
||||||
?.status ?: 0
|
?.status ?: Download.State.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ class RecentsPresenter(
|
|||||||
if (update) {
|
if (update) {
|
||||||
val item = recentItems.find { it.chapter.id == chapter.id } ?: return
|
val item = recentItems.find { it.chapter.id == chapter.id } ?: return
|
||||||
item.apply {
|
item.apply {
|
||||||
status = Download.NOT_DOWNLOADED
|
status = Download.State.NOT_DOWNLOADED
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user