commit d350182f159219d750fe30c58f7a33fa672033be
parent fb0180fc9d0e043399b63e942fbe9eab75f6a547
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sat, 28 Oct 2023 17:16:45 +0200
feat: call start confirmation
Diffstat:
4 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json
@@ -332,6 +332,10 @@
"name": "Message Preview Length",
"description": "Specify the amount of messages to get previewed"
},
+ "call_start_confirmation": {
+ "name": "Call Start Confirmation",
+ "description": "Shows a confirmation dialog when starting a call"
+ },
"prevent_message_sending": {
"name": "Prevent Message Sending",
"description": "Prevents sending certain types of messages"
@@ -785,6 +789,11 @@
"background_option": "Background"
},
+ "call_start_confirmation": {
+ "dialog_title": "Start Call",
+ "dialog_message": "Are you sure you want to start a call?"
+ },
+
"download_processor": {
"attachment_type": {
"snap": "Snap",
diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/MessagingTweaks.kt
@@ -11,6 +11,7 @@ class MessagingTweaks : ConfigContainer() {
val unlimitedSnapViewTime = boolean("unlimited_snap_view_time")
val disableReplayInFF = boolean("disable_replay_in_ff")
val messagePreviewLength = integer("message_preview_length", defaultValue = 20)
+ val callStartConfirmation = boolean("call_start_confirmation") { requireRestart() }
val autoSaveMessagesInConversations = multiple("auto_save_messages_in_conversations",
"CHAT",
"SNAP",
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/CallStartConfirmation.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/messaging/CallStartConfirmation.kt
@@ -0,0 +1,53 @@
+package me.rhunk.snapenhance.core.features.impl.messaging
+
+import android.annotation.SuppressLint
+import android.view.MotionEvent
+import android.view.View
+import me.rhunk.snapenhance.core.features.Feature
+import me.rhunk.snapenhance.core.features.FeatureLoadParams
+import me.rhunk.snapenhance.core.ui.ViewAppearanceHelper
+import me.rhunk.snapenhance.core.util.hook.HookAdapter
+import me.rhunk.snapenhance.core.util.hook.HookStage
+import me.rhunk.snapenhance.core.util.hook.hook
+
+class CallStartConfirmation : Feature("CallStartConfirmation", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
+ private fun hookTouchEvent(param: HookAdapter, motionEvent: MotionEvent, onConfirm: () -> Unit) {
+ if (motionEvent.action != MotionEvent.ACTION_UP) return
+ param.setResult(true)
+ ViewAppearanceHelper.newAlertDialogBuilder(context.mainActivity)
+ .setTitle(context.translation["call_start_confirmation.dialog_title"])
+ .setMessage(context.translation["call_start_confirmation.dialog_message"])
+ .setPositiveButton(context.translation["button.positive"]) { _, _ -> onConfirm() }
+ .setNeutralButton(context.translation["button.negative"]) { _, _ -> }
+ .show()
+ }
+
+ @SuppressLint("DiscouragedApi")
+ override fun onActivityCreate() {
+ if (!context.config.messaging.callStartConfirmation.get()) return
+
+ findClass("com.snap.composer.views.ComposerRootView").hook("dispatchTouchEvent", HookStage.BEFORE) { param ->
+ if (param.thisObject<Any>()::class.java.name != "com.snap.talk.CallButtonsView") return@hook
+ hookTouchEvent(param, param.arg(0)) {
+ param.invokeOriginal()
+ }
+ }
+
+ val callButton1 = context.resources.getIdentifier("friend_action_button3", "id", "com.snapchat.android")
+ val callButton2 = context.resources.getIdentifier("friend_action_button4", "id", "com.snapchat.android")
+
+ findClass("com.snap.ui.view.stackdraw.StackDrawLayout").hook("onTouchEvent", HookStage.BEFORE) { param ->
+ val view = param.thisObject<View>()
+ if (view.id != callButton1 && view.id != callButton2) return@hook
+
+ hookTouchEvent(param, param.arg(0)) {
+ arrayOf(
+ MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0f, 0f, 0),
+ MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0f, 0f, 0)
+ ).forEach {
+ param.invokeOriginal(arrayOf(it))
+ }
+ }
+ }
+ }
+}+
\ No newline at end of file
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt
@@ -101,6 +101,7 @@ class FeatureManager(
HideStreakRestore::class,
HideFriendFeedEntry::class,
HideQuickAddFriendFeed::class,
+ CallStartConfirmation::class,
)
initializeFeatures()