Always attempt to split tall images when downloading
This commit is contained in:
parent
843e748de3
commit
2769525b2c
@ -55,11 +55,6 @@ object SettingsDownloadScreen : SearchableSettings {
|
|||||||
pref = downloadPreferences.saveChaptersAsCBZ(),
|
pref = downloadPreferences.saveChaptersAsCBZ(),
|
||||||
title = stringResource(R.string.save_chapter_as_cbz),
|
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(
|
getDeleteChaptersGroup(
|
||||||
downloadPreferences = downloadPreferences,
|
downloadPreferences = downloadPreferences,
|
||||||
categories = allCategories,
|
categories = allCategories,
|
||||||
|
@ -410,10 +410,8 @@ class Downloader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When the page is ready, set page path, progress (just in case) and status
|
// When the page is ready, set page path, progress (just in case) and status
|
||||||
val success = splitTallImageIfNeeded(page, tmpDir)
|
splitTallImageIfNeeded(page, tmpDir)
|
||||||
if (!success) {
|
|
||||||
notifier.onError(context.getString(R.string.download_notifier_split_failed), download.chapter.name, download.manga.title)
|
|
||||||
}
|
|
||||||
page.uri = file.uri
|
page.uri = file.uri
|
||||||
page.progress = 100
|
page.progress = 100
|
||||||
page.status = Page.State.READY
|
page.status = Page.State.READY
|
||||||
@ -501,21 +499,18 @@ class Downloader(
|
|||||||
return ImageUtil.getExtensionFromMimeType(mime)
|
return ImageUtil.getExtensionFromMimeType(mime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean {
|
private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile) {
|
||||||
if (!downloadPreferences.splitTallImages().get()) return true
|
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)
|
// If the original page was previously split, then skip
|
||||||
val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) }
|
if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return
|
||||||
?: 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 true
|
|
||||||
|
|
||||||
return try {
|
|
||||||
ImageUtil.splitTallImage(tmpDir, imageFile, filenamePrefix)
|
ImageUtil.splitTallImage(tmpDir, imageFile, filenamePrefix)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logcat(LogPriority.ERROR, e)
|
logcat(LogPriority.ERROR, e) { "Failed to split downloaded image" }
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,6 @@ class DownloadPreferences(
|
|||||||
|
|
||||||
fun saveChaptersAsCBZ() = preferenceStore.getBoolean("save_chapter_as_cbz", true)
|
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 autoDownloadWhileReading() = preferenceStore.getInt("auto_download_while_reading", 0)
|
||||||
|
|
||||||
fun removeAfterReadSlots() = preferenceStore.getInt("remove_after_read_slots", -1)
|
fun removeAfterReadSlots() = preferenceStore.getInt("remove_after_read_slots", -1)
|
||||||
|
@ -444,7 +444,6 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<string name="download_ahead_info">Only works on entries in library and if the current chapter plus the next one are already downloaded</string>
|
<string name="download_ahead_info">Only works on entries in library and if the current chapter plus the next one are already downloaded</string>
|
||||||
<string name="save_chapter_as_cbz">Save as CBZ archive</string>
|
<string name="save_chapter_as_cbz">Save as CBZ archive</string>
|
||||||
<string name="split_tall_images">Split tall images</string>
|
|
||||||
<string name="split_tall_images_summary">Improves reader performance</string>
|
<string name="split_tall_images_summary">Improves reader performance</string>
|
||||||
|
|
||||||
<!-- Tracking section -->
|
<!-- Tracking section -->
|
||||||
@ -898,7 +897,6 @@
|
|||||||
<string name="download_notifier_download_paused">Downloads paused</string>
|
<string name="download_notifier_download_paused">Downloads paused</string>
|
||||||
<string name="download_notifier_split_page_not_found">Page %d not found while splitting</string>
|
<string name="download_notifier_split_page_not_found">Page %d not found while splitting</string>
|
||||||
<string name="download_notifier_split_page_path_not_found">Couldn\'t find file path of page %d</string>
|
<string name="download_notifier_split_page_path_not_found">Couldn\'t find file path of page %d</string>
|
||||||
<string name="download_notifier_split_failed">Couldn\'t split downloaded image</string>
|
|
||||||
<string name="download_notifier_cache_renewal">Checking downloads</string>
|
<string name="download_notifier_cache_renewal">Checking downloads</string>
|
||||||
|
|
||||||
<!-- Notification channels -->
|
<!-- Notification channels -->
|
||||||
|
Loading…
Reference in New Issue
Block a user