-
-
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.
#1274 move TriggerKeyEntity to its own file
- Loading branch information
Showing
9 changed files
with
101 additions
and
89 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
app/src/main/java/io/github/sds100/keymapper/data/entities/TriggerKeyEntity.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,69 @@ | ||
package io.github.sds100.keymapper.data.entities | ||
|
||
import android.os.Parcelable | ||
import com.github.salomonbrys.kotson.byInt | ||
import com.github.salomonbrys.kotson.byNullableInt | ||
import com.github.salomonbrys.kotson.byNullableString | ||
import com.github.salomonbrys.kotson.byString | ||
import com.github.salomonbrys.kotson.jsonDeserializer | ||
import com.google.gson.annotations.SerializedName | ||
import kotlinx.android.parcel.Parcelize | ||
import java.util.UUID | ||
|
||
@Parcelize | ||
data class TriggerKeyEntity( | ||
@SerializedName(NAME_KEYCODE) | ||
val keyCode: Int, | ||
@SerializedName(NAME_DEVICE_ID) | ||
val deviceId: String = DEVICE_ID_THIS_DEVICE, | ||
|
||
@SerializedName(NAME_DEVICE_NAME) | ||
val deviceName: String? = null, | ||
|
||
@TriggerEntity.ClickType | ||
@SerializedName(NAME_CLICK_TYPE) | ||
val clickType: Int = TriggerEntity.SHORT_PRESS, | ||
|
||
@SerializedName(NAME_FLAGS) | ||
val flags: Int = 0, | ||
|
||
@SerializedName(NAME_UID) | ||
val uid: String = UUID.randomUUID().toString(), | ||
) : Parcelable { | ||
|
||
companion object { | ||
// DON'T CHANGE THESE. Used for JSON serialization and parsing. | ||
const val NAME_KEYCODE = "keyCode" | ||
const val NAME_DEVICE_ID = "deviceId" | ||
const val NAME_DEVICE_NAME = "deviceName" | ||
const val NAME_CLICK_TYPE = "clickType" | ||
const val NAME_FLAGS = "flags" | ||
const val NAME_UID = "uid" | ||
|
||
// IDS! DON'T CHANGE | ||
const val DEVICE_ID_THIS_DEVICE = "io.github.sds100.keymapper.THIS_DEVICE" | ||
const val DEVICE_ID_ANY_DEVICE = "io.github.sds100.keymapper.ANY_DEVICE" | ||
|
||
const val FLAG_DO_NOT_CONSUME_KEY_EVENT = 1 | ||
|
||
val DESERIALIZER = jsonDeserializer { | ||
val keycode by it.json.byInt(NAME_KEYCODE) | ||
val deviceId by it.json.byString(NAME_DEVICE_ID) | ||
val deviceName by it.json.byNullableString(NAME_DEVICE_NAME) | ||
val clickType by it.json.byInt(NAME_CLICK_TYPE) | ||
|
||
// nullable because this property was added after backup and restore was released. | ||
val flags by it.json.byNullableInt(NAME_FLAGS) | ||
val uid by it.json.byNullableString(NAME_UID) | ||
|
||
TriggerKeyEntity( | ||
keycode, | ||
deviceId, | ||
deviceName, | ||
clickType, | ||
flags ?: 0, | ||
uid ?: UUID.randomUUID().toString(), | ||
) | ||
} | ||
} | ||
} |
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
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