Skip to content

Commit

Permalink
fix crash when no thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog committed Sep 14, 2024
1 parent 58c6cf5 commit aa903b8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/src/main/java/com/aliernfrog/pftool/impl/MapFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,17 @@ class MapFile(
is DocumentFileCompat -> if (file.isDirectory()) file.findFile(thumbnailFileName)?.uri?.toString() else null
is ServiceFile -> if (!file.isFile) {
if (cachedThumbnailModel != null) return cachedThumbnailModel
val fd = shizukuViewModel.fileService!!.getFd("$path/$thumbnailFileName")
val input = ParcelFileDescriptor.AutoCloseInputStream(fd)
val output = ByteArrayOutputStream()
input.copyTo(output)
cachedThumbnailModel = output.toByteArray()
output.close()
input.close()
fd.close()
val thumbnailPath = "$path/$thumbnailFileName"
if (shizukuViewModel.fileService!!.exists(thumbnailPath)) {
val fd = shizukuViewModel.fileService!!.getFd("$path/$thumbnailFileName")
val input = ParcelFileDescriptor.AutoCloseInputStream(fd)
val output = ByteArrayOutputStream()
input.copyTo(output)
cachedThumbnailModel = output.toByteArray()
output.close()
input.close()
fd.close()
}
return cachedThumbnailModel
} else null
else -> null
Expand Down Expand Up @@ -351,9 +354,9 @@ class MapFile(
*/
fun getThumbnailFile(): Any? {
return when (file) {
is File -> File("${file.absolutePath}/$thumbnailFileName")
is File -> File("$path/$thumbnailFileName")
is DocumentFileCompat -> file.findFile(thumbnailFileName)
is ServiceFile -> shizukuViewModel.fileService!!.getFile("${file.path}/$thumbnailFileName")
is ServiceFile -> shizukuViewModel.fileService!!.getFile("$path/$thumbnailFileName")
else -> throw IllegalArgumentException("MapFile/getThumbnailFile: unexpected class")
}
}
Expand Down

0 comments on commit aa903b8

Please sign in to comment.