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.
- Volume up/down actions now allow selecting a specific audio stream (e.g., music, notifications) to control, consolidating the functionality of increase/decrease stream actions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot Reword this to something like "consolidated volume and stream actions"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to "Consolidated volume and stream actions." in commit 3a6ac16


## Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,39 @@ sealed class ActionData : Comparable<ActionData> {
}

@Serializable
data class Up(val showVolumeUi: Boolean) : Volume() {
data class Up(

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 Up -> compareValuesBy(
this,
other,
{ it.showVolumeUi },
{ it.volumeStream },
)
else -> super.compareTo(other)
}
}

@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 @@ -303,9 +303,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 @@ -922,6 +931,32 @@ object ActionDataEntityMapper {
),
)

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 @@ -143,7 +143,15 @@ class ActionUiHelper(
hasShowVolumeUiFlag = true
}

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

is ActionData.Volume.Mute -> {
Expand Down Expand Up @@ -175,7 +183,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 @@ -55,6 +55,8 @@ fun HandleActionBottomSheets(delegate: CreateActionDelegate) {
ChangeFlashlightStrengthActionBottomSheet(delegate)
HttpRequestBottomSheet(delegate)
SmsActionBottomSheet(delegate)
VolumeUpActionBottomSheet(delegate)
VolumeDownActionBottomSheet(delegate)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CreateActionDelegate(

var httpRequestBottomSheetState: ActionData.HttpRequest? by mutableStateOf(null)
var smsActionBottomSheetState: SmsActionBottomSheetState? by mutableStateOf(null)
var volumeUpActionState: VolumeActionBottomSheetState? by mutableStateOf(null)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot

Just use the same volumeActionState and store which ActionId is being used. Then use that to figure out which action to create when done is clicked. Also show different bottom sheet title depending on the action.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Consolidated into single volumeActionState with actionId field to determine which action to create. The bottom sheet title now dynamically changes based on the actionId. See commit 3a6ac16

var volumeDownActionState: VolumeActionBottomSheetState? by mutableStateOf(null)

init {
coroutineScope.launch {
Expand Down Expand Up @@ -160,6 +162,30 @@ class CreateActionDelegate(
actionResult.update { action }
}

fun onDoneConfigVolumeUpClick() {
volumeUpActionState?.also { state ->
val action = ActionData.Volume.Up(
showVolumeUi = state.showVolumeUi,
volumeStream = state.volumeStream,
)

volumeUpActionState = null
actionResult.update { action }
}
}

fun onDoneConfigVolumeDownClick() {
volumeDownActionState?.also { state ->
val action = ActionData.Volume.Down(
showVolumeUi = state.showVolumeUi,
volumeStream = state.volumeStream,
)

volumeDownActionState = null
actionResult.update { action }
}
}

fun onTestSmsClick() {
coroutineScope.launch {
(smsActionBottomSheetState as? SmsActionBottomSheetState.SendSms)?.also { state ->
Expand Down Expand Up @@ -263,17 +289,31 @@ class CreateActionDelegate(
return action
}

ActionId.VOLUME_UP,
ActionId.VOLUME_DOWN,
ActionId.VOLUME_UP -> {
val oldVolumeUpData = oldData as? ActionData.Volume.Up
volumeUpActionState = VolumeActionBottomSheetState(
volumeStream = oldVolumeUpData?.volumeStream,
showVolumeUi = oldVolumeUpData?.showVolumeUi ?: false,
)
return null
}

ActionId.VOLUME_DOWN -> {
val oldVolumeDownData = oldData as? ActionData.Volume.Down
volumeDownActionState = VolumeActionBottomSheetState(
volumeStream = oldVolumeDownData?.volumeStream,
showVolumeUi = oldVolumeDownData?.showVolumeUi ?: false,
)
return null
}

ActionId.VOLUME_MUTE,
ActionId.VOLUME_UNMUTE,
ActionId.VOLUME_TOGGLE_MUTE,
-> {
val showVolumeUiId = 0
val isVolumeUiChecked =
when (oldData) {
is ActionData.Volume.Up -> oldData.showVolumeUi
is ActionData.Volume.Down -> oldData.showVolumeUi
is ActionData.Volume.Mute -> oldData.showVolumeUi
is ActionData.Volume.UnMute -> oldData.showVolumeUi
is ActionData.Volume.ToggleMute -> oldData.showVolumeUi
Expand All @@ -295,8 +335,6 @@ class CreateActionDelegate(
val showVolumeUi = chosenFlags.contains(showVolumeUiId)

val action = when (actionId) {
ActionId.VOLUME_UP -> ActionData.Volume.Up(showVolumeUi)
ActionId.VOLUME_DOWN -> ActionData.Volume.Down(showVolumeUi)
ActionId.VOLUME_MUTE -> ActionData.Volume.Mute(showVolumeUi)
ActionId.VOLUME_UNMUTE -> ActionData.Volume.UnMute(showVolumeUi)
ActionId.VOLUME_TOGGLE_MUTE -> ActionData.Volume.ToggleMute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,17 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
}

is ActionData.Volume.Down -> {
result = audioAdapter.lowerVolume(showVolumeUi = action.showVolumeUi)
result = audioAdapter.lowerVolume(
stream = action.volumeStream,
showVolumeUi = action.showVolumeUi,
)
}

is ActionData.Volume.Up -> {
result = audioAdapter.raiseVolume(showVolumeUi = action.showVolumeUi)
result = audioAdapter.raiseVolume(
stream = action.volumeStream,
showVolumeUi = action.showVolumeUi,
)
}

is ActionData.Volume.Mute -> {
Expand Down
Loading
Loading