Skip to content

Commit d438f5c

Browse files
Fixed: Someone has reported a crash for ZimFileReader.getFavicon.
* Improved the return of the `illustration` item; previously, we were checking first that it had the `illustration` item or not, and then getting the illustration. It calls twice at the library. Now, we are directly getting the illustration like metadata, and if not found, returning null. It will work similarly to the previous, but an extra JNI call is avoided.
1 parent 55a599a commit d438f5c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import javax.inject.Inject
5757

5858
private const val TAG = "ZimFileReader"
5959

60-
@Suppress("LongParameterList")
6160
class ZimFileReader constructor(
6261
val zimReaderSource: ZimReaderSource,
6362
val jniKiwixReader: Archive,
@@ -150,15 +149,14 @@ class ZimFileReader constructor(
150149
val date: String get() = getSafeMetaData("Date", "")
151150
val description: String get() = getSafeMetaData("Description", "")
152151
val favicon: String?
153-
get() =
154-
if (jniKiwixReader.hasIllustration(ILLUSTRATION_SIZE)) {
155-
Base64.encodeToString(
156-
jniKiwixReader.getIllustrationItem(ILLUSTRATION_SIZE).data.data,
157-
Base64.DEFAULT
158-
)
159-
} else {
160-
null
161-
}
152+
get() = runCatching {
153+
Base64.encodeToString(
154+
jniKiwixReader.getIllustrationItem(ILLUSTRATION_SIZE).data.data,
155+
Base64.DEFAULT
156+
)
157+
}.onFailure {
158+
Log.e(TAG, "Could not get the favicon for $title. Original exception: $it")
159+
}.getOrNull()
162160
val language: String get() = getSafeMetaData("Language", "")
163161

164162
val tags: String

0 commit comments

Comments
 (0)