feat: call start confirmation

This commit is contained in:
rhunk
2023-10-28 17:16:45 +02:00
parent fb0180fc9d
commit d350182f15
4 changed files with 64 additions and 0 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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))
}
}
}
}
}

View File

@ -101,6 +101,7 @@ class FeatureManager(
HideStreakRestore::class,
HideFriendFeedEntry::class,
HideQuickAddFriendFeed::class,
CallStartConfirmation::class,
)
initializeFeatures()