Skip to content

Commit 32e511e

Browse files
authored
Merge pull request #1849 from keymapperorg/copilot/action-send-sms
Add SMS actions: Send SMS and Compose SMS
2 parents 9eef520 + f3fc3e6 commit 32e511e

File tree

27 files changed

+857
-84
lines changed

27 files changed

+857
-84
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ktlint_standard_function-expression-body = disabled
33
ktlint_function_naming_ignore_when_annotated_with = Composable
44
ktlint_ignore_back_ticked_identifier = true
55
ktlint_code_style = intellij_idea # Use IntelliJ style because it has trailing commas
6+
ij_kotlin_indent_before_arrow_on_new_line = true
67

78
[base/src/main/java/io/github/sds100/keymapper/base/utils/ui/compose/icons/*.{kt,kts}]
89
ktlint_standard_property-naming = disabled

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- #1773 Option to show floating buttons on top of keyboard or notification panel.
1515
- #1335 Intent API to enable/disable/toggle a key map.
1616
- #114 action to force stop app, and an action to clear an app from recents
17+
- #727 Actions to send SMS messages: "Send SMS" and "Compose SMS"
1718

1819
## Removed
1920

base/src/main/assets/whats-new.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Action to force stop an app or clear it from recents.
44

5+
Action to send SMS message.
6+
57
Enable/disable all the key maps in a group. Intent API to enable/disable/toggle a key map.
68

79
Option to show floating buttons on top of keyboard or notification panel.

base/src/main/java/io/github/sds100/keymapper/base/BaseMainActivity.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ abstract class BaseMainActivity : AppCompatActivity() {
155155
)
156156
super.onCreate(savedInstanceState)
157157

158-
if (viewModel.previousNightMode != currentNightMode) {
159-
resourceProvider.onThemeChange()
160-
}
161-
162158
requestPermissionDelegate = RequestPermissionDelegate(
163159
this,
164160
showDialogs = true,

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,32 @@ sealed class ActionData : Comparable<ActionData> {
557557
}
558558
}
559559

560+
@Serializable
561+
data class SendSms(
562+
val number: String,
563+
val message: String,
564+
) : ActionData() {
565+
override val id = ActionId.SEND_SMS
566+
567+
override fun compareTo(other: ActionData) = when (other) {
568+
is SendSms -> compareValuesBy(this, other, { it.number }, { it.message })
569+
else -> super.compareTo(other)
570+
}
571+
}
572+
573+
@Serializable
574+
data class ComposeSms(
575+
val number: String,
576+
val message: String,
577+
) : ActionData() {
578+
override val id = ActionId.COMPOSE_SMS
579+
580+
override fun compareTo(other: ActionData) = when (other) {
581+
is ComposeSms -> compareValuesBy(this, other, { it.number }, { it.message })
582+
else -> super.compareTo(other)
583+
}
584+
}
585+
560586
@Serializable
561587
data class Url(
562588
val url: String,

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ object ActionDataEntityMapper {
3939
ActionEntity.Type.PINCH_COORDINATE -> ActionId.PINCH_SCREEN
4040
ActionEntity.Type.INTENT -> ActionId.INTENT
4141
ActionEntity.Type.PHONE_CALL -> ActionId.PHONE_CALL
42+
ActionEntity.Type.SEND_SMS -> ActionId.SEND_SMS
43+
ActionEntity.Type.COMPOSE_SMS -> ActionId.COMPOSE_SMS
4244
ActionEntity.Type.SOUND -> ActionId.SOUND
4345
ActionEntity.Type.SYSTEM_ACTION -> {
4446
SYSTEM_ACTION_ID_MAP.getKey(entity.data) ?: return null
@@ -229,6 +231,23 @@ object ActionDataEntityMapper {
229231

230232
ActionId.PHONE_CALL -> ActionData.PhoneCall(number = entity.data)
231233

234+
ActionId.SEND_SMS, ActionId.COMPOSE_SMS -> {
235+
val message = entity.extras.getData(ActionEntity.EXTRA_SMS_MESSAGE)
236+
.valueOrNull() ?: return null
237+
238+
when (actionId) {
239+
ActionId.SEND_SMS -> ActionData.SendSms(
240+
number = entity.data,
241+
message = message,
242+
)
243+
ActionId.COMPOSE_SMS -> ActionData.ComposeSms(
244+
number = entity.data,
245+
message = message,
246+
)
247+
else -> return null
248+
}
249+
}
250+
232251
ActionId.SOUND -> {
233252
val isRingtoneUri = try {
234253
entity.data.toUri().scheme != null
@@ -651,6 +670,8 @@ object ActionDataEntityMapper {
651670
is ActionData.App -> ActionEntity.Type.APP
652671
is ActionData.AppShortcut -> ActionEntity.Type.APP_SHORTCUT
653672
is ActionData.PhoneCall -> ActionEntity.Type.PHONE_CALL
673+
is ActionData.SendSms -> ActionEntity.Type.SEND_SMS
674+
is ActionData.ComposeSms -> ActionEntity.Type.COMPOSE_SMS
654675
is ActionData.TapScreen -> ActionEntity.Type.TAP_COORDINATE
655676
is ActionData.SwipeScreen -> ActionEntity.Type.SWIPE_COORDINATE
656677
is ActionData.PinchScreen -> ActionEntity.Type.PINCH_COORDINATE
@@ -693,6 +714,8 @@ object ActionDataEntityMapper {
693714
is ActionData.App -> data.packageName
694715
is ActionData.AppShortcut -> data.uri
695716
is ActionData.PhoneCall -> data.number
717+
is ActionData.SendSms -> data.number
718+
is ActionData.ComposeSms -> data.number
696719
is ActionData.TapScreen -> "${data.x},${data.y}"
697720
is ActionData.SwipeScreen -> "${data.xStart},${data.yStart},${data.xEnd},${data.yEnd},${data.fingerCount},${data.duration}"
698721
is ActionData.PinchScreen -> "${data.x},${data.y},${data.distance},${data.pinchType},${data.fingerCount},${data.duration}"
@@ -752,6 +775,14 @@ object ActionDataEntityMapper {
752775

753776
is ActionData.PhoneCall -> emptyList()
754777

778+
is ActionData.SendSms -> listOf(
779+
EntityExtra(ActionEntity.EXTRA_SMS_MESSAGE, data.message),
780+
)
781+
782+
is ActionData.ComposeSms -> listOf(
783+
EntityExtra(ActionEntity.EXTRA_SMS_MESSAGE, data.message),
784+
)
785+
755786
is ActionData.DoNotDisturb.Enable -> listOf(
756787
EntityExtra(ActionEntity.EXTRA_DND_MODE, DND_MODE_MAP[data.dndMode]!!),
757788
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ enum class ActionId {
133133

134134
ANSWER_PHONE_CALL,
135135
END_PHONE_CALL,
136+
SEND_SMS,
137+
COMPOSE_SMS,
136138
DEVICE_CONTROLS,
137139

138140
FORCE_STOP_APP,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,15 @@ class ActionUiHelper(
576576

577577
ActionData.ClearRecentApp -> getString(R.string.action_clear_recent_app)
578578
ActionData.ForceStopApp -> getString(R.string.action_force_stop_app)
579+
is ActionData.ComposeSms -> getString(
580+
R.string.action_compose_sms_description,
581+
arrayOf(action.message, action.number)
582+
)
583+
584+
is ActionData.SendSms -> getString(
585+
R.string.action_send_sms_description,
586+
arrayOf(action.message, action.number)
587+
)
579588
}
580589

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

0 commit comments

Comments
 (0)