Skip to content

Commit

Permalink
#1274 fix: only show button for long press if all the keys are key co…
Browse files Browse the repository at this point in the history
…de triggers
  • Loading branch information
sds100 committed Nov 14, 2024
1 parent 3cc1549 commit ad1af28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ abstract class BaseConfigTriggerViewModel(
}
}.flowOn(Dispatchers.Default).stateIn(coroutineScope, SharingStarted.Eagerly, false)

/**
* Long press is only allowed for triggers that only use key code trigger keys.
*/
val longPressButtonVisible: StateFlow<Boolean> = config.mapping.map { state ->
when (state) {
is State.Data -> state.data.trigger.keys.all { it is KeyCodeTriggerKey }
State.Loading -> false
}
}.flowOn(Dispatchers.Default).stateIn(coroutineScope, SharingStarted.Eagerly, false)

/**
* Only show the buttons for the trigger mode if keys have been added. The buttons
* shouldn't be shown when no trigger is selected because they aren't relevant
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_trigger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/radio_button_long_press" />
android:text="@string/radio_button_long_press"
android:visibility="@{viewModel.longPressButtonVisible ? View.VISIBLE : View.GONE}" />

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/radioButtonDoublePress"
Expand Down

0 comments on commit ad1af28

Please sign in to comment.