-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#479 make Hold Down and Repeat action options mutually exclusive and …
…migrate user data for this change
- Loading branch information
Showing
5 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
app/schemas/io.github.sds100.keymapper.data.db.AppDatabase/8.json
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,102 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 8, | ||
"identityHash": "ba6a25ab74ecd5a7b5b70684ce72d100", | ||
"entities": [ | ||
{ | ||
"tableName": "keymaps", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `trigger` TEXT NOT NULL, `action_list` TEXT NOT NULL, `constraint_list` TEXT NOT NULL, `constraint_mode` INTEGER NOT NULL, `flags` INTEGER NOT NULL, `folder_name` TEXT, `is_enabled` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "trigger", | ||
"columnName": "trigger", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "actionList", | ||
"columnName": "action_list", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "constraintList", | ||
"columnName": "constraint_list", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "constraintMode", | ||
"columnName": "constraint_mode", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "flags", | ||
"columnName": "flags", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "folderName", | ||
"columnName": "folder_name", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "isEnabled", | ||
"columnName": "is_enabled", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"id" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "deviceinfo", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`descriptor` TEXT NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY(`descriptor`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "descriptor", | ||
"columnName": "descriptor", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"descriptor" | ||
], | ||
"autoGenerate": false | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ba6a25ab74ecd5a7b5b70684ce72d100')" | ||
] | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/io/github/sds100/keymapper/data/db/migration/Migration_7_8.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,62 @@ | ||
@file:Suppress("ClassName") | ||
|
||
package io.github.sds100.keymapper.data.db.migration | ||
|
||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
import androidx.sqlite.db.SupportSQLiteQueryBuilder | ||
import com.github.salomonbrys.kotson.fromJson | ||
import com.github.salomonbrys.kotson.registerTypeAdapter | ||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import io.github.sds100.keymapper.data.model.Action | ||
import splitties.bitflags.hasFlag | ||
import splitties.bitflags.minusFlag | ||
|
||
/** | ||
* Created by sds100 on 25/06/20. | ||
*/ | ||
|
||
/** | ||
* If an action has both the Repeat and Hold Down flags then remove the Hold Down flag and assume that the user wants | ||
* the Repeat flag. | ||
*/ | ||
object Migration_7_8 { | ||
|
||
private const val ACTION_FLAG_REPEAT = 4 | ||
private const val ACTION_FLAG_HOLD_DOWN = 8 | ||
|
||
fun migrate(database: SupportSQLiteDatabase) = database.apply { | ||
val query = SupportSQLiteQueryBuilder | ||
.builder("keymaps") | ||
.columns(arrayOf("id", "action_list")) | ||
.create() | ||
|
||
query(query).apply { | ||
val gson = GsonBuilder().registerTypeAdapter(Action.DESERIALIZER).create() | ||
|
||
while (moveToNext()) { | ||
val idColumnIndex = getColumnIndex("id") | ||
val id = getInt(idColumnIndex) | ||
|
||
val actionListColumnIndex = getColumnIndex("action_list") | ||
|
||
val actionList = gson.fromJson<List<Action>>(getString(actionListColumnIndex)) | ||
|
||
val newActionList = actionList.map { | ||
if (it.flags.hasFlag(ACTION_FLAG_REPEAT) && it.flags.hasFlag(ACTION_FLAG_HOLD_DOWN)) { | ||
return@map it.clone(flags = it.flags.minusFlag(ACTION_FLAG_HOLD_DOWN)) | ||
} | ||
|
||
it | ||
} | ||
|
||
execSQL("UPDATE keymaps SET action_list='${newActionList.json}' WHERE id=$id") | ||
} | ||
|
||
close() | ||
} | ||
} | ||
|
||
val Any.json: String | ||
get() = Gson().toJson(this) | ||
} |
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