From fd74a1e121cf421700cda5b959e0d36c568fbc36 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 3 Sep 2023 19:34:02 +0200 Subject: [PATCH] Wear CWF Remove variable and SonarLint bug --- .../rx/weardata/CustomWatchfaceFormat.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt index a6151eb964..8b897cbcb0 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt @@ -72,7 +72,7 @@ enum class ResFormat(val extension: String) { companion object { fun fromFileName(fileName: String): ResFormat = - values().firstOrNull { it.extension == fileName.substringAfterLast(".") } ?: UNKNOWN + values().firstOrNull { it.extension == fileName.substringAfterLast(".").lowercase() } ?: UNKNOWN } } @@ -108,14 +108,19 @@ data class ResData(val value: ByteArray, val format: ResFormat) { return when (format) { ResFormat.TTF -> { // Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available - val tempFile = File.createTempFile("temp", ".ttf") - val fileOutputStream = FileOutputStream(tempFile) - fileOutputStream.write(value) - fileOutputStream.close() + File.createTempFile("temp", ".ttf").let { tempFile -> + FileOutputStream(tempFile).let { fileOutputStream -> + fileOutputStream.write(value) + fileOutputStream.close() + } - val typeface = Typeface.createFromFile(tempFile) - tempFile.delete() // delete tempfile after usage - typeface + Typeface.createFromFile(tempFile).let { + if (!tempFile.delete()) { + // delete tempfile after usage + } + it + } + } } else -> {