Skip to content

Commit

Permalink
#1274: represent assistant triggers as normal key map trigger keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Oct 3, 2024
1 parent af0c895 commit c82459a
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.sds100.keymapper.mappings.keymaps.trigger

import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase
import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCase
import io.github.sds100.keymapper.mappings.keymaps.DisplayKeyMapUseCase
import io.github.sds100.keymapper.onboarding.OnboardingUseCase
import io.github.sds100.keymapper.util.ui.ResourceProvider
import kotlinx.coroutines.CoroutineScope

/**
* Created by sds100 on 24/11/20.
*/

class ConfigTriggerViewModel(
coroutineScope: CoroutineScope,
onboarding: OnboardingUseCase,
config: ConfigKeyMapUseCase,
recordTrigger: RecordTriggerUseCase,
createKeyMapShortcut: CreateKeyMapShortcutUseCase,
displayKeyMap: DisplayKeyMapUseCase,
resourceProvider: ResourceProvider,
) : BaseConfigTriggerViewModel(
coroutineScope,
onboarding,
config,
recordTrigger,
createKeyMapShortcut,
displayKeyMap,
resourceProvider,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.github.sds100.keymapper.constraints.ConstraintUtils
import io.github.sds100.keymapper.mappings.ConfigMappingUiState
import io.github.sds100.keymapper.mappings.ConfigMappingViewModel
import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerKeyViewModel
import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerUseCase
import io.github.sds100.keymapper.onboarding.OnboardingUseCase
import io.github.sds100.keymapper.ui.utils.getJsonSerializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.github.sds100.keymapper.mappings.keymaps
package io.github.sds100.keymapper.mappings.keymaps.trigger

import android.os.Build
import android.view.KeyEvent
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.mappings.ClickType
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.Trigger
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerError
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyLinkType
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyListItem
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerMode
import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase
import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCase
import io.github.sds100.keymapper.mappings.keymaps.DisplayKeyMapUseCase
import io.github.sds100.keymapper.mappings.keymaps.KeyMap
import io.github.sds100.keymapper.onboarding.OnboardingUseCase
import io.github.sds100.keymapper.system.devices.InputDeviceUtils
import io.github.sds100.keymapper.system.keyevents.KeyEventUtils
Expand Down Expand Up @@ -56,7 +52,7 @@ import kotlinx.coroutines.runBlocking
* Created by sds100 on 24/11/20.
*/

class ConfigTriggerViewModel(
abstract class BaseConfigTriggerViewModel(
private val coroutineScope: CoroutineScope,
private val onboarding: OnboardingUseCase,
private val config: ConfigKeyMapUseCase,
Expand Down Expand Up @@ -366,17 +362,17 @@ class ConfigTriggerViewModel(

if (result is Error.AccessibilityServiceDisabled) {
ViewModelHelper.handleAccessibilityServiceStoppedSnackBar(
resourceProvider = this@ConfigTriggerViewModel,
popupViewModel = this@ConfigTriggerViewModel,
resourceProvider = this@BaseConfigTriggerViewModel,
popupViewModel = this@BaseConfigTriggerViewModel,
startService = displayKeyMap::startAccessibilityService,
message = R.string.dialog_message_enable_accessibility_service_to_record_trigger,
)
}

if (result is Error.AccessibilityServiceCrashed) {
ViewModelHelper.handleAccessibilityServiceCrashedSnackBar(
resourceProvider = this@ConfigTriggerViewModel,
popupViewModel = this@ConfigTriggerViewModel,
resourceProvider = this@BaseConfigTriggerViewModel,
popupViewModel = this@BaseConfigTriggerViewModel,
restartService = displayKeyMap::restartAccessibilityService,
message = R.string.dialog_message_restart_accessibility_service_to_record_trigger,
)
Expand All @@ -395,8 +391,8 @@ class ConfigTriggerViewModel(
when (TriggerError.valueOf(listItemId)) {
TriggerError.DND_ACCESS_DENIED -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ViewModelHelper.showDialogExplainingDndAccessBeingUnavailable(
resourceProvider = this@ConfigTriggerViewModel,
popupViewModel = this@ConfigTriggerViewModel,
resourceProvider = this@BaseConfigTriggerViewModel,
popupViewModel = this@BaseConfigTriggerViewModel,
neverShowDndTriggerErrorAgain = { displayKeyMap.neverShowDndTriggerErrorAgain() },
fixError = { displayKeyMap.fixError(it) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.navigation.navGraphViewModels
import com.airbnb.epoxy.EpoxyRecyclerView
import io.github.sds100.keymapper.R
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.sds100.keymapper.mappings.keymaps
package io.github.sds100.keymapper.mappings.keymaps.trigger

import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.mappings.OptionMinimums
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerFromOtherAppsListItem
import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCase
import io.github.sds100.keymapper.mappings.keymaps.CreateKeyMapShortcutUseCase
import io.github.sds100.keymapper.mappings.keymaps.KeyMap
import io.github.sds100.keymapper.util.Defaultable
import io.github.sds100.keymapper.util.State
import io.github.sds100.keymapper.util.dataOrNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sds100.keymapper.mappings.keymaps
package io.github.sds100.keymapper.mappings.keymaps.trigger

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -31,8 +31,6 @@ import androidx.compose.ui.unit.dp
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.compose.KeyMapperTheme
import io.github.sds100.keymapper.compose.LocalCustomColorsPalette
import io.github.sds100.keymapper.mappings.keymaps.trigger.AdvancedTriggersBottomSheet
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerState

/**
* This row of buttons is shown at the bottom of the TriggerFragment.
Expand All @@ -53,6 +51,7 @@ fun RecordTriggerButtonRow(
onDismissRequest = {
showBottomSheet = false
},
onChooseAssistantTrigger = viewModel::onChooseAssistantTrigger,
sheetState = sheetState,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ 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.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
import io.github.sds100.keymapper.util.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<variable
name="viewModel"
type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" />
type="io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel" />

</data>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout-w600dp-land/fragment_trigger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<variable
name="viewModel"
type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" />
type="io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout-w900dp-h600dp/fragment_trigger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<variable
name="viewModel"
type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" />
type="io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_trigger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<variable
name="viewModel"
type="io.github.sds100.keymapper.mappings.keymaps.ConfigTriggerViewModel" />
type="io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel" />

</data>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.sds100.keymapper.mappings.keymaps

import android.view.KeyEvent
import io.github.sds100.keymapper.R
import io.github.sds100.keymapper.mappings.keymaps.trigger.ConfigTriggerViewModel
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.RecordedKey
Expand Down

0 comments on commit c82459a

Please sign in to comment.