From 2769525b2c12547b8dc29b1209ea3bc5d22f1e3f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Mar 2023 12:57:16 -0400 Subject: [PATCH] Always attempt to split tall images when downloading --- .../settings/screen/SettingsDownloadScreen.kt | 5 ---- .../tachiyomi/data/download/Downloader.kt | 25 ++++++++----------- .../download/service/DownloadPreferences.kt | 2 -- i18n/src/main/res/values/strings.xml | 2 -- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt index fa6b0af2b..36bf6fe8e 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt @@ -55,11 +55,6 @@ object SettingsDownloadScreen : SearchableSettings { pref = downloadPreferences.saveChaptersAsCBZ(), title = stringResource(R.string.save_chapter_as_cbz), ), - Preference.PreferenceItem.SwitchPreference( - pref = downloadPreferences.splitTallImages(), - title = stringResource(R.string.split_tall_images), - subtitle = stringResource(R.string.split_tall_images_summary), - ), getDeleteChaptersGroup( downloadPreferences = downloadPreferences, categories = allCategories, 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 9f4682ad6..81965ba6c 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 @@ -410,10 +410,8 @@ class Downloader( } // When the page is ready, set page path, progress (just in case) and status - val success = splitTallImageIfNeeded(page, tmpDir) - if (!success) { - notifier.onError(context.getString(R.string.download_notifier_split_failed), download.chapter.name, download.manga.title) - } + splitTallImageIfNeeded(page, tmpDir) + page.uri = file.uri page.progress = 100 page.status = Page.State.READY @@ -501,21 +499,18 @@ class Downloader( return ImageUtil.getExtensionFromMimeType(mime) } - private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean { - if (!downloadPreferences.splitTallImages().get()) return true + private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile) { + try { + val filenamePrefix = String.format("%03d", page.number) + val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) } + ?: error(context.getString(R.string.download_notifier_split_page_not_found, page.number)) - val filenamePrefix = String.format("%03d", page.number) - val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) } - ?: throw Error(context.getString(R.string.download_notifier_split_page_not_found, page.number)) + // If the original page was previously split, then skip + if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return - // If the original page was previously split, then skip - if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return true - - return try { ImageUtil.splitTallImage(tmpDir, imageFile, filenamePrefix) } catch (e: Exception) { - logcat(LogPriority.ERROR, e) - false + logcat(LogPriority.ERROR, e) { "Failed to split downloaded image" } } } diff --git a/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt b/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt index cc930cf51..060963028 100644 --- a/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt +++ b/domain/src/main/java/tachiyomi/domain/download/service/DownloadPreferences.kt @@ -14,8 +14,6 @@ class DownloadPreferences( fun saveChaptersAsCBZ() = preferenceStore.getBoolean("save_chapter_as_cbz", true) - fun splitTallImages() = preferenceStore.getBoolean("split_tall_images", false) - fun autoDownloadWhileReading() = preferenceStore.getInt("auto_download_while_reading", 0) fun removeAfterReadSlots() = preferenceStore.getInt("remove_after_read_slots", -1) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 9cdd8ad11..88ac37d83 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -444,7 +444,6 @@ Only works on entries in library and if the current chapter plus the next one are already downloaded Save as CBZ archive - Split tall images Improves reader performance @@ -898,7 +897,6 @@ Downloads paused Page %d not found while splitting Couldn\'t find file path of page %d - Couldn\'t split downloaded image Checking downloads