Reimplement chapter download indicator longpress (#7412)

This commit is contained in:
AntsyLich
2022-07-02 22:43:18 +06:00
committed by GitHub
parent f3c50ee9a3
commit deaded5af2
8 changed files with 169 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.runBlocking
import logcat.LogPriority
import rx.Observable
import uy.kohesive.injekt.Injekt
@@ -104,10 +105,12 @@ class DownloadManager(
fun startDownloadNow(chapterId: Long?) {
if (chapterId == null) return
val download = downloader.queue.find { it.chapter.id == chapterId } ?: return
val download = downloader.queue.find { it.chapter.id == chapterId }
// If not in queue try to start a new download
val toAdd = download ?: runBlocking { Download.fromChapterId(chapterId) } ?: return
val queue = downloader.queue.toMutableList()
queue.remove(download)
queue.add(0, download)
download?.let { queue.remove(it) }
queue.add(0, toAdd)
reorderQueue(queue)
if (isPaused()) {
if (DownloadService.isRunning(context)) {

View File

@@ -1,10 +1,17 @@
package eu.kanade.tachiyomi.data.download.model
import eu.kanade.domain.chapter.interactor.GetChapter
import eu.kanade.domain.chapter.model.toDbChapter
import eu.kanade.domain.manga.interactor.GetMangaById
import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import rx.subjects.PublishSubject
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
data class Download(
val source: HttpSource,
@@ -57,4 +64,19 @@ data class Download(
DOWNLOADED(3),
ERROR(4),
}
companion object {
suspend fun fromChapterId(
chapterId: Long,
getChapter: GetChapter = Injekt.get(),
getMangaById: GetMangaById = Injekt.get(),
sourceManager: SourceManager = Injekt.get(),
): Download? {
val chapter = getChapter.await(chapterId) ?: return null
val manga = getMangaById.await(chapter.mangaId) ?: return null
val source = sourceManager.get(manga.source) as? HttpSource ?: return null
return Download(source, manga.toDbManga(), chapter.toDbChapter())
}
}
}