File tree Expand file tree Collapse file tree 6 files changed +30
-12
lines changed
base/src/main/java/io/github/sds100/keymapper/base
data/src/main/java/io/github/sds100/keymapper/data Expand file tree Collapse file tree 6 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -780,6 +780,7 @@ class BackupManagerImpl @Inject constructor(
780780 private fun getSoundUidsToBackup (keyMapList : List <KeyMapEntity >): Set <String > {
781781 val soundActions = keyMapList
782782 .flatMap { it.actionList }
783+ .filterNotNull()
783784 .filter { it.type == ActionEntity .Type .SOUND }
784785
785786 return soundActions
Original file line number Diff line number Diff line change @@ -112,7 +112,9 @@ object KeyMapEntityMapper {
112112 entity : KeyMapEntity ,
113113 floatingButtons : List <FloatingButtonEntityWithLayout >,
114114 ): KeyMap {
115- val actionList = entity.actionList.mapNotNull { ActionEntityMapper .fromEntity(it) }
115+ val actionList = entity.actionList
116+ .filterNotNull()
117+ .mapNotNull { ActionEntityMapper .fromEntity(it) }
116118
117119 val constraintList =
118120 entity.constraintList.map { ConstraintEntityMapper .fromEntity(it) }.toSet()
Original file line number Diff line number Diff line change @@ -5,16 +5,15 @@ import com.github.salomonbrys.kotson.fromJson
55import com.github.salomonbrys.kotson.registerTypeAdapter
66import com.google.gson.GsonBuilder
77import io.github.sds100.keymapper.data.entities.ActionEntity
8- import io.github.sds100.keymapper.data.entities.ConstraintEntity
98
109class ActionListTypeConverter {
11- private val gson = GsonBuilder ().registerTypeAdapter(ConstraintEntity .DESERIALIZER ).create()
10+ private val gson = GsonBuilder ().registerTypeAdapter(ActionEntity .DESERIALIZER ).create()
1211
1312 @TypeConverter
14- fun toActionList (json : String ): List <ActionEntity > {
15- return gson.fromJson<MutableList <ActionEntity >>(json)
13+ fun toActionList (json : String ): List <ActionEntity ? > {
14+ return gson.fromJson<MutableList <ActionEntity ? >>(json)
1615 }
1716
1817 @TypeConverter
19- fun toJsonString (actionList : List <ActionEntity >): String = gson.toJson(actionList)!!
18+ fun toJsonString (actionList : List <ActionEntity ? >): String = gson.toJson(actionList)!!
2019}
Original file line number Diff line number Diff line change @@ -142,8 +142,18 @@ data class ActionEntity(
142142 const val EXTRA_REPEAT_LIMIT = " extra_repeat_limit"
143143
144144 val DESERIALIZER = jsonDeserializer {
145- val typeString by it.json.byString(NAME_ACTION_TYPE )
146- val type = Type .valueOf(typeString)
145+ val typeString by it.json.byNullableString(NAME_ACTION_TYPE )
146+ // If it is an unknown type then do not deserialize
147+ if (typeString == null ) {
148+ return @jsonDeserializer null
149+ }
150+
151+ val type: Type = try {
152+ Type .valueOf(typeString!! )
153+ } catch (e: IllegalArgumentException ) {
154+ // If it is an unknown type then do not deserialize
155+ return @jsonDeserializer null
156+ }
147157
148158 val data by it.json.byString(NAME_DATA )
149159
Original file line number Diff line number Diff line change @@ -17,9 +17,12 @@ data class FingerprintMapEntity(
1717 @PrimaryKey
1818 val id : Int = ID_UNKNOWN ,
1919
20+ /* *
21+ * The action can be null if it wasn't deserialized successfully.
22+ */
2023 @SerializedName(NAME_ACTION_LIST )
2124 @ColumnInfo(name = FingerprintMapDao .KEY_ACTION_LIST )
22- val actionList : List <ActionEntity > = listOf(),
25+ val actionList : List <ActionEntity ? > = listOf(),
2326
2427 @SerializedName(NAME_CONSTRAINTS )
2528 @ColumnInfo(name = FingerprintMapDao .KEY_CONSTRAINT_LIST )
@@ -63,7 +66,7 @@ data class FingerprintMapEntity(
6366 val id by it.json.byNullableInt(NAME_ID )
6467
6568 val actionListJson by it.json.byArray(NAME_ACTION_LIST )
66- val actionList = it.context.deserialize<List <ActionEntity >>(actionListJson)
69+ val actionList = it.context.deserialize<List <ActionEntity ? >>(actionListJson)
6770
6871 val extrasJson by it.json.byArray(NAME_EXTRAS )
6972 val extras = it.context.deserialize<List <EntityExtra >>(extrasJson)
Original file line number Diff line number Diff line change @@ -41,9 +41,12 @@ data class KeyMapEntity(
4141 @ColumnInfo(name = KeyMapDao .KEY_TRIGGER )
4242 val trigger : TriggerEntity = TriggerEntity (),
4343
44+ /* *
45+ * The action can be null if it wasn't deserialized successfully.
46+ */
4447 @SerializedName(NAME_ACTION_LIST )
4548 @ColumnInfo(name = KeyMapDao .KEY_ACTION_LIST )
46- val actionList : List <ActionEntity > = listOf(),
49+ val actionList : List <ActionEntity ? > = listOf(),
4750
4851 @SerializedName(NAME_CONSTRAINT_LIST )
4952 @ColumnInfo(name = KeyMapDao .KEY_CONSTRAINT_LIST )
@@ -87,7 +90,7 @@ data class KeyMapEntity(
8790
8891 val DESERIALIZER = jsonDeserializer {
8992 val actionListJsonArray by it.json.byArray(NAME_ACTION_LIST )
90- val actionList = it.context.deserialize<List <ActionEntity >>(actionListJsonArray)
93+ val actionList = it.context.deserialize<List <ActionEntity ? >>(actionListJsonArray)
9194
9295 val triggerJsonObject by it.json.byObject(NAME_TRIGGER )
9396 val trigger = it.context.deserialize<TriggerEntity >(triggerJsonObject)
You can’t perform that action at this time.
0 commit comments