refactor: Allow nullable [skip ci]

This commit is contained in:
Ahmad Ansori Palembani 2024-07-10 12:02:03 +07:00
parent 73b395000f
commit 1d7fab08cf
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 4 additions and 2 deletions

View file

@ -181,7 +181,7 @@ class DownloadManager(val context: Context) {
fun buildPageList(source: Source, manga: Manga, chapter: Chapter): List<Page> {
val chapterDir = provider.findChapterDir(chapter, manga, source)
val files = chapterDir?.listFiles().orEmpty()
.filter { it.isFile && ImageUtil.isImage(it.name.orEmpty()) { it.openInputStream() } }
.filter { it.isFile && ImageUtil.isImage(it.name) { it.openInputStream() } }
if (files.isEmpty()) {
throw Exception(context.getString(MR.strings.no_pages_found))

View file

@ -44,7 +44,9 @@ import kotlin.math.roundToInt
object ImageUtil {
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
fun isImage(name: String?, openStream: (() -> InputStream)? = null): Boolean {
if (name == null) return false
val extension = name.substringAfterLast('.')
return ImageType.entries.any { it.extension == extension } || openStream?.let { findImageType(it) } != null
}