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

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