commit feee29509d8f5a6e62bce9693a0f97d0f9b9bc90
parent e956400ffebe740dc61ecc5ffa0c47c0c5c90706
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sat, 18 Nov 2023 19:07:35 +0100

feat(core): disable confirmation dialogs

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 12++++++++++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt | 1+
Acore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt | 1+
4 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -408,6 +408,10 @@ "name": "Snapchat Plus", "description": "Enables Snapchat Plus features\nSome Server-sided features may not work" }, + "disable_confirmation_dialogs": { + "name": "Disable Confirmation Dialogs", + "description": "Automatically confirms selected actions" + }, "auto_updater": { "name": "Auto Updater", "description": "Automatically checks for new updates" @@ -738,6 +742,14 @@ "old_bitmoji_selfie": { "2d": "2D Bitmoji", "3d": "3D Bitmoji" + }, + "disable_confirmation_dialogs": { + "remove_friend": "Remove Friend", + "block_friend": "Block Friend", + "ignore_friend": "Ignore Friend", + "hide_friend": "Hide Friend", + "hide_conversation": "Hide Conversation", + "clear_conversation": "Clear Conversation from Friend Feed" } } }, diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt @@ -9,6 +9,7 @@ class Global : ConfigContainer() { } val spoofLocation = container("spoofLocation", SpoofLocation()) val snapchatPlus = boolean("snapchat_plus") { requireRestart() } + val disableConfirmationDialogs = multiple("disable_confirmation_dialogs", "remove_friend", "block_friend", "ignore_friend", "hide_friend", "hide_conversation", "clear_conversation") { requireRestart() } val disableMetrics = boolean("disable_metrics") val blockAds = boolean("block_ads") val bypassVideoLengthRestriction = unique("bypass_video_length_restriction", "split", "single") { addNotices( diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/DisableConfirmationDialogs.kt @@ -0,0 +1,54 @@ +package me.rhunk.snapenhance.core.features.impl.ui + +import android.view.View +import android.widget.TextView +import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent +import me.rhunk.snapenhance.core.features.Feature +import me.rhunk.snapenhance.core.features.FeatureLoadParams +import me.rhunk.snapenhance.core.util.ktx.getId +import me.rhunk.snapenhance.core.util.ktx.getIdentifier +import java.util.regex.Pattern + +class DisableConfirmationDialogs : Feature("Disable Confirmation Dialogs", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { + override fun onActivityCreate() { + val disableConfirmationDialogs = context.config.global.disableConfirmationDialogs.get().takeIf { it.isNotEmpty() } ?: return + val dialogContent = context.resources.getId("dialog_content") + val alertDialogTitle = context.resources.getId("alert_dialog_title") + + val questions = listOf( + "remove_friend" to "action_menu_remove_friend_question", + "block_friend" to "action_menu_block_friend_question", + "ignore_friend" to "action_menu_ignore_friend_question", + "hide_friend" to "action_menu_hide_friend_question", + "hide_conversation" to "hide_or_block_clear_conversation_dialog_title", + "clear_conversation" to "action_menu_clear_conversation_dialog_title" + ).associate { pair -> + pair.first to runCatching { + Pattern.compile( + context.resources.getString(context.resources.getIdentifier(pair.second, "string")) + .split("%s").joinToString(".*") { + Pattern.quote(it) + }, Pattern.CASE_INSENSITIVE) + }.onFailure { + context.log.error("Failed to compile regex for ${pair.second}", it) + }.getOrNull() + } + + context.event.subscribe(AddViewEvent::class) { event -> + if (event.parent.id != dialogContent || !event.view::class.java.name.endsWith("SnapButtonView")) return@subscribe + + val dialogTitle = event.parent.findViewById<TextView>(alertDialogTitle)?.text?.toString() ?: return@subscribe + + questions.forEach { (key, value) -> + if (!disableConfirmationDialogs.contains(key)) return@forEach + + if (value?.matcher(dialogTitle)?.matches() == true) { + event.parent.visibility = View.GONE + event.parent.postDelayed({ + event.view.callOnClick() + }, 400) + } + } + } + } +}+ \ 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 @@ -107,6 +107,7 @@ class FeatureManager( InstantDelete::class, BypassScreenshotDetection::class, HalfSwipeNotifier::class, + DisableConfirmationDialogs::class, ) initializeFeatures()