From 3664195c71a7b5f3f43f4307d85ec306152181eb Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sat, 18 Sep 2021 23:45:38 +0430 Subject: [PATCH] rewrite getFormat the kotlin way (#5930) --- .../eu/kanade/tachiyomi/source/LocalSource.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 1c4e8c3cf..b28b79213 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -272,17 +272,17 @@ class LocalSource(private val context: Context) : CatalogueSource { } private fun getFormat(file: File): Format { - val extension = file.extension - return if (file.isDirectory) { - Format.Directory(file) - } else if (extension.equals("zip", true) || extension.equals("cbz", true)) { - Format.Zip(file) - } else if (extension.equals("rar", true) || extension.equals("cbr", true)) { - Format.Rar(file) - } else if (extension.equals("epub", true)) { - Format.Epub(file) - } else { - throw Exception(context.getString(R.string.local_invalid_format)) + return file.run { + when { + isDirectory -> Format.Directory(file) + extension.equals("zip", true) -> Format.Zip(file) + extension.equals("cbz", true) -> Format.Zip(file) + extension.equals("rar", true) -> Format.Rar(file) + extension.equals("cbr", true) -> Format.Rar(file) + extension.equals("epub", true) -> Format.Epub(file) + + else -> throw Exception("Invalid chapter format") + } } }