Skip to content

Commit cecbb02

Browse files
committed
Merge branch 'develop' into copilot/hinge-closed-open-constraint
2 parents cea95d4 + fa34fd5 commit cecbb02

File tree

65 files changed

+1256
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1256
-755
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- #727 Actions to send SMS messages: "Send SMS" and "Compose SMS"
1818
- #1819 Explain how to enable the accessibility service restricted setting
1919
- #661 Action to execute shell commands.
20+
- #991 Consolidated volume and stream actions.
21+
- #1066 Action to mute/unmute microphone.
2022

2123
## Removed
2224

@@ -42,7 +44,8 @@
4244
- #1818 the Key Mapper GUI Keyboard is no longer mentioned in the app. It still works but PRO mode
4345
and the auto switching feature are the preferred way to work around the limitations of the Key
4446
Mapper keyboard.
45-
- Allow selecting notification and alarm sound and not just ringtones for Sound action
47+
- Allow selecting notification and alarm sound and not just ringtones for Sound action.
48+
- #1064 wait for switch keyboard action to complete before doing next action.
4649

4750
## [3.2.1](https://github.com/sds100/KeyMapper/releases/tag/v3.2.1)
4851

app/src/main/java/io/github/sds100/keymapper/trigger/ConfigTriggerViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class ConfigTriggerViewModel @Inject constructor(
5151

5252
override fun onEditFloatingLayoutClick() {}
5353

54-
override fun showTriggerSetup(shortcut: TriggerSetupShortcut) {
54+
override fun showTriggerSetup(shortcut: TriggerSetupShortcut, forceProMode: Boolean) {
5555
when (shortcut) {
5656
TriggerSetupShortcut.ASSISTANT -> viewModelScope.launch {
5757
navigateToAdvancedTriggers("purchase_assistant_trigger")
5858
}
5959

60-
else -> super.showTriggerSetup(shortcut)
60+
else -> super.showTriggerSetup(shortcut, forceProMode)
6161
}
6262
}
6363
}

base/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ dependencies {
9393
implementation(libs.google.flexbox)
9494
implementation(libs.squareup.okhttp)
9595
coreLibraryDesugaring(libs.desugar.jdk.libs)
96-
implementation(libs.canopas.introshowcaseview)
9796
implementation(libs.dagger.hilt.android)
9897
ksp(libs.dagger.hilt.android.compiler)
9998
implementation(libs.bundles.splitties)

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,40 @@ sealed class ActionData : Comparable<ActionData> {
9898

9999
@Serializable
100100
sealed class Volume : ActionData() {
101-
sealed class Stream : Volume() {
102-
abstract val volumeStream: VolumeStream
103-
abstract val showVolumeUi: Boolean
101+
@Serializable
102+
data class Up(
103+
val showVolumeUi: Boolean,
104+
val volumeStream: VolumeStream? = null,
105+
) : Volume() {
106+
override val id = ActionId.VOLUME_UP
104107

105108
override fun compareTo(other: ActionData) = when (other) {
106-
is Stream -> compareValuesBy(
109+
is Up -> compareValuesBy(
107110
this,
108111
other,
109-
{ it.id },
112+
{ it.showVolumeUi },
110113
{ it.volumeStream },
111114
)
112-
113115
else -> super.compareTo(other)
114116
}
115-
116-
@Serializable
117-
data class Increase(
118-
override val showVolumeUi: Boolean,
119-
override val volumeStream: VolumeStream,
120-
) : Stream() {
121-
override val id = ActionId.VOLUME_INCREASE_STREAM
122-
}
123-
124-
@Serializable
125-
data class Decrease(
126-
override val showVolumeUi: Boolean,
127-
override val volumeStream: VolumeStream,
128-
) : Stream() {
129-
override val id = ActionId.VOLUME_DECREASE_STREAM
130-
}
131117
}
132118

133119
@Serializable
134-
data class Up(val showVolumeUi: Boolean) : Volume() {
135-
override val id = ActionId.VOLUME_UP
136-
}
137-
138-
@Serializable
139-
data class Down(val showVolumeUi: Boolean) : Volume() {
120+
data class Down(
121+
val showVolumeUi: Boolean,
122+
val volumeStream: VolumeStream? = null,
123+
) : Volume() {
140124
override val id = ActionId.VOLUME_DOWN
125+
126+
override fun compareTo(other: ActionData) = when (other) {
127+
is Down -> compareValuesBy(
128+
this,
129+
other,
130+
{ it.showVolumeUi },
131+
{ it.volumeStream },
132+
)
133+
else -> super.compareTo(other)
134+
}
141135
}
142136

143137
@Serializable
@@ -183,6 +177,24 @@ sealed class ActionData : Comparable<ActionData> {
183177
}
184178
}
185179

180+
@Serializable
181+
sealed class Microphone : ActionData() {
182+
@Serializable
183+
data object Mute : Microphone() {
184+
override val id = ActionId.MUTE_MICROPHONE
185+
}
186+
187+
@Serializable
188+
data object Unmute : Microphone() {
189+
override val id = ActionId.UNMUTE_MICROPHONE
190+
}
191+
192+
@Serializable
193+
data object Toggle : Microphone() {
194+
override val id = ActionId.TOGGLE_MUTE_MICROPHONE
195+
}
196+
}
197+
186198
@Serializable
187199
sealed class Flashlight : ActionData() {
188200
abstract val lens: CameraLens

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ object ActionDataEntityMapper {
274274

275275
ActionId.VOLUME_INCREASE_STREAM,
276276
ActionId.VOLUME_DECREASE_STREAM,
277-
-> {
277+
-> {
278278
val stream =
279279
entity.extras.getData(ActionEntity.EXTRA_STREAM_TYPE).then {
280280
VOLUME_STREAM_MAP.getKey(it)!!.success()
@@ -283,12 +283,13 @@ object ActionDataEntityMapper {
283283
val showVolumeUi =
284284
entity.flags.hasFlag(ActionEntity.ACTION_FLAG_SHOW_VOLUME_UI)
285285

286+
// Convert old stream actions to new volume up/down with stream parameter
286287
when (actionId) {
287288
ActionId.VOLUME_INCREASE_STREAM ->
288-
ActionData.Volume.Stream.Increase(showVolumeUi, stream)
289+
ActionData.Volume.Up(showVolumeUi, stream)
289290

290291
ActionId.VOLUME_DECREASE_STREAM ->
291-
ActionData.Volume.Stream.Decrease(showVolumeUi, stream)
292+
ActionData.Volume.Down(showVolumeUi, stream)
292293

293294
else -> throw Exception("don't know how to create system action for $actionId")
294295
}
@@ -299,13 +300,22 @@ object ActionDataEntityMapper {
299300
ActionId.VOLUME_TOGGLE_MUTE,
300301
ActionId.VOLUME_UNMUTE,
301302
ActionId.VOLUME_MUTE,
302-
-> {
303+
-> {
303304
val showVolumeUi =
304305
entity.flags.hasFlag(ActionEntity.ACTION_FLAG_SHOW_VOLUME_UI)
305306

307+
// For VOLUME_UP and VOLUME_DOWN, optionally read the stream type
308+
val volumeStream = if (actionId == ActionId.VOLUME_UP || actionId == ActionId.VOLUME_DOWN) {
309+
entity.extras.getData(ActionEntity.EXTRA_STREAM_TYPE).then {
310+
VOLUME_STREAM_MAP.getKey(it)?.success() ?: null.success()
311+
}.valueOrNull()
312+
} else {
313+
null
314+
}
315+
306316
when (actionId) {
307-
ActionId.VOLUME_UP -> ActionData.Volume.Up(showVolumeUi)
308-
ActionId.VOLUME_DOWN -> ActionData.Volume.Down(showVolumeUi)
317+
ActionId.VOLUME_UP -> ActionData.Volume.Up(showVolumeUi, volumeStream)
318+
ActionId.VOLUME_DOWN -> ActionData.Volume.Down(showVolumeUi, volumeStream)
309319
ActionId.VOLUME_TOGGLE_MUTE -> ActionData.Volume.ToggleMute(
310320
showVolumeUi,
311321
)
@@ -317,10 +327,14 @@ object ActionDataEntityMapper {
317327
}
318328
}
319329

330+
ActionId.MUTE_MICROPHONE -> ActionData.Microphone.Mute
331+
ActionId.UNMUTE_MICROPHONE -> ActionData.Microphone.Unmute
332+
ActionId.TOGGLE_MUTE_MICROPHONE -> ActionData.Microphone.Toggle
333+
320334
ActionId.TOGGLE_FLASHLIGHT,
321335
ActionId.ENABLE_FLASHLIGHT,
322336
ActionId.CHANGE_FLASHLIGHT_STRENGTH,
323-
-> {
337+
-> {
324338
val lens = entity.extras.getData(ActionEntity.EXTRA_LENS).then {
325339
LENS_MAP.getKey(it)!!.success()
326340
}.valueOrNull() ?: return null
@@ -346,7 +360,7 @@ object ActionDataEntityMapper {
346360
}
347361

348362
ActionId.DISABLE_FLASHLIGHT,
349-
-> {
363+
-> {
350364
val lens = entity.extras.getData(ActionEntity.EXTRA_LENS).then {
351365
LENS_MAP.getKey(it)!!.success()
352366
}.valueOrNull() ?: return null
@@ -355,7 +369,7 @@ object ActionDataEntityMapper {
355369

356370
ActionId.TOGGLE_DND_MODE,
357371
ActionId.ENABLE_DND_MODE,
358-
-> {
372+
-> {
359373
val dndMode = entity.extras.getData(ActionEntity.EXTRA_DND_MODE).then {
360374
DND_MODE_MAP.getKey(it)!!.success()
361375
}.valueOrNull() ?: return null
@@ -385,7 +399,7 @@ object ActionDataEntityMapper {
385399
ActionId.STOP_MEDIA_PACKAGE,
386400
ActionId.STEP_FORWARD_PACKAGE,
387401
ActionId.STEP_BACKWARD_PACKAGE,
388-
-> {
402+
-> {
389403
val packageName =
390404
entity.extras.getData(ActionEntity.EXTRA_PACKAGE_NAME).valueOrNull()
391405
?: return null
@@ -730,7 +744,6 @@ object ActionDataEntityMapper {
730744
var flags = 0
731745

732746
val showVolumeUiFlag = when (data) {
733-
is ActionData.Volume.Stream -> data.showVolumeUi
734747
is ActionData.Volume.Up -> data.showVolumeUi
735748
is ActionData.Volume.Down -> data.showVolumeUi
736749
is ActionData.Volume.Mute -> data.showVolumeUi
@@ -915,12 +928,31 @@ object ActionDataEntityMapper {
915928

916929
is ActionData.Volume ->
917930
when (data) {
918-
is ActionData.Volume.Stream -> listOf(
919-
EntityExtra(
920-
ActionEntity.EXTRA_STREAM_TYPE,
921-
VOLUME_STREAM_MAP[data.volumeStream]!!,
922-
),
923-
)
931+
is ActionData.Volume.Up -> buildList {
932+
if (data.volumeStream != null) {
933+
VOLUME_STREAM_MAP[data.volumeStream]?.let { streamValue ->
934+
add(
935+
EntityExtra(
936+
ActionEntity.EXTRA_STREAM_TYPE,
937+
streamValue,
938+
),
939+
)
940+
}
941+
}
942+
}
943+
944+
is ActionData.Volume.Down -> buildList {
945+
if (data.volumeStream != null) {
946+
VOLUME_STREAM_MAP[data.volumeStream]?.let { streamValue ->
947+
add(
948+
EntityExtra(
949+
ActionEntity.EXTRA_STREAM_TYPE,
950+
streamValue,
951+
),
952+
)
953+
}
954+
}
955+
}
924956

925957
else -> emptyList()
926958
}
@@ -1139,6 +1171,9 @@ object ActionDataEntityMapper {
11391171
ActionId.VOLUME_UNMUTE to "volume_unmute",
11401172
ActionId.VOLUME_MUTE to "volume_mute",
11411173
ActionId.VOLUME_TOGGLE_MUTE to "volume_toggle_mute",
1174+
ActionId.MUTE_MICROPHONE to "mute_microphone",
1175+
ActionId.UNMUTE_MICROPHONE to "unmute_microphone",
1176+
ActionId.TOGGLE_MUTE_MICROPHONE to "toggle_mute_microphone",
11421177

11431178
ActionId.EXPAND_NOTIFICATION_DRAWER to "expand_notification_drawer",
11441179
ActionId.TOGGLE_NOTIFICATION_DRAWER to "toggle_notification_drawer",

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ enum class ActionId {
4545
VOLUME_UP,
4646
VOLUME_DOWN,
4747
VOLUME_SHOW_DIALOG,
48+
@Deprecated("Use VOLUME_DOWN with volumeStream parameter instead")
4849
VOLUME_DECREASE_STREAM,
50+
@Deprecated("Use VOLUME_UP with volumeStream parameter instead")
4951
VOLUME_INCREASE_STREAM,
5052
CYCLE_RINGER_MODE,
5153
CHANGE_RINGER_MODE,
@@ -56,6 +58,9 @@ enum class ActionId {
5658
VOLUME_UNMUTE,
5759
VOLUME_MUTE,
5860
VOLUME_TOGGLE_MUTE,
61+
MUTE_MICROPHONE,
62+
UNMUTE_MICROPHONE,
63+
TOGGLE_MUTE_MICROPHONE,
5964

6065
EXPAND_NOTIFICATION_DRAWER,
6166
TOGGLE_NOTIFICATION_DRAWER,

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUiHelper.kt

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ class ActionUiHelper(
6060
}
6161

6262
if (action.device != null) {
63-
val name = if (action.device.name.isBlank()) {
63+
val name = action.device.name.ifBlank {
6464
getString(R.string.unknown_device_name)
65-
} else {
66-
action.device.name
6765
}
6866

6967
val nameToShow = if (showDeviceDescriptors) {
@@ -116,34 +114,20 @@ class ActionUiHelper(
116114
val string: String
117115

118116
when (action) {
119-
is ActionData.Volume.Stream -> {
120-
val streamString = getString(
121-
VolumeStreamStrings.getLabel(action.volumeStream),
122-
)
123-
117+
is ActionData.Volume.Down -> {
124118
if (action.showVolumeUi) {
125119
hasShowVolumeUiFlag = true
126120
}
127121

128-
string = when (action) {
129-
is ActionData.Volume.Stream.Decrease -> getString(
122+
string = if (action.volumeStream != null) {
123+
val streamString = getString(VolumeStreamStrings.getLabel(action.volumeStream))
124+
getString(
130125
R.string.action_decrease_stream_formatted,
131126
streamString,
132127
)
133-
134-
is ActionData.Volume.Stream.Increase -> getString(
135-
R.string.action_increase_stream_formatted,
136-
streamString,
137-
)
138-
}
139-
}
140-
141-
is ActionData.Volume.Down -> {
142-
if (action.showVolumeUi) {
143-
hasShowVolumeUiFlag = true
128+
} else {
129+
getString(R.string.action_volume_down)
144130
}
145-
146-
string = getString(R.string.action_volume_down)
147131
}
148132

149133
is ActionData.Volume.Mute -> {
@@ -175,7 +159,15 @@ class ActionUiHelper(
175159
hasShowVolumeUiFlag = true
176160
}
177161

178-
string = getString(R.string.action_volume_up)
162+
string = if (action.volumeStream != null) {
163+
val streamString = getString(VolumeStreamStrings.getLabel(action.volumeStream))
164+
getString(
165+
R.string.action_increase_stream_formatted,
166+
streamString,
167+
)
168+
} else {
169+
getString(R.string.action_volume_up)
170+
}
179171
}
180172

181173
ActionData.Volume.CycleRingerMode -> {
@@ -603,6 +595,10 @@ class ActionUiHelper(
603595
R.string.action_send_sms_description,
604596
arrayOf(action.message, action.number),
605597
)
598+
599+
ActionData.Microphone.Mute -> getString(R.string.action_mute_microphone)
600+
ActionData.Microphone.Toggle -> getString(R.string.action_toggle_mute_microphone)
601+
ActionData.Microphone.Unmute -> getString(R.string.action_unmute_microphone)
606602
}
607603

608604
fun getIcon(action: ActionData): ComposeIconInfo = when (action) {

0 commit comments

Comments
 (0)