From 13a2d3dfddbd58d6242eccac169085e96d5fabcd 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) --- .../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 bed8c5e369..e6c7e7ba9b 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 25dc94e128..3da98fc0c2 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 f6cfe38abb..1db775856e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -394,6 +394,7 @@ All Unread Are you sure you want to delete selected chapters? + Invalid download directory Tracking