-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
252 additions
and
231 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/androidMain/java/io/bimmergestalt/headunit/rhmi/RHMIResources.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.bimmergestalt.headunit.rhmi | ||
|
||
import android.os.Handler | ||
import android.os.Looper | ||
import android.util.Log | ||
import de.bmw.idrive.BMWRemoting | ||
import io.bimmergestalt.headunit.models.ImageModel | ||
import io.bimmergestalt.headunit.models.ImageTintable | ||
import io.bimmergestalt.headunit.utils.decodeAndCacheImage | ||
import io.bimmergestalt.idriveconnectkit.rhmi.RHMIModel | ||
import io.bimmergestalt.idriveconnectkit.rhmi.deserialization.loadFromXML | ||
import kotlinx.coroutines.android.asCoroutineDispatcher | ||
import kotlinx.coroutines.runBlocking | ||
import java.io.ByteArrayInputStream | ||
import java.util.zip.ZipInputStream | ||
|
||
fun RHMIResources.Companion.loadResources(incoming: Map<BMWRemoting.RHMIResourceType, List<ByteArray>>): RHMIResources { | ||
val app = RHMIApplicationState() | ||
app.loadFromXML(incoming[BMWRemoting.RHMIResourceType.DESCRIPTION]!!.first()) | ||
|
||
// convert any ImageIds and RaImages to a generic Model | ||
app.models.keys.forEach { id -> | ||
if (app.models[id] is RHMIModel.ImageIdModel || | ||
app.models[id] is RHMIModel.RaImageModel) { | ||
app.models[id] = ImageModel(app, id) | ||
} | ||
} | ||
|
||
val textFiles = incoming.getOrDefault(BMWRemoting.RHMIResourceType.TEXTDB, emptyList()).map { | ||
loadZipfile(it) | ||
}.fold(HashMap<String, ByteArray>()) { acc, cur -> | ||
acc.putAll(cur); acc | ||
}.mapKeys { it.key.split('.').first() | ||
}.mapValues { | ||
loadTextDb(it.value.decodeToString()) | ||
} | ||
Log.i("Resources", "Loaded textDb $textFiles") | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
val iconFiles = incoming.getOrDefault(BMWRemoting.RHMIResourceType.IMAGEDB, emptyList()).map { | ||
loadZipfile(it) | ||
}.fold(HashMap<String, ByteArray>()) { acc, cur -> | ||
acc.putAll(cur); acc | ||
}.mapKeys { it.key.split('.').first().toInt() }.mapValues { | ||
runBlocking { it.value.decodeAndCacheImage(true) } | ||
}.filterValues { | ||
it != null | ||
} as Map<Int, ImageTintable> | ||
|
||
// convert any hardcoded ImageIds to their ImageBitmaps | ||
app.modelStates.keys.forEach { | ||
val value = app.modelStates[it] | ||
if (value is BMWRemoting.RHMIResourceIdentifier && value.type == BMWRemoting.RHMIResourceType.IMAGEID) { | ||
app.modelStates[it] = iconFiles[value.id] | ||
} | ||
} | ||
|
||
return RHMIResources(app, textFiles, iconFiles) | ||
} | ||
|
||
fun loadZipfile(input: ByteArray): Map<String, ByteArray> { | ||
val output = HashMap<String, ByteArray>() | ||
// based on https://stackoverflow.com/a/66683493/169035 | ||
val zip = ZipInputStream(ByteArrayInputStream(input)) | ||
zip.use { | ||
generateSequence { it.nextEntry }.forEach { | ||
output[it.name] = zip.readBytes() | ||
} | ||
} | ||
return output | ||
} | ||
|
||
fun loadTextDb(input: String): Map<Int, String> { | ||
return input.lines() | ||
.map { it.split('=', limit = 2) } | ||
.filter { it.size == 2 && it[0].toIntOrNull() != null } | ||
.associate { it[0].toInt() to it[1] } | ||
} |
74 changes: 0 additions & 74 deletions
74
app/src/androidMain/java/io/bimmergestalt/headunit/rhmi/Resources.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/commonMain/kotlin/io/bimmergestalt/headunit/apps/calendar/CalendarAppDay.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.