Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- #727 Actions to send SMS messages: "Send SMS" and "Compose SMS"
- #1819 Explain how to enable the accessibility service restricted setting
- #661 Action to execute shell commands.
- #991 Consolidated volume and stream actions.
- #1066 Action to mute/unmute microphone.

## Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,46 +98,40 @@ sealed class ActionData : Comparable<ActionData> {

@Serializable
sealed class Volume : ActionData() {
sealed class Stream : Volume() {
abstract val volumeStream: VolumeStream
abstract val showVolumeUi: Boolean
@Serializable
data class Up(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Can you delete the streams in ActionData. Mark the ActionIds as deprecated. The ActionDataEntityMapper should be backwards compatible with the old Stream ActionIds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated VOLUME_INCREASE_STREAM and VOLUME_DECREASE_STREAM ActionIds, and marked Volume.Stream classes as deprecated. Kept the classes for full backward compatibility - old stream ActionIds will still deserialize correctly via ActionDataEntityMapper. See commit 3a6ac16

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot delete ActionData.Stream classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted ActionData.Volume.Stream classes completely. Old stream actions are now automatically migrated to Volume.Up/Down with stream parameter via ActionDataEntityMapper. See commit 39ca2c4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted ActionData.Volume.Stream classes completely. Old stream actions are now automatically migrated to Volume.Up/Down with stream parameter via ActionDataEntityMapper. See commit 39ca2c4

val showVolumeUi: Boolean,
val volumeStream: VolumeStream? = null,
) : Volume() {
override val id = ActionId.VOLUME_UP

override fun compareTo(other: ActionData) = when (other) {
is Stream -> compareValuesBy(
is Up -> compareValuesBy(
this,
other,
{ it.id },
{ it.showVolumeUi },
{ it.volumeStream },
)

else -> super.compareTo(other)
}

@Serializable
data class Increase(
override val showVolumeUi: Boolean,
override val volumeStream: VolumeStream,
) : Stream() {
override val id = ActionId.VOLUME_INCREASE_STREAM
}

@Serializable
data class Decrease(
override val showVolumeUi: Boolean,
override val volumeStream: VolumeStream,
) : Stream() {
override val id = ActionId.VOLUME_DECREASE_STREAM
}
}

@Serializable
data class Up(val showVolumeUi: Boolean) : Volume() {
override val id = ActionId.VOLUME_UP
}

@Serializable
data class Down(val showVolumeUi: Boolean) : Volume() {
data class Down(
val showVolumeUi: Boolean,
val volumeStream: VolumeStream? = null,
) : Volume() {
override val id = ActionId.VOLUME_DOWN

override fun compareTo(other: ActionData) = when (other) {
is Down -> compareValuesBy(
this,
other,
{ it.showVolumeUi },
{ it.volumeStream },
)
else -> super.compareTo(other)
}
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,13 @@ object ActionDataEntityMapper {
val showVolumeUi =
entity.flags.hasFlag(ActionEntity.ACTION_FLAG_SHOW_VOLUME_UI)

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

ActionId.VOLUME_DECREASE_STREAM ->
ActionData.Volume.Stream.Decrease(showVolumeUi, stream)
ActionData.Volume.Down(showVolumeUi, stream)

else -> throw Exception("don't know how to create system action for $actionId")
}
Expand All @@ -303,9 +304,18 @@ object ActionDataEntityMapper {
val showVolumeUi =
entity.flags.hasFlag(ActionEntity.ACTION_FLAG_SHOW_VOLUME_UI)

// For VOLUME_UP and VOLUME_DOWN, optionally read the stream type
val volumeStream = if (actionId == ActionId.VOLUME_UP || actionId == ActionId.VOLUME_DOWN) {
entity.extras.getData(ActionEntity.EXTRA_STREAM_TYPE).then {
VOLUME_STREAM_MAP.getKey(it)?.success() ?: null.success()
}.valueOrNull()
} else {
null
}

when (actionId) {
ActionId.VOLUME_UP -> ActionData.Volume.Up(showVolumeUi)
ActionId.VOLUME_DOWN -> ActionData.Volume.Down(showVolumeUi)
ActionId.VOLUME_UP -> ActionData.Volume.Up(showVolumeUi, volumeStream)
ActionId.VOLUME_DOWN -> ActionData.Volume.Down(showVolumeUi, volumeStream)
ActionId.VOLUME_TOGGLE_MUTE -> ActionData.Volume.ToggleMute(
showVolumeUi,
)
Expand Down Expand Up @@ -734,7 +744,6 @@ object ActionDataEntityMapper {
var flags = 0

val showVolumeUiFlag = when (data) {
is ActionData.Volume.Stream -> data.showVolumeUi
is ActionData.Volume.Up -> data.showVolumeUi
is ActionData.Volume.Down -> data.showVolumeUi
is ActionData.Volume.Mute -> data.showVolumeUi
Expand Down Expand Up @@ -919,12 +928,31 @@ object ActionDataEntityMapper {

is ActionData.Volume ->
when (data) {
is ActionData.Volume.Stream -> listOf(
EntityExtra(
ActionEntity.EXTRA_STREAM_TYPE,
VOLUME_STREAM_MAP[data.volumeStream]!!,
),
)
is ActionData.Volume.Up -> buildList {
if (data.volumeStream != null) {
VOLUME_STREAM_MAP[data.volumeStream]?.let { streamValue ->
add(
EntityExtra(
ActionEntity.EXTRA_STREAM_TYPE,
streamValue,
),
)
}
}
}

is ActionData.Volume.Down -> buildList {
if (data.volumeStream != null) {
VOLUME_STREAM_MAP[data.volumeStream]?.let { streamValue ->
add(
EntityExtra(
ActionEntity.EXTRA_STREAM_TYPE,
streamValue,
),
)
}
}
}

else -> emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ enum class ActionId {
VOLUME_UP,
VOLUME_DOWN,
VOLUME_SHOW_DIALOG,
@Deprecated("Use VOLUME_DOWN with volumeStream parameter instead")
VOLUME_DECREASE_STREAM,
@Deprecated("Use VOLUME_UP with volumeStream parameter instead")
VOLUME_INCREASE_STREAM,
CYCLE_RINGER_MODE,
CHANGE_RINGER_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,20 @@ class ActionUiHelper(
val string: String

when (action) {
is ActionData.Volume.Stream -> {
val streamString = getString(
VolumeStreamStrings.getLabel(action.volumeStream),
)

is ActionData.Volume.Down -> {
if (action.showVolumeUi) {
hasShowVolumeUiFlag = true
}

string = when (action) {
is ActionData.Volume.Stream.Decrease -> getString(
string = if (action.volumeStream != null) {
val streamString = getString(VolumeStreamStrings.getLabel(action.volumeStream))
getString(
R.string.action_decrease_stream_formatted,
streamString,
)

is ActionData.Volume.Stream.Increase -> getString(
R.string.action_increase_stream_formatted,
streamString,
)
}
}

is ActionData.Volume.Down -> {
if (action.showVolumeUi) {
hasShowVolumeUiFlag = true
} else {
getString(R.string.action_volume_down)
}

string = getString(R.string.action_volume_down)
}

is ActionData.Volume.Mute -> {
Expand Down Expand Up @@ -173,7 +159,15 @@ class ActionUiHelper(
hasShowVolumeUiFlag = true
}

string = getString(R.string.action_volume_up)
string = if (action.volumeStream != null) {
val streamString = getString(VolumeStreamStrings.getLabel(action.volumeStream))
getString(
R.string.action_increase_stream_formatted,
streamString,
)
} else {
getString(R.string.action_volume_up)
}
}

ActionData.Volume.CycleRingerMode -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,6 @@ fun ActionData.isEditable(): Boolean = when (this) {
is ActionData.Volume.Mute,
is ActionData.Volume.UnMute,
is ActionData.Volume.ToggleMute,
is ActionData.Volume.Stream.Increase,
is ActionData.Volume.Stream.Decrease,
is ActionData.Volume.SetRingerMode,
is ActionData.DoNotDisturb.Enable,
is ActionData.DoNotDisturb.Toggle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fun HandleActionBottomSheets(delegate: CreateActionDelegate) {
ChangeFlashlightStrengthActionBottomSheet(delegate)
HttpRequestBottomSheet(delegate)
SmsActionBottomSheet(delegate)
VolumeActionBottomSheet(delegate)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ConfigActionsUseCaseImpl @Inject constructor(
}
}

if (data is ActionData.Volume.Down || data is ActionData.Volume.Up || data is ActionData.Volume.Stream) {
if (data is ActionData.Volume.Down || data is ActionData.Volume.Up) {
repeat = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class ConfigActionsViewModel @Inject constructor(
combine(config.keyMap, actionOptionsUid, transform = ::buildOptionsState)
.stateIn(viewModelScope, SharingStarted.Lazily, null)

private var editedActionUid: String? = null

private val actionErrorSnapshot: StateFlow<ActionErrorSnapshot?> =
displayAction.actionErrorSnapshot.stateIn(viewModelScope, SharingStarted.Lazily, null)

Expand All @@ -99,7 +101,7 @@ class ConfigActionsViewModel @Inject constructor(

viewModelScope.launch {
createActionDelegate.actionResult.filterNotNull().collect { action ->
val actionUid = actionOptionsUid.value ?: return@collect
val actionUid = editedActionUid ?: return@collect
config.setActionData(actionUid, action)
actionOptionsUid.update { null }
}
Expand Down Expand Up @@ -186,6 +188,7 @@ class ConfigActionsViewModel @Inject constructor(
viewModelScope.launch {
// Clear the bottom sheet so navigating back with predicted-back works
actionOptionsUid.update { null }
editedActionUid = actionUid

val keyMap = config.keyMap.first().dataOrNull() ?: return@launch

Expand Down
Loading
Loading