Skip to content

Commit 29200b5

Browse files
committed
#1625 create HTTP request action
1 parent 2ef7e50 commit 29200b5

File tree

20 files changed

+533
-5
lines changed

20 files changed

+533
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## [3.0 Beta 5](https://github.com/sds100/KeyMapper/releases/tag/v3.0.0-beta.5)
22

3-
#### TO BE RELEASED
3+
#### 4 April 2025
4+
5+
- #1625 HTTP Request action.
6+
7+
###
48

59
## Bug fixes
610

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ dependencies {
191191
implementation "org.lsposed.hiddenapibypass:hiddenapibypass:4.3"
192192
proImplementation 'com.revenuecat.purchases:purchases:8.15.0'
193193
proImplementation "com.airbnb.android:lottie-compose:6.6.3"
194+
implementation("com.squareup.okhttp3:okhttp:4.12.0")
194195

195196
// splitties
196197
implementation "com.louiscad.splitties:splitties-bitflags:$splitties_version"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Key Mapper 3.0 is here! 🎉
55
🗂️ Grouping key maps into folders with shared constraints.
66

77
🔦 You can now change the flashlight brightness. Tip: use the constraint for when the flashlight is showing to remap your volume buttons to change the brightness.
8+
🛜 Send HTTP requests with a new action.
89

910
❤️ There are also tonnes of improvements to make your key mapping experience more enjoyable.
1011

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.sds100.keymapper.system.camera.CameraLens
55
import io.github.sds100.keymapper.system.display.Orientation
66
import io.github.sds100.keymapper.system.intents.IntentExtraModel
77
import io.github.sds100.keymapper.system.intents.IntentTarget
8+
import io.github.sds100.keymapper.system.network.HttpMethod
89
import io.github.sds100.keymapper.system.volume.DndMode
910
import io.github.sds100.keymapper.system.volume.RingerMode
1011
import io.github.sds100.keymapper.system.volume.VolumeStream
@@ -828,4 +829,14 @@ sealed class ActionData : Comparable<ActionData> {
828829
object DeviceControls : ActionData() {
829830
override val id: ActionId = ActionId.DEVICE_CONTROLS
830831
}
832+
833+
@Serializable
834+
data class HttpRequest(
835+
val description: String,
836+
val method: HttpMethod,
837+
val url: String,
838+
val body: String,
839+
) : ActionData() {
840+
override val id: ActionId = ActionId.HTTP_REQUEST
841+
}
831842
}

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import io.github.sds100.keymapper.data.entities.getData
88
import io.github.sds100.keymapper.system.camera.CameraLens
99
import io.github.sds100.keymapper.system.intents.IntentExtraModel
1010
import io.github.sds100.keymapper.system.intents.IntentTarget
11+
import io.github.sds100.keymapper.system.network.HttpMethod
1112
import io.github.sds100.keymapper.system.volume.DndMode
1213
import io.github.sds100.keymapper.system.volume.RingerMode
1314
import io.github.sds100.keymapper.system.volume.VolumeStream
1415
import io.github.sds100.keymapper.util.getKey
1516
import io.github.sds100.keymapper.util.success
1617
import io.github.sds100.keymapper.util.then
1718
import io.github.sds100.keymapper.util.valueOrNull
18-
import kotlinx.serialization.encodeToString
1919
import kotlinx.serialization.json.Json
2020
import splitties.bitflags.hasFlag
2121

@@ -496,6 +496,27 @@ object ActionDataEntityMapper {
496496
ActionId.ANSWER_PHONE_CALL -> ActionData.AnswerCall
497497
ActionId.END_PHONE_CALL -> ActionData.EndCall
498498
ActionId.DEVICE_CONTROLS -> ActionData.DeviceControls
499+
ActionId.HTTP_REQUEST -> {
500+
val method = entity.extras.getData(ActionEntity.EXTRA_HTTP_METHOD).then {
501+
HTTP_METHOD_MAP.getKey(it)!!.success()
502+
}.valueOrNull() ?: return null
503+
504+
val description =
505+
entity.extras.getData(ActionEntity.EXTRA_HTTP_DESCRIPTION).valueOrNull()
506+
?: return null
507+
508+
val url = entity.extras.getData(ActionEntity.EXTRA_HTTP_URL).valueOrNull()
509+
?: return null
510+
511+
val body = entity.extras.getData(ActionEntity.EXTRA_HTTP_BODY).valueOrNull() ?: ""
512+
513+
ActionData.HttpRequest(
514+
description = description,
515+
method = method,
516+
url = url,
517+
body = body,
518+
)
519+
}
499520
}
500521
}
501522

@@ -713,6 +734,13 @@ object ActionDataEntityMapper {
713734
EntityExtra(ActionEntity.EXTRA_SOUND_FILE_DESCRIPTION, data.soundDescription),
714735
)
715736

737+
is ActionData.HttpRequest -> listOf(
738+
EntityExtra(ActionEntity.EXTRA_HTTP_DESCRIPTION, data.description),
739+
EntityExtra(ActionEntity.EXTRA_HTTP_METHOD, HTTP_METHOD_MAP[data.method]!!),
740+
EntityExtra(ActionEntity.EXTRA_HTTP_URL, data.url),
741+
EntityExtra(ActionEntity.EXTRA_HTTP_BODY, data.body),
742+
)
743+
716744
else -> emptyList()
717745
}
718746

@@ -750,6 +778,14 @@ object ActionDataEntityMapper {
750778
IntentTarget.SERVICE to "SERVICE",
751779
)
752780

781+
private val HTTP_METHOD_MAP = mapOf(
782+
HttpMethod.GET to "GET",
783+
HttpMethod.POST to "POST",
784+
HttpMethod.PUT to "PUT",
785+
HttpMethod.DELETE to "DELETE",
786+
HttpMethod.PATCH to "PATCH",
787+
)
788+
753789
/**
754790
* DON'T CHANGE THESE
755791
*/
@@ -865,5 +901,6 @@ object ActionDataEntityMapper {
865901
ActionId.ANSWER_PHONE_CALL to "answer_phone_call",
866902
ActionId.END_PHONE_CALL to "end_phone_call",
867903
ActionId.DEVICE_CONTROLS to "device_controls",
904+
ActionId.HTTP_REQUEST to "http_request",
868905
)
869906
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ enum class ActionId {
129129
ANSWER_PHONE_CALL,
130130
END_PHONE_CALL,
131131
DEVICE_CONTROLS,
132+
133+
HTTP_REQUEST,
132134
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ class ActionUiHelper(
528528
ActionData.EndCall -> getString(R.string.action_end_call)
529529

530530
ActionData.DeviceControls -> getString(R.string.action_device_controls)
531+
is ActionData.HttpRequest -> action.description
531532
}
532533

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import androidx.compose.material.icons.outlined.FlashlightOff
3232
import androidx.compose.material.icons.outlined.FlashlightOn
3333
import androidx.compose.material.icons.outlined.Fullscreen
3434
import androidx.compose.material.icons.outlined.Home
35+
import androidx.compose.material.icons.outlined.Http
3536
import androidx.compose.material.icons.outlined.Keyboard
3637
import androidx.compose.material.icons.outlined.KeyboardHide
3738
import androidx.compose.material.icons.outlined.Link
@@ -220,6 +221,7 @@ object ActionUtils {
220221
ActionId.TEXT_PASTE -> ActionCategory.CONTENT
221222
ActionId.SCREENSHOT -> ActionCategory.CONTENT
222223
ActionId.URL -> ActionCategory.CONTENT
224+
ActionId.HTTP_REQUEST -> ActionCategory.CONTENT
223225

224226
ActionId.PHONE_CALL -> ActionCategory.TELEPHONY
225227
ActionId.ANSWER_PHONE_CALL -> ActionCategory.TELEPHONY
@@ -339,6 +341,7 @@ object ActionUtils {
339341
ActionId.ANSWER_PHONE_CALL -> R.string.action_answer_call
340342
ActionId.END_PHONE_CALL -> R.string.action_end_call
341343
ActionId.DEVICE_CONTROLS -> R.string.action_device_controls
344+
ActionId.HTTP_REQUEST -> R.string.action_http_request
342345
}
343346

344347
@DrawableRes
@@ -433,7 +436,6 @@ object ActionUtils {
433436
ActionId.CONSUME_KEY_EVENT -> null
434437
ActionId.OPEN_SETTINGS -> R.drawable.ic_outline_settings_24
435438
ActionId.SHOW_POWER_MENU -> R.drawable.ic_outline_power_settings_new_24
436-
437439
ActionId.APP -> R.drawable.ic_outline_android_24
438440
ActionId.APP_SHORTCUT -> R.drawable.ic_outline_open_in_new_24
439441
ActionId.KEY_CODE -> R.drawable.ic_q_24
@@ -451,6 +453,7 @@ object ActionUtils {
451453
ActionId.ANSWER_PHONE_CALL -> R.drawable.ic_outline_call_24
452454
ActionId.END_PHONE_CALL -> R.drawable.ic_outline_call_end_24
453455
ActionId.DEVICE_CONTROLS -> R.drawable.ic_home_automation
456+
ActionId.HTTP_REQUEST -> null
454457
}
455458

456459
fun getMinApi(id: ActionId): Int = when (id) {
@@ -766,6 +769,7 @@ object ActionUtils {
766769
ActionId.ANSWER_PHONE_CALL -> Icons.Outlined.Call
767770
ActionId.END_PHONE_CALL -> Icons.Outlined.CallEnd
768771
ActionId.DEVICE_CONTROLS -> KeyMapperIcons.HomeIotDevice
772+
ActionId.HTTP_REQUEST -> Icons.Outlined.Http
769773
}
770774
}
771775

@@ -817,6 +821,7 @@ fun ActionData.isEditable(): Boolean = when (this) {
817821
is ActionData.Text,
818822
is ActionData.Url,
819823
is ActionData.PhoneCall,
824+
is ActionData.HttpRequest,
820825
-> true
821826

822827
else -> false

app/src/main/java/io/github/sds100/keymapper/actions/ActionsScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fun ActionsScreen(modifier: Modifier = Modifier, viewModel: ConfigActionsViewMod
6868

6969
EnableFlashlightActionBottomSheet(viewModel.createActionDelegate)
7070
ChangeFlashlightStrengthActionBottomSheet(viewModel.createActionDelegate)
71+
HttpRequestBottomSheet(viewModel.createActionDelegate)
7172

7273
ActionsScreen(
7374
modifier = modifier,

app/src/main/java/io/github/sds100/keymapper/actions/ChooseActionScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fun ChooseActionScreen(
6868

6969
EnableFlashlightActionBottomSheet(viewModel.createActionDelegate)
7070
ChangeFlashlightStrengthActionBottomSheet(viewModel.createActionDelegate)
71+
HttpRequestBottomSheet(viewModel.createActionDelegate)
7172

7273
ChooseActionScreen(
7374
modifier = modifier,

0 commit comments

Comments
 (0)