Wear CWF Remove variable and SonarLint bug

This commit is contained in:
Philoul 2023-09-03 19:34:02 +02:00
parent 170b2ecec0
commit fd74a1e121

View file

@ -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)
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 -> {