File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
src/commonMain/kotlin/io/rebble/libpebblecommon Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,32 @@ enum class WatchType(val codename: String) {
55 BASALT (" basalt" ),
66 CHALK (" chalk" ),
77 DIORITE (" diorite" ),
8- EMERY (" emery" )
8+ EMERY (" emery" );
9+
10+ fun getCompatibleAppVariants (): List <WatchType > {
11+ return when (this ) {
12+ APLITE -> listOf (APLITE )
13+ BASALT -> listOf (BASALT , APLITE )
14+ CHALK -> listOf (CHALK )
15+ DIORITE -> listOf (DIORITE , APLITE )
16+ EMERY -> listOf (
17+ EMERY ,
18+ BASALT ,
19+ DIORITE ,
20+ APLITE
21+ )
22+ }
23+ }
24+
25+ /* *
26+ * Get the most compatible variant for this WatchType
27+ * @param availableAppVariants List of variants, from [io.rebble.libpebblecommon.metadata.pbw.appinfo.PbwAppInfo.targetPlatforms]
28+ */
29+ fun getBestVariant (availableAppVariants : List <String >): WatchType ? {
30+ val compatibleVariants = getCompatibleAppVariants()
31+
32+ return compatibleVariants.firstOrNull() { variant ->
33+ availableAppVariants.contains(variant.codename)
34+ }
35+ }
936}
Original file line number Diff line number Diff line change 1+ package io.rebble.libpebblecommon.util
2+
3+ import io.rebble.libpebblecommon.metadata.pbw.appinfo.PbwAppInfo
4+ import io.rebble.libpebblecommon.metadata.pbw.manifest.PbwManifest
5+ import kotlinx.serialization.decodeFromString
6+ import kotlinx.serialization.encodeToString
7+ import kotlinx.serialization.json.Json
8+
9+ object SerializationUtil {
10+ private val json = Json { ignoreUnknownKeys = true }
11+ fun serializeAppInfo (appInfo : PbwAppInfo ): String = json.encodeToString(appInfo)
12+ fun deserializeAppInfo (jsonString : String ): PbwAppInfo = json.decodeFromString(jsonString)
13+
14+ fun serializeManifest (manifest : PbwManifest ): String = json.encodeToString(manifest)
15+ fun deserializeManifest (jsonString : String ): PbwManifest = json.decodeFromString(jsonString)
16+ }
You can’t perform that action at this time.
0 commit comments