From c40e4f6c5a91f035bdcba2de15f1316eb6c59a87 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 9 Jan 2020 08:39:40 -0500 Subject: [PATCH] Provide more human readable error when downloading to invalid directory (#2462) (cherry picked from commit 13a2d3dfddbd58d6242eccac169085e96d5fabcd) --- .../tachiyomi/data/download/DownloadProvider.kt | 11 ++++++++--- .../eu/kanade/tachiyomi/data/download/Downloader.kt | 2 +- app/src/main/res/values/strings.xml | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) 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 bed8c5e36..e6c7e7ba9 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 @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import android.net.Uri import com.hippo.unifile.UniFile +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -46,9 +47,13 @@ class DownloadProvider(private val context: Context) { * @param source the source of the manga. */ internal fun getMangaDir(manga: Manga, source: Source): UniFile { - return downloadsDir - .createDirectory(getSourceDirName(source)) - .createDirectory(getMangaDirName(manga)) + try { + return downloadsDir + .createDirectory(getSourceDirName(source)) + .createDirectory(getMangaDirName(manga)) + } catch (e: NullPointerException) { + throw Exception(context.getString(R.string.invalid_download_dir)) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 0dc8e1e6c..1388101c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -102,7 +102,7 @@ class Downloader( pending.forEach { if (it.status != Download.QUEUE) it.status = Download.QUEUE } downloadsRelay.call(pending) - return !pending.isEmpty() + return pending.isNotEmpty() } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1502040f3..9373e4aff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -393,6 +393,7 @@ Download all Download unread Are you sure you want to delete selected chapters? + Invalid download directory Tracking