Skip to content

Commit 39ca2c4

Browse files
Copilotsds100
andcommitted
Delete ActionData.Volume.Stream classes
- Removed deprecated Stream sealed class and Increase/Decrease subclasses - Updated ActionDataEntityMapper to convert old VOLUME_INCREASE_STREAM and VOLUME_DECREASE_STREAM to Volume.Up and Volume.Down with stream parameter - Updated CreateActionDelegate to redirect old stream action IDs to new bottom sheet - Removed all Stream references from PerformActionsUseCase, ActionUiHelper, ConfigActionsUseCase, ActionUtils, and KeyMapActionsComparator - Maintained full backward compatibility - old keymaps with stream actions will be automatically migrated to new format Co-authored-by: sds100 <[email protected]>
1 parent b8f32da commit 39ca2c4

File tree

8 files changed

+28
-117
lines changed

8 files changed

+28
-117
lines changed

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,6 @@ sealed class ActionData : Comparable<ActionData> {
9898

9999
@Serializable
100100
sealed class Volume : ActionData() {
101-
@Deprecated("Use Volume.Up or Volume.Down with volumeStream parameter instead")
102-
sealed class Stream : Volume() {
103-
abstract val volumeStream: VolumeStream
104-
abstract val showVolumeUi: Boolean
105-
106-
override fun compareTo(other: ActionData) = when (other) {
107-
is Stream -> compareValuesBy(
108-
this,
109-
other,
110-
{ it.id },
111-
{ it.volumeStream },
112-
)
113-
114-
else -> super.compareTo(other)
115-
}
116-
117-
@Serializable
118-
data class Increase(
119-
override val showVolumeUi: Boolean,
120-
override val volumeStream: VolumeStream,
121-
) : Stream() {
122-
override val id = ActionId.VOLUME_INCREASE_STREAM
123-
}
124-
125-
@Serializable
126-
data class Decrease(
127-
override val showVolumeUi: Boolean,
128-
override val volumeStream: VolumeStream,
129-
) : Stream() {
130-
override val id = ActionId.VOLUME_DECREASE_STREAM
131-
}
132-
}
133-
134101
@Serializable
135102
data class Up(
136103
val showVolumeUi: Boolean,

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -739,7 +740,6 @@ object ActionDataEntityMapper {
739740
var flags = 0
740741

741742
val showVolumeUiFlag = when (data) {
742-
is ActionData.Volume.Stream -> data.showVolumeUi
743743
is ActionData.Volume.Up -> data.showVolumeUi
744744
is ActionData.Volume.Down -> data.showVolumeUi
745745
is ActionData.Volume.Mute -> data.showVolumeUi
@@ -924,13 +924,6 @@ object ActionDataEntityMapper {
924924

925925
is ActionData.Volume ->
926926
when (data) {
927-
is ActionData.Volume.Stream -> listOf(
928-
EntityExtra(
929-
ActionEntity.EXTRA_STREAM_TYPE,
930-
VOLUME_STREAM_MAP[data.volumeStream]!!,
931-
),
932-
)
933-
934927
is ActionData.Volume.Up -> buildList {
935928
if (data.volumeStream != null) {
936929
VOLUME_STREAM_MAP[data.volumeStream]?.let { streamValue ->

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,6 @@ class ActionUiHelper(
116116
val string: String
117117

118118
when (action) {
119-
is ActionData.Volume.Stream -> {
120-
val streamString = getString(
121-
VolumeStreamStrings.getLabel(action.volumeStream),
122-
)
123-
124-
if (action.showVolumeUi) {
125-
hasShowVolumeUiFlag = true
126-
}
127-
128-
string = when (action) {
129-
is ActionData.Volume.Stream.Decrease -> getString(
130-
R.string.action_decrease_stream_formatted,
131-
streamString,
132-
)
133-
134-
is ActionData.Volume.Stream.Increase -> getString(
135-
R.string.action_increase_stream_formatted,
136-
streamString,
137-
)
138-
}
139-
}
140-
141119
is ActionData.Volume.Down -> {
142120
if (action.showVolumeUi) {
143121
hasShowVolumeUiFlag = true

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,6 @@ fun ActionData.isEditable(): Boolean = when (this) {
896896
is ActionData.Volume.Mute,
897897
is ActionData.Volume.UnMute,
898898
is ActionData.Volume.ToggleMute,
899-
is ActionData.Volume.Stream.Increase,
900-
is ActionData.Volume.Stream.Decrease,
901899
is ActionData.Volume.SetRingerMode,
902900
is ActionData.DoNotDisturb.Enable,
903901
is ActionData.DoNotDisturb.Toggle,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class ConfigActionsUseCaseImpl @Inject constructor(
216216
}
217217
}
218218

219-
if (data is ActionData.Volume.Down || data is ActionData.Volume.Up || data is ActionData.Volume.Stream) {
219+
if (data is ActionData.Volume.Down || data is ActionData.Volume.Up) {
220220
repeat = true
221221
}
222222

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

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -346,45 +346,33 @@ class CreateActionDelegate(
346346
ActionId.VOLUME_INCREASE_STREAM,
347347
ActionId.VOLUME_DECREASE_STREAM,
348348
-> {
349-
val showVolumeUiId = 0
350-
val isVolumeUiChecked = if (oldData is ActionData.Volume.Stream) {
351-
oldData.showVolumeUi
352-
} else {
353-
false
349+
// These deprecated actions are now converted to Volume.Up/Down with stream parameter
350+
// Determine which action ID to use based on the old action
351+
val newActionId = when (actionId) {
352+
ActionId.VOLUME_INCREASE_STREAM -> ActionId.VOLUME_UP
353+
ActionId.VOLUME_DECREASE_STREAM -> ActionId.VOLUME_DOWN
354+
else -> return null
354355
}
355356

356-
val dialogItems = listOf(
357-
MultiChoiceItem(
358-
showVolumeUiId,
359-
getString(R.string.flag_show_volume_dialog),
360-
isVolumeUiChecked,
361-
),
362-
)
363-
364-
val showVolumeUiDialog = DialogModel.MultiChoice(items = dialogItems)
365-
366-
val chosenFlags =
367-
showDialog("show_volume_ui", showVolumeUiDialog) ?: return null
368-
369-
val showVolumeUi = chosenFlags.contains(showVolumeUiId)
370-
371-
val items = VolumeStream.entries
372-
.map { it to getString(VolumeStreamStrings.getLabel(it)) }
373-
374-
val stream = showDialog("pick_volume_stream", DialogModel.SingleChoice(items))
375-
?: return null
376-
377-
val action = when (actionId) {
378-
ActionId.VOLUME_INCREASE_STREAM ->
379-
ActionData.Volume.Stream.Increase(showVolumeUi = showVolumeUi, stream)
380-
381-
ActionId.VOLUME_DECREASE_STREAM ->
382-
ActionData.Volume.Stream.Decrease(showVolumeUi = showVolumeUi, stream)
357+
// Get the old stream if this is being edited
358+
val oldStream = when (oldData) {
359+
is ActionData.Volume.Up -> oldData.volumeStream
360+
is ActionData.Volume.Down -> oldData.volumeStream
361+
else -> null
362+
}
383363

384-
else -> throw Exception("don't know how to create action for $actionId")
364+
val oldShowVolumeUi = when (oldData) {
365+
is ActionData.Volume.Up -> oldData.showVolumeUi
366+
is ActionData.Volume.Down -> oldData.showVolumeUi
367+
else -> false
385368
}
386369

387-
return action
370+
volumeActionState = VolumeActionBottomSheetState(
371+
actionId = newActionId,
372+
volumeStream = oldStream ?: VolumeStream.MUSIC, // Default to MUSIC for old stream actions
373+
showVolumeUi = oldShowVolumeUi,
374+
)
375+
return null
388376
}
389377

390378
ActionId.CHANGE_RINGER_MODE -> {

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,6 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
342342
result = audioAdapter.muteVolume(showVolumeUi = action.showVolumeUi)
343343
}
344344

345-
is ActionData.Volume.Stream.Decrease -> {
346-
result = audioAdapter.lowerVolume(
347-
stream = action.volumeStream,
348-
showVolumeUi = action.showVolumeUi,
349-
)
350-
}
351-
352-
is ActionData.Volume.Stream.Increase -> {
353-
result = audioAdapter.raiseVolume(
354-
stream = action.volumeStream,
355-
showVolumeUi = action.showVolumeUi,
356-
)
357-
}
358-
359345
is ActionData.Volume.ToggleMute -> {
360346
result = audioAdapter.toggleMuteVolume(showVolumeUi = action.showVolumeUi)
361347
}

base/src/main/java/io/github/sds100/keymapper/base/sorting/comparators/KeyMapActionsComparator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class KeyMapActionsComparator(
7070
is ActionData.InputKeyEvent -> Success(action.keyCode.toString())
7171
is ActionData.Sound.SoundFile -> Success(action.soundDescription)
7272
is ActionData.Sound.Ringtone -> Success(action.uri)
73-
is ActionData.Volume.Stream -> Success(action.volumeStream.toString())
73+
is ActionData.Volume.Up -> Success(action.volumeStream?.toString() ?: "")
74+
is ActionData.Volume.Down -> Success(action.volumeStream?.toString() ?: "")
7475
is ActionData.Volume.SetRingerMode -> Success(action.ringerMode.toString())
7576
is ActionData.Flashlight -> Success(action.lens.toString())
7677
is ActionData.SwitchKeyboard -> Success(action.savedImeName)

0 commit comments

Comments
 (0)