From 492a24ec17362d309b15b96905ea17d1d9b91d44 Mon Sep 17 00:00:00 2001 From: len Date: Fri, 15 Apr 2016 15:14:02 +0200 Subject: [PATCH] Use always 3 characters for downloaded pages. Fixes #181 --- .../tachiyomi/data/download/DownloadManager.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 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 8df5923ea..769b0b9d7 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 @@ -260,16 +260,15 @@ class DownloadManager(private val context: Context, private val sourceManager: S // Get the filename for an image given the page private fun getImageFilename(page: Page): String { val url = page.imageUrl - val number = page.pageNumber + 1 + val number = String.format("%03d", page.pageNumber + 1) + // Try to preserve file extension - if (UrlUtil.isJpg(url)) { - return "$number.jpg" - } else if (UrlUtil.isPng(url)) { - return "$number.png" - } else if (UrlUtil.isGif(url)) { - return "$number.gif" + return when { + UrlUtil.isJpg(url) -> "$number.jpg" + UrlUtil.isPng(url) -> "$number.png" + UrlUtil.isGif(url) -> "$number.gif" + else -> Uri.parse(url).lastPathSegment.replace(imageFilenameRegex, "_") } - return Uri.parse(url).lastPathSegment.replace(imageFilenameRegex, "_") } private fun isImageDownloaded(imagePath: File): Boolean {