From 4ef7b16925ae6555d54cc18160b255134a9b4ce1 Mon Sep 17 00:00:00 2001 From: len Date: Thu, 24 Nov 2016 21:50:02 +0100 Subject: [PATCH] Minor refactor --- .../tachiyomi/data/download/DownloadProvider.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 11 +++++------ .../main/java/eu/kanade/tachiyomi/util/DiskUtil.kt | 2 +- 3 files changed, 8 insertions(+), 9 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 78230041dd..77c2de04d1 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 @@ -83,7 +83,7 @@ class DownloadProvider(private val context: Context) { * @param manga the manga to query. */ fun getMangaDirName(manga: Manga): String { - return DiskUtil.buildValidFatFilename(manga.title) + return DiskUtil.buildValidFilename(manga.title) } /** @@ -92,7 +92,7 @@ class DownloadProvider(private val context: Context) { * @param chapter the chapter to query. */ fun getChapterDirName(chapter: Chapter): String { - return DiskUtil.buildValidFatFilename(chapter.name) + return DiskUtil.buildValidFilename(chapter.name) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index f99b7ada90..cdb030f1b5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -570,17 +570,16 @@ class ReaderPresenter : BasePresenter() { val destDir = File(pictureDirectory) destDir.mkdirs() - // Find out file extension. + // Find out file mime type. val mime = context.contentResolver.getType(page.uri) ?: context.contentResolver.openInputStream(page.uri).buffered().use { URLConnection.guessContentTypeFromStream(it) } + + // Build destination file. val ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) ?: "jpg" - - // Destination file. - - val filename = "${manga.title} - ${chapter.name} - ${page.index + 1}.$ext" - val destFile = File(destDir, DiskUtil.buildValidFatFilename(filename)) + val filename = "${manga.title} - ${chapter.name} - ${page.index + 1}" + val destFile = File(destDir, DiskUtil.buildValidFilename(filename) + ".$ext") context.contentResolver.openInputStream(page.uri).use { input -> destFile.outputStream().use { output -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt index 13c8126e5e..b3e3acda25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/DiskUtil.kt @@ -36,7 +36,7 @@ object DiskUtil { * replacing any invalid characters with "_". This method doesn't allow private files (starting * with a dot), but you can manually add it later. */ - fun buildValidFatFilename(origName: String): String { + fun buildValidFilename(origName: String): String { val name = origName.trim('.', ' ') if (name.isNullOrEmpty()) { return "(invalid)"