From 53a44fb2115c137cd7905acd91ef99f28ade1afd Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 8 Jan 2020 19:30:50 -0800 Subject: [PATCH] Added delete pending Downloads method Also sources now show langauge for multi langauge users --- .../tachiyomi/data/download/DownloadManager.kt | 14 ++++++++++++++ .../tachiyomi/data/download/DownloadProvider.kt | 11 ----------- .../tachiyomi/ui/download/DownloadPresenter.kt | 3 +-- .../manga/design/MigrationSourceHolder.kt | 9 +++++++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index ec8fc455d0..a7366d0dec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -90,6 +90,7 @@ class DownloadManager(val context: Context) { * @param isNotification value that determines if status is set (needed for view updates) */ fun clearQueue(isNotification: Boolean = false) { + deletePendingDownloads(*downloader.queue.toTypedArray()) downloader.clearQueue(isNotification) } @@ -181,6 +182,19 @@ class DownloadManager(val context: Context) { return cache.getDownloadCount(manga) } + /** + * Calls delete chapter, which deletes temp downloads + * @param downloads list of downloads to cancel + */ + fun deletePendingDownloads(vararg downloads: Download) { + val downloadsByManga = downloads.groupBy { it.manga.id } + downloadsByManga.map { entry -> + val manga = entry.value.first().manga + val source = entry.value.first().source + deleteChapters(entry.value.map { it.chapter }, manga, source) + } + } + /** * Deletes the directories of a list of partially downloaded chapters. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index 6581e6c711..23156486bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -132,16 +132,6 @@ class DownloadProvider(private val context: Context) { * @param chapter the chapter to query. */ fun getChapterDirName(chapter: Chapter): String { - return DiskUtil.buildValidFilename("${chapter.id} - ${chapter.name}") - } - - /** - * Returns the chapter directory name for a chapter (that used the scanlator - * - * @param chapter the chapter to query. - */ - //TODO: Delete this in due time. N2Self, merging that pr was a mistake - private fun getChapterDirNameWithScanlator(chapter: Chapter): String { return DiskUtil.buildValidFilename("${chapter.id}_${chapter.scanlator}_${chapter.name}") } @@ -154,7 +144,6 @@ class DownloadProvider(private val context: Context) { return listOf( getChapterDirName(chapter), // Legacy chapter directory name used in v0.8.4 and before - getChapterDirNameWithScanlator(chapter), DiskUtil.buildValidFilename(chapter.name) ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt index 3daccb8e02..e892553d8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt @@ -66,8 +66,7 @@ class DownloadPresenter : BasePresenter() { } fun cancelDownload(download: Download) { - downloadManager.deleteChapters(listOf(download.chapter), download.manga, - download.source) + downloadManager.deletePendingDownloads(download) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt index e26bd29623..0575b87a65 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt @@ -3,10 +3,13 @@ package eu.kanade.tachiyomi.ui.migration.manga.design import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG import android.view.View import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.getRound import kotlinx.android.synthetic.main.migration_source_item.* +import uy.kohesive.injekt.injectLazy class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter): BaseFlexibleViewHolder(view, adapter) { @@ -15,9 +18,11 @@ class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter): } fun bind(source: HttpSource, sourceEnabled: Boolean) { + val preferences by injectLazy() + val isMultiLanguage = preferences.enabledLanguages().getOrDefault().size > 1 // Set capitalized title. - title.text = source.name.capitalize() - + val sourceName = if (isMultiLanguage) source.toString() else source.name.capitalize() + title.text = sourceName // Update circle letter image. itemView.post { image.setImageDrawable(image.getRound(source.name.take(1).toUpperCase(),false))