From be93e77d2366231e9df3ad30ea915123b3327908 Mon Sep 17 00:00:00 2001 From: sds100 Date: Thu, 3 Oct 2024 15:31:39 +0200 Subject: [PATCH] #1274 name KeyMapTrigger to CustomTrigger --- .../keymapper/data/entities/TriggerEntity.kt | 4 +- .../data/migration/Migration11To12.kt | 4 +- .../mappings/keymaps/ConfigKeyMapUseCase.kt | 4 +- .../mappings/keymaps/ConfigKeyMapViewModel.kt | 2 +- ...el.kt => ConfigTriggerOptionsViewModel.kt} | 4 +- ...ViewModel.kt => ConfigTriggerViewModel.kt} | 39 +++++++++---------- .../mappings/keymaps/DisplayKeyMapUseCase.kt | 14 +++---- .../keymapper/mappings/keymaps/KeyMap.kt | 10 ++--- .../mappings/keymaps/KeyMapListItemCreator.kt | 18 ++++----- .../keymaps/RecordTriggerButtonRow.kt | 2 +- .../keymaps/detection/KeyMapController.kt | 28 ++++++------- .../trigger/ConfigTriggerOptionsFragment.kt | 4 +- .../{KeyMapTrigger.kt => CustomTrigger.kt} | 14 +++---- ...pTriggerError.kt => CustomTriggerError.kt} | 2 +- .../keymaps/trigger/TriggerFragment.kt | 24 ++++++------ .../mappings/keymaps/trigger/TriggerKey.kt | 2 +- .../fragment_trigger.xml | 2 +- .../layout-w600dp-land/fragment_trigger.xml | 2 +- .../layout-w900dp-h600dp/fragment_trigger.xml | 2 +- app/src/main/res/layout/fragment_trigger.xml | 2 +- ...kt => ConfigCustomTriggerViewModelTest.kt} | 6 +-- .../mappings/keymaps/KeyMapControllerTest.kt | 14 +++---- ...riggerKeyMapFromOtherAppsControllerTest.kt | 4 +- .../sds100/keymapper/util/KeyMapUtils.kt | 8 ++-- 24 files changed, 106 insertions(+), 109 deletions(-) rename app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/{ConfigKeyMapTriggerOptionsViewModel.kt => ConfigTriggerOptionsViewModel.kt} (98%) rename app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/{ConfigKeyMapTriggerViewModel.kt => ConfigTriggerViewModel.kt} (93%) rename app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/{KeyMapTrigger.kt => CustomTrigger.kt} (94%) rename app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/{KeyMapTriggerError.kt => CustomTriggerError.kt} (85%) rename app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/{ConfigKeyMapTriggerViewModelTest.kt => ConfigCustomTriggerViewModelTest.kt} (95%) diff --git a/app/src/main/java/io/github/sds100/keymapper/data/entities/TriggerEntity.kt b/app/src/main/java/io/github/sds100/keymapper/data/entities/TriggerEntity.kt index a8279aa957..650712d408 100644 --- a/app/src/main/java/io/github/sds100/keymapper/data/entities/TriggerEntity.kt +++ b/app/src/main/java/io/github/sds100/keymapper/data/entities/TriggerEntity.kt @@ -16,9 +16,6 @@ import java.util.UUID * Created by sds100 on 16/07/2018. */ -/** - * @property [keys] The key codes which will trigger the action - */ @Parcelize data class TriggerEntity( @SerializedName(NAME_KEYS) @@ -80,6 +77,7 @@ data class TriggerEntity( } } + // TODO move to separate file @Parcelize data class KeyEntity( @SerializedName(NAME_KEYCODE) diff --git a/app/src/main/java/io/github/sds100/keymapper/data/migration/Migration11To12.kt b/app/src/main/java/io/github/sds100/keymapper/data/migration/Migration11To12.kt index 8f0df017fa..eca08ec637 100644 --- a/app/src/main/java/io/github/sds100/keymapper/data/migration/Migration11To12.kt +++ b/app/src/main/java/io/github/sds100/keymapper/data/migration/Migration11To12.kt @@ -98,12 +98,12 @@ object Migration11To12 { val cursor = database.query(keyMapListQuery) val keyMapIdColumnIndex = cursor.getColumnIndex("id") - val keyMapTriggerColumnIndex = cursor.getColumnIndex("trigger") + val triggerColumnIndex = cursor.getColumnIndex("trigger") val keyMapActionListColumnIndex = cursor.getColumnIndex("action_list") while (cursor.moveToNext()) { val id = cursor.getLong(keyMapIdColumnIndex) - val triggerJson = cursor.getString(keyMapTriggerColumnIndex) + val triggerJson = cursor.getString(triggerColumnIndex) val triggerJsonObject = parser.parse(triggerJson).asJsonObject val actionListJson = cursor.getString(keyMapActionListColumnIndex) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt index 8746b8556a..9f412c96a1 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapUseCase.kt @@ -9,7 +9,7 @@ import io.github.sds100.keymapper.data.repositories.PreferenceRepository import io.github.sds100.keymapper.mappings.BaseConfigMappingUseCase import io.github.sds100.keymapper.mappings.ClickType import io.github.sds100.keymapper.mappings.ConfigMappingUseCase -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKey import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode @@ -435,7 +435,7 @@ class ConfigKeyMapUseCaseImpl( } } - private fun editTrigger(block: (trigger: KeyMapTrigger) -> KeyMapTrigger) { + private fun editTrigger(block: (trigger: CustomTrigger) -> CustomTrigger) { editKeyMap { keyMap -> val newTrigger = block(keyMap.trigger) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt index 9b4366b199..0ead48c9f8 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapViewModel.kt @@ -61,7 +61,7 @@ class ConfigKeyMapViewModel( resourceProvider, ) - val configTriggerViewModel = ConfigKeyMapTriggerViewModel( + val configTriggerViewModel = ConfigTriggerViewModel( viewModelScope, onboarding, config, diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerOptionsViewModel.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerOptionsViewModel.kt similarity index 98% rename from app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerOptionsViewModel.kt rename to app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerOptionsViewModel.kt index d59d6665b2..19577221b2 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerOptionsViewModel.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerOptionsViewModel.kt @@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext /** * Created by sds100 on 29/11/20. */ -class ConfigKeyMapTriggerOptionsViewModel( +class ConfigTriggerOptionsViewModel( private val coroutineScope: CoroutineScope, private val config: ConfigKeyMapUseCase, private val createKeyMapShortcut: CreateKeyMapShortcutUseCase, @@ -109,7 +109,7 @@ class ConfigKeyMapTriggerOptionsViewModel( result.onFailure { error -> val snackBar = PopupUi.SnackBar( - message = error.getFullMessage(this@ConfigKeyMapTriggerOptionsViewModel), + message = error.getFullMessage(this@ConfigTriggerOptionsViewModel), ) showPopup("create_shortcut_result", snackBar) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModel.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerViewModel.kt similarity index 93% rename from app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModel.kt rename to app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerViewModel.kt index ff661846ad..c019af1ed2 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModel.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/ConfigTriggerViewModel.kt @@ -2,11 +2,10 @@ package io.github.sds100.keymapper.mappings.keymaps import android.os.Build import android.view.KeyEvent -import androidx.compose.runtime.getValue import io.github.sds100.keymapper.R import io.github.sds100.keymapper.mappings.ClickType -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTriggerError +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTriggerError import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerState import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerUseCase import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice @@ -57,7 +56,7 @@ import kotlinx.coroutines.runBlocking * Created by sds100 on 24/11/20. */ -class ConfigKeyMapTriggerViewModel( +class ConfigTriggerViewModel( private val coroutineScope: CoroutineScope, private val onboarding: OnboardingUseCase, private val config: ConfigKeyMapUseCase, @@ -69,7 +68,7 @@ class ConfigKeyMapTriggerViewModel( PopupViewModel by PopupViewModelImpl(), NavigationViewModel by NavigationViewModelImpl() { - val optionsViewModel = ConfigKeyMapTriggerOptionsViewModel( + val optionsViewModel = ConfigTriggerOptionsViewModel( coroutineScope, config, createKeyMapShortcut, @@ -269,20 +268,20 @@ class ConfigKeyMapTriggerViewModel( } } - private fun buildTriggerErrorListItems(triggerErrors: List) = + private fun buildTriggerErrorListItems(triggerErrors: List) = triggerErrors.map { error -> when (error) { - KeyMapTriggerError.DND_ACCESS_DENIED -> TextListItem.Error( + CustomTriggerError.DND_ACCESS_DENIED -> TextListItem.Error( id = error.toString(), text = getString(R.string.trigger_error_dnd_access_denied), ) - KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED -> TextListItem.Error( + CustomTriggerError.SCREEN_OFF_ROOT_DENIED -> TextListItem.Error( id = error.toString(), text = getString(R.string.trigger_error_screen_off_root_permission_denied), ) - KeyMapTriggerError.CANT_DETECT_IN_PHONE_CALL -> TextListItem.Error( + CustomTriggerError.CANT_DETECT_IN_PHONE_CALL -> TextListItem.Error( id = error.toString(), text = getString(R.string.trigger_error_cant_detect_in_phone_call), ) @@ -367,8 +366,8 @@ class ConfigKeyMapTriggerViewModel( if (result is Error.AccessibilityServiceDisabled) { ViewModelHelper.handleAccessibilityServiceStoppedSnackBar( - resourceProvider = this@ConfigKeyMapTriggerViewModel, - popupViewModel = this@ConfigKeyMapTriggerViewModel, + resourceProvider = this@ConfigTriggerViewModel, + popupViewModel = this@ConfigTriggerViewModel, startService = displayKeyMap::startAccessibilityService, message = R.string.dialog_message_enable_accessibility_service_to_record_trigger, ) @@ -376,8 +375,8 @@ class ConfigKeyMapTriggerViewModel( if (result is Error.AccessibilityServiceCrashed) { ViewModelHelper.handleAccessibilityServiceCrashedSnackBar( - resourceProvider = this@ConfigKeyMapTriggerViewModel, - popupViewModel = this@ConfigKeyMapTriggerViewModel, + resourceProvider = this@ConfigTriggerViewModel, + popupViewModel = this@ConfigTriggerViewModel, restartService = displayKeyMap::restartAccessibilityService, message = R.string.dialog_message_restart_accessibility_service_to_record_trigger, ) @@ -393,22 +392,22 @@ class ConfigKeyMapTriggerViewModel( fun onTriggerErrorClick(listItemId: String) { coroutineScope.launch { - when (KeyMapTriggerError.valueOf(listItemId)) { - KeyMapTriggerError.DND_ACCESS_DENIED -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + when (CustomTriggerError.valueOf(listItemId)) { + CustomTriggerError.DND_ACCESS_DENIED -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { ViewModelHelper.showDialogExplainingDndAccessBeingUnavailable( - resourceProvider = this@ConfigKeyMapTriggerViewModel, - popupViewModel = this@ConfigKeyMapTriggerViewModel, + resourceProvider = this@ConfigTriggerViewModel, + popupViewModel = this@ConfigTriggerViewModel, neverShowDndTriggerErrorAgain = { displayKeyMap.neverShowDndTriggerErrorAgain() }, fixError = { displayKeyMap.fixError(it) }, ) } - KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED -> { + CustomTriggerError.SCREEN_OFF_ROOT_DENIED -> { val error = Error.PermissionDenied(Permission.ROOT) displayKeyMap.fixError(error) } - KeyMapTriggerError.CANT_DETECT_IN_PHONE_CALL -> { + CustomTriggerError.CANT_DETECT_IN_PHONE_CALL -> { displayKeyMap.fixError(Error.CantDetectKeyEventsInPhoneCall) } } @@ -416,7 +415,7 @@ class ConfigKeyMapTriggerViewModel( } private fun createListItems( - trigger: KeyMapTrigger, + trigger: CustomTrigger, showDeviceDescriptors: Boolean, ): List = trigger.keys.mapIndexed { index, key -> diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/DisplayKeyMapUseCase.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/DisplayKeyMapUseCase.kt index cb9eac6c7a..d26574abb7 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/DisplayKeyMapUseCase.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/DisplayKeyMapUseCase.kt @@ -5,7 +5,7 @@ import android.view.KeyEvent import io.github.sds100.keymapper.data.Keys import io.github.sds100.keymapper.data.repositories.PreferenceRepository import io.github.sds100.keymapper.mappings.DisplaySimpleMappingUseCase -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTriggerError +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTriggerError import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter import io.github.sds100.keymapper.system.inputmethod.KeyMapperImeHelper import io.github.sds100.keymapper.system.permissions.Permission @@ -40,20 +40,20 @@ class DisplayKeyMapUseCaseImpl( preferenceRepository.get(Keys.neverShowDndError).map { }.drop(1), ) - override suspend fun getTriggerErrors(keyMap: KeyMap): List { + override suspend fun getTriggerErrors(keyMap: KeyMap): List { val trigger = keyMap.trigger - val errors = mutableListOf() + val errors = mutableListOf() // can only detect volume button presses during a phone call with an input method service if (!keyMapperImeHelper.isCompatibleImeChosen() && keyMap.requiresImeKeyEventForwarding()) { - errors.add(KeyMapTriggerError.CANT_DETECT_IN_PHONE_CALL) + errors.add(CustomTriggerError.CANT_DETECT_IN_PHONE_CALL) } if (trigger.keys.any { it.keyCode in keysThatRequireDndAccess }) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !permissionAdapter.isGranted(Permission.ACCESS_NOTIFICATION_POLICY) ) { - errors.add(KeyMapTriggerError.DND_ACCESS_DENIED) + errors.add(CustomTriggerError.DND_ACCESS_DENIED) } } @@ -61,7 +61,7 @@ class DisplayKeyMapUseCaseImpl( !permissionAdapter.isGranted(Permission.ROOT) && trigger.isDetectingWhenScreenOffAllowed() ) { - errors.add(KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED) + errors.add(CustomTriggerError.SCREEN_OFF_ROOT_DENIED) } return errors @@ -70,5 +70,5 @@ class DisplayKeyMapUseCaseImpl( interface DisplayKeyMapUseCase : DisplaySimpleMappingUseCase { val invalidateTriggerErrors: Flow - suspend fun getTriggerErrors(keyMap: KeyMap): List + suspend fun getTriggerErrors(keyMap: KeyMap): List } diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMap.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMap.kt index 48099c3dad..310b92e29b 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMap.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMap.kt @@ -9,8 +9,8 @@ import io.github.sds100.keymapper.constraints.ConstraintState import io.github.sds100.keymapper.data.entities.KeyMapEntity import io.github.sds100.keymapper.mappings.Mapping import io.github.sds100.keymapper.mappings.keymaps.detection.KeyMapController -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeymapTriggerEntityMapper +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTriggerEntityMapper import kotlinx.serialization.Serializable import java.util.UUID @@ -22,7 +22,7 @@ import java.util.UUID data class KeyMap( val dbId: Long? = null, val uid: String = UUID.randomUUID().toString(), - val trigger: KeyMapTrigger = KeyMapTrigger(), + val trigger: CustomTrigger = CustomTrigger(), override val actionList: List = emptyList(), override val constraintState: ConstraintState = ConstraintState(), override val isEnabled: Boolean = true, @@ -81,7 +81,7 @@ object KeyMapEntityMapper { return KeyMap( dbId = entity.id, uid = entity.uid, - trigger = KeymapTriggerEntityMapper.fromEntity(entity.trigger), + trigger = CustomTriggerEntityMapper.fromEntity(entity.trigger), actionList = actionList, constraintState = ConstraintState(constraintList, constraintMode), isEnabled = entity.isEnabled, @@ -93,7 +93,7 @@ object KeyMapEntityMapper { return KeyMapEntity( id = dbId, - trigger = KeymapTriggerEntityMapper.toEntity(keyMap.trigger), + trigger = CustomTriggerEntityMapper.toEntity(keyMap.trigger), actionList = actionEntityList, constraintList = keyMap.constraintState.constraints.map { ConstraintEntityMapper.toEntity( diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapListItemCreator.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapListItemCreator.kt index 38b3502647..85b9480619 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapListItemCreator.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapListItemCreator.kt @@ -3,8 +3,8 @@ package io.github.sds100.keymapper.mappings.keymaps import io.github.sds100.keymapper.R import io.github.sds100.keymapper.mappings.BaseMappingListItemCreator import io.github.sds100.keymapper.mappings.ClickType -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTriggerError +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTriggerError import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode import io.github.sds100.keymapper.system.devices.InputDeviceUtils @@ -111,21 +111,21 @@ class KeyMapListItemCreator( val triggerErrorChips = triggerErrors.map { when (it) { - KeyMapTriggerError.DND_ACCESS_DENIED -> + CustomTriggerError.DND_ACCESS_DENIED -> ChipUi.Error( - id = KeyMapTriggerError.DND_ACCESS_DENIED.toString(), + id = CustomTriggerError.DND_ACCESS_DENIED.toString(), text = getString(R.string.trigger_error_dnd_access_denied_short), error = Error.PermissionDenied(Permission.ACCESS_NOTIFICATION_POLICY), ) - KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED -> ChipUi.Error( - id = KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED.toString(), + CustomTriggerError.SCREEN_OFF_ROOT_DENIED -> ChipUi.Error( + id = CustomTriggerError.SCREEN_OFF_ROOT_DENIED.toString(), text = getString(R.string.trigger_error_screen_off_root_permission_denied_short), error = Error.PermissionDenied(Permission.ROOT), ) - KeyMapTriggerError.CANT_DETECT_IN_PHONE_CALL -> ChipUi.Error( - id = KeyMapTriggerError.SCREEN_OFF_ROOT_DENIED.toString(), + CustomTriggerError.CANT_DETECT_IN_PHONE_CALL -> ChipUi.Error( + id = CustomTriggerError.SCREEN_OFF_ROOT_DENIED.toString(), text = getString(R.string.trigger_error_cant_detect_in_phone_call), error = Error.CantDetectKeyEventsInPhoneCall, ) @@ -143,7 +143,7 @@ class KeyMapListItemCreator( ) } - private fun getTriggerOptionLabels(trigger: KeyMapTrigger): List { + private fun getTriggerOptionLabels(trigger: CustomTrigger): List { val labels = mutableListOf() if (trigger.isVibrateAllowed() && trigger.vibrate) { diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/RecordTriggerButtonRow.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/RecordTriggerButtonRow.kt index c181a35057..95f16cd088 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/RecordTriggerButtonRow.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/RecordTriggerButtonRow.kt @@ -41,7 +41,7 @@ import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerState @Composable fun RecordTriggerButtonRow( modifier: Modifier = Modifier, - viewModel: ConfigKeyMapTriggerViewModel, + viewModel: ConfigTriggerViewModel, ) { val recordTriggerState by viewModel.recordTriggerState.collectAsState() val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/KeyMapController.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/KeyMapController.kt index 2e5a83a7de..22249f707d 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/KeyMapController.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/KeyMapController.kt @@ -15,7 +15,7 @@ import io.github.sds100.keymapper.data.entities.ActionEntity import io.github.sds100.keymapper.mappings.ClickType import io.github.sds100.keymapper.mappings.keymaps.KeyMap import io.github.sds100.keymapper.mappings.keymaps.KeyMapAction -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKey import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode @@ -57,13 +57,13 @@ class KeyMapController( * @return whether the actions assigned to this trigger will be performed on the down event of the final key * rather than the up event. */ - fun performActionOnDown(trigger: KeyMapTrigger): Boolean = ( - trigger.keys.size <= 1 && - trigger.keys.getOrNull(0)?.clickType != ClickType.DOUBLE_PRESS && - trigger.mode == TriggerMode.Undefined - ) || + fun performActionOnDown(trigger: CustomTrigger): Boolean = ( + trigger.keys.size <= 1 && + trigger.keys.getOrNull(0)?.clickType != ClickType.DOUBLE_PRESS && + trigger.mode == TriggerMode.Undefined + ) || - trigger.mode is TriggerMode.Parallel + trigger.mode is TriggerMode.Parallel } /** @@ -96,7 +96,7 @@ class KeyMapController( setActionMapAndOptions(value.flatMap { it.actionList }.toSet()) - val triggers = mutableListOf() + val triggers = mutableListOf() val sequenceTriggers = mutableListOf() val parallelTriggers = mutableListOf() @@ -407,7 +407,7 @@ class KeyMapController( private var doublePressTimeoutTimes = longArrayOf() private var actionMap: SparseArrayCompat = SparseArrayCompat() - private var triggers: Array = emptyArray() + private var triggers: Array = emptyArray() /** * The events to detect for each sequence trigger. @@ -1470,7 +1470,7 @@ class KeyMapController( } } - private fun KeyMapTrigger.matchingEventAtIndex(event: Event, index: Int): Boolean { + private fun CustomTrigger.matchingEventAtIndex(event: Event, index: Int): Boolean { if (index >= this.keys.size) return false val key = this.keys[index] @@ -1508,16 +1508,16 @@ class KeyMapController( this.clickType == otherKey.clickType } - private fun longPressDelay(trigger: KeyMapTrigger): Long = + private fun longPressDelay(trigger: CustomTrigger): Long = trigger.longPressDelay?.toLong() ?: defaultLongPressDelay.value - private fun doublePressTimeout(trigger: KeyMapTrigger): Long = + private fun doublePressTimeout(trigger: CustomTrigger): Long = trigger.doublePressDelay?.toLong() ?: defaultDoublePressDelay.value - private fun vibrateDuration(trigger: KeyMapTrigger): Long = + private fun vibrateDuration(trigger: CustomTrigger): Long = trigger.vibrateDuration?.toLong() ?: defaultVibrateDuration.value - private fun sequenceTriggerTimeout(trigger: KeyMapTrigger): Long = + private fun sequenceTriggerTimeout(trigger: CustomTrigger): Long = trigger.sequenceTriggerTimeout?.toLong() ?: defaultSequenceTriggerTimeout.value private fun setActionMapAndOptions(actions: Set) { diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/ConfigTriggerOptionsFragment.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/ConfigTriggerOptionsFragment.kt index 1f8cb7419b..f250ea72fa 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/ConfigTriggerOptionsFragment.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/ConfigTriggerOptionsFragment.kt @@ -6,8 +6,8 @@ import androidx.core.content.getSystemService import androidx.navigation.navGraphViewModels import com.airbnb.epoxy.EpoxyRecyclerView import io.github.sds100.keymapper.R -import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapTriggerOptionsViewModel import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapViewModel +import io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerOptionsViewModel import io.github.sds100.keymapper.system.url.UrlUtils import io.github.sds100.keymapper.triggerFromOtherApps import io.github.sds100.keymapper.ui.utils.configuredCheckBox @@ -39,7 +39,7 @@ class ConfigTriggerOptionsFragment : SimpleRecyclerViewFragment() { Inject.configKeyMapViewModel(requireContext()) } - private val viewModel: ConfigKeyMapTriggerOptionsViewModel + private val viewModel: ConfigTriggerOptionsViewModel get() = configKeyMapViewModel.configTriggerViewModel.optionsViewModel override var isAppBarVisible = false diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTrigger.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTrigger.kt similarity index 94% rename from app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTrigger.kt rename to app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTrigger.kt index e00454c0df..5f4fb4cb27 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTrigger.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTrigger.kt @@ -15,7 +15,7 @@ import splitties.bitflags.withFlag */ @Serializable -data class KeyMapTrigger( +data class CustomTrigger( val keys: List = emptyList(), val mode: TriggerMode = TriggerMode.Undefined, val vibrate: Boolean = false, @@ -51,11 +51,11 @@ data class KeyMapTrigger( !keys.isNullOrEmpty() && keys.size > 1 && mode is TriggerMode.Sequence } -object KeymapTriggerEntityMapper { +object CustomTriggerEntityMapper { fun fromEntity( entity: TriggerEntity, - ): KeyMapTrigger { - val keys = entity.keys.map { KeymapTriggerKeyEntityMapper.fromEntity(it) } + ): CustomTrigger { + val keys = entity.keys.map { TriggerKeyEntityMapper.fromEntity(it) } val mode = when { entity.mode == TriggerEntity.SEQUENCE && keys.size > 1 -> TriggerMode.Sequence @@ -63,7 +63,7 @@ object KeymapTriggerEntityMapper { else -> TriggerMode.Undefined } - return KeyMapTrigger( + return CustomTrigger( keys = keys, mode = mode, @@ -90,7 +90,7 @@ object KeymapTriggerEntityMapper { ) } - fun toEntity(trigger: KeyMapTrigger): TriggerEntity { + fun toEntity(trigger: CustomTrigger): TriggerEntity { val extras = mutableListOf() if (trigger.isChangingSequenceTriggerTimeoutAllowed() && trigger.sequenceTriggerTimeout != null) { @@ -158,7 +158,7 @@ object KeymapTriggerEntityMapper { } return TriggerEntity( - keys = trigger.keys.map { KeymapTriggerKeyEntityMapper.toEntity(it) }, + keys = trigger.keys.map { TriggerKeyEntityMapper.toEntity(it) }, extras = extras, mode = mode, flags = flags, diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTriggerError.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTriggerError.kt similarity index 85% rename from app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTriggerError.kt rename to app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTriggerError.kt index c1a996ef6d..93b5e9803f 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/KeyMapTriggerError.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/CustomTriggerError.kt @@ -3,7 +3,7 @@ package io.github.sds100.keymapper.mappings.keymaps.trigger /** * Created by sds100 on 04/04/2021. */ -enum class KeyMapTriggerError { +enum class CustomTriggerError { DND_ACCESS_DENIED, SCREEN_OFF_ROOT_DENIED, CANT_DETECT_IN_PHONE_CALL, diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerFragment.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerFragment.kt index 3600cf1534..8cddee8eb9 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerFragment.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerFragment.kt @@ -18,8 +18,8 @@ import io.github.sds100.keymapper.TriggerKeyBindingModel_ import io.github.sds100.keymapper.compose.KeyMapperTheme import io.github.sds100.keymapper.databinding.FragmentTriggerBinding import io.github.sds100.keymapper.fixError -import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapTriggerViewModel import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapViewModel +import io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel import io.github.sds100.keymapper.mappings.keymaps.RecordTriggerButtonRow import io.github.sds100.keymapper.triggerKey import io.github.sds100.keymapper.util.FragmentInfo @@ -43,7 +43,7 @@ class TriggerFragment : RecyclerViewFragment(R.id.nav_config_keymap) { Inject.configKeyMapViewModel(requireContext()) }.value.configTriggerViewModel @@ -52,7 +52,7 @@ class TriggerFragment : RecyclerViewFragment>> - get() = configKeyMapTriggerViewModel.triggerKeyListItems + get() = configTriggerViewModel.triggerKeyListItems override fun bind(inflater: LayoutInflater, container: ViewGroup?) = FragmentTriggerBinding.inflate(inflater, container, false).apply { @@ -64,19 +64,19 @@ class TriggerFragment : RecyclerViewFragment + configTriggerViewModel.errorListItems.collectLatest { listItems -> binding.enableTriggerKeyDragging(triggerKeyController) @@ -87,7 +87,7 @@ class TriggerFragment : RecyclerViewFragment - configKeyMapTriggerViewModel.onTriggerErrorClick(it.id) + configTriggerViewModel.onTriggerErrorClick(it.id) } } } @@ -111,7 +111,7 @@ class TriggerFragment : RecyclerViewFragment - configKeyMapTriggerViewModel.onRemoveKeyClick(model.id) + configTriggerViewModel.onRemoveKeyClick(model.id) } onMoreClick { _ -> - configKeyMapTriggerViewModel.onTriggerKeyOptionsClick(model.id) + configTriggerViewModel.onTriggerKeyOptionsClick(model.id) } onDeviceClick { _ -> - configKeyMapTriggerViewModel.onChooseDeviceClick(model.id) + configTriggerViewModel.onChooseDeviceClick(model.id) } } } diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerKey.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerKey.kt index d437859aa5..b21eeecc5b 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerKey.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/TriggerKey.kt @@ -30,7 +30,7 @@ data class TriggerKey( } } -object KeymapTriggerKeyEntityMapper { +object TriggerKeyEntityMapper { fun fromEntity( entity: TriggerEntity.KeyEntity, ): TriggerKey = TriggerKey( diff --git a/app/src/main/res/layout-w1000dp-h400dp-land/fragment_trigger.xml b/app/src/main/res/layout-w1000dp-h400dp-land/fragment_trigger.xml index 93db4f2df4..26b6b399e7 100644 --- a/app/src/main/res/layout-w1000dp-h400dp-land/fragment_trigger.xml +++ b/app/src/main/res/layout-w1000dp-h400dp-land/fragment_trigger.xml @@ -9,7 +9,7 @@ + type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" /> diff --git a/app/src/main/res/layout-w600dp-land/fragment_trigger.xml b/app/src/main/res/layout-w600dp-land/fragment_trigger.xml index 3955cbf244..88710ebe69 100644 --- a/app/src/main/res/layout-w600dp-land/fragment_trigger.xml +++ b/app/src/main/res/layout-w600dp-land/fragment_trigger.xml @@ -10,7 +10,7 @@ + type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" /> + type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" /> + type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" /> diff --git a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModelTest.kt b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigCustomTriggerViewModelTest.kt similarity index 95% rename from app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModelTest.kt rename to app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigCustomTriggerViewModelTest.kt index 608eda705d..5e8250472a 100644 --- a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigKeyMapTriggerViewModelTest.kt +++ b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/ConfigCustomTriggerViewModelTest.kt @@ -34,12 +34,12 @@ import org.mockito.kotlin.mock @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) -class ConfigKeyMapTriggerViewModelTest { +class ConfigCustomTriggerViewModelTest { private val testDispatcher = UnconfinedTestDispatcher() private val testScope = TestScope(testDispatcher) - private lateinit var viewModel: ConfigKeyMapTriggerViewModel + private lateinit var viewModel: ConfigTriggerViewModel private lateinit var mockConfigKeyMapUseCase: ConfigKeyMapUseCase private lateinit var mockRecordTrigger: RecordTriggerUseCase private lateinit var fakeOnboarding: FakeOnboardingUseCase @@ -66,7 +66,7 @@ class ConfigKeyMapTriggerViewModelTest { fakeResourceProvider = FakeResourceProvider() - viewModel = ConfigKeyMapTriggerViewModel( + viewModel = ConfigTriggerViewModel( testScope, fakeOnboarding, mockConfigKeyMapUseCase, diff --git a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapControllerTest.kt b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapControllerTest.kt index 0cbfa8b502..411076a8e8 100644 --- a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapControllerTest.kt +++ b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/KeyMapControllerTest.kt @@ -12,7 +12,7 @@ import io.github.sds100.keymapper.constraints.DetectConstraintsUseCase import io.github.sds100.keymapper.mappings.ClickType import io.github.sds100.keymapper.mappings.keymaps.detection.DetectKeyMapsUseCase import io.github.sds100.keymapper.mappings.keymaps.detection.KeyMapController -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKey import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode @@ -378,7 +378,7 @@ class KeyMapControllerTest { runTest(testDispatcher) { // GIVEN val keyMap1 = KeyMap( - trigger = KeyMapTrigger( + trigger = CustomTrigger( keys = listOf(triggerKey(KeyEvent.KEYCODE_VOLUME_DOWN)), longPressDelay = 500, ), @@ -386,7 +386,7 @@ class KeyMapControllerTest { ) val keyMap2 = KeyMap( - trigger = KeyMapTrigger( + trigger = CustomTrigger( keys = listOf(triggerKey(KeyEvent.KEYCODE_VOLUME_DOWN)), longPressDelay = 1000, ), @@ -1980,7 +1980,7 @@ class KeyMapControllerTest { @Test @Parameters(method = "params_repeatAction") - fun parallelTrigger_holdDown_repeatAction10Times(description: String, trigger: KeyMapTrigger) = + fun parallelTrigger_holdDown_repeatAction10Times(description: String, trigger: CustomTrigger) = runTest(testDispatcher) { // given val action = KeyMapAction( @@ -2032,7 +2032,7 @@ class KeyMapControllerTest { @Parameters(method = "params_dualParallelTrigger_input2ndKey_doNotConsumeUp") fun dualParallelTrigger_input2ndKey_doNotConsumeUp( description: String, - trigger: KeyMapTrigger, + trigger: CustomTrigger, ) = runTest(testDispatcher) { // given @@ -2304,7 +2304,7 @@ class KeyMapControllerTest { @Test @Parameters(method = "params_multipleActionsPerformed") - fun validInput_multipleActionsPerformed(description: String, trigger: KeyMapTrigger) = + fun validInput_multipleActionsPerformed(description: String, trigger: CustomTrigger) = runTest(testDispatcher) { val actionList = listOf(TEST_ACTION, TEST_ACTION_2) // GIVEN @@ -3259,7 +3259,7 @@ class KeyMapControllerTest { ) private suspend fun mockParallelTrigger( - trigger: KeyMapTrigger, + trigger: CustomTrigger, delay: Long? = null, ) { require(trigger.mode is TriggerMode.Parallel) diff --git a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/TriggerKeyMapFromOtherAppsControllerTest.kt b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/TriggerKeyMapFromOtherAppsControllerTest.kt index 429e26b30f..8bb79a0b3a 100644 --- a/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/TriggerKeyMapFromOtherAppsControllerTest.kt +++ b/app/src/test/java/io/github/sds100/keymapper/mappings/keymaps/TriggerKeyMapFromOtherAppsControllerTest.kt @@ -6,7 +6,7 @@ import io.github.sds100.keymapper.actions.RepeatMode import io.github.sds100.keymapper.constraints.ConstraintSnapshotImpl import io.github.sds100.keymapper.constraints.DetectConstraintsUseCase import io.github.sds100.keymapper.mappings.keymaps.detection.DetectKeyMapsUseCase -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger import junitparams.JUnitParamsRunner import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay @@ -115,7 +115,7 @@ class TriggerKeyMapFromOtherAppsControllerTest { ) val keyMap = KeyMap( actionList = listOf(action), - trigger = KeyMapTrigger(triggerFromOtherApps = true), + trigger = CustomTrigger(triggerFromOtherApps = true), ) keyMapListFlow.value = listOf(keyMap) diff --git a/app/src/test/java/io/github/sds100/keymapper/util/KeyMapUtils.kt b/app/src/test/java/io/github/sds100/keymapper/util/KeyMapUtils.kt index aeb5af1aed..e47b2b8151 100644 --- a/app/src/test/java/io/github/sds100/keymapper/util/KeyMapUtils.kt +++ b/app/src/test/java/io/github/sds100/keymapper/util/KeyMapUtils.kt @@ -1,7 +1,7 @@ package io.github.sds100.keymapper.util import io.github.sds100.keymapper.mappings.ClickType -import io.github.sds100.keymapper.mappings.keymaps.trigger.KeyMapTrigger +import io.github.sds100.keymapper.mappings.keymaps.trigger.CustomTrigger import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKey import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode @@ -10,17 +10,17 @@ import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode * Created by sds100 on 19/04/2021. */ -fun singleKeyTrigger(key: TriggerKey): KeyMapTrigger = KeyMapTrigger( +fun singleKeyTrigger(key: TriggerKey): CustomTrigger = CustomTrigger( keys = listOf(key), mode = TriggerMode.Undefined, ) -fun parallelTrigger(vararg keys: TriggerKey): KeyMapTrigger = KeyMapTrigger( +fun parallelTrigger(vararg keys: TriggerKey): CustomTrigger = CustomTrigger( keys = keys.toList(), mode = TriggerMode.Parallel(keys[0].clickType), ) -fun sequenceTrigger(vararg keys: TriggerKey): KeyMapTrigger = KeyMapTrigger( +fun sequenceTrigger(vararg keys: TriggerKey): CustomTrigger = CustomTrigger( keys = keys.toList(), mode = TriggerMode.Sequence, )