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 { companion object {
fun fromFileName(fileName: String): ResFormat = 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) { return when (format) {
ResFormat.TTF -> { ResFormat.TTF -> {
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available // Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
val tempFile = File.createTempFile("temp", ".ttf") File.createTempFile("temp", ".ttf").let { tempFile ->
val fileOutputStream = FileOutputStream(tempFile) FileOutputStream(tempFile).let { fileOutputStream ->
fileOutputStream.write(value) fileOutputStream.write(value)
fileOutputStream.close() fileOutputStream.close()
}
val typeface = Typeface.createFromFile(tempFile) Typeface.createFromFile(tempFile).let {
tempFile.delete() // delete tempfile after usage if (!tempFile.delete()) {
typeface // delete tempfile after usage
}
it
}
}
} }
else -> { else -> {