commit cc94ea93b27398a0ef17b1d6e259f525a2d796ae
parent 47e9a0e0b1b8f78e50feed8f1ae077324d48a2bb
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 20 Dec 2023 23:45:12 +0100

feat: suspend location updates

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 8++++++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/bridge/types/BridgeFileType.kt | 3++-
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Global.kt | 1+
Acore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/SuspendLocationUpdates.kt | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt | 1+
5 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -453,6 +453,10 @@ } } }, + "suspend_location_updates": { + "name": "Suspend Location Updates", + "description": "Adds a button in map settings to suspend location updates" + }, "snapchat_plus": { "name": "Snapchat Plus", "description": "Enables Snapchat Plus features\nSome Server-sided features may not work" @@ -1030,5 +1034,9 @@ "streaks_reminder": { "notification_title": "Streaks", "notification_text": "You will lose your Streak with {friend} in {hoursLeft} hours" + }, + + "suspend_location_updates": { + "switch_text": "Suspend Location Updates" } } \ No newline at end of file diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/types/BridgeFileType.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/types/BridgeFileType.kt @@ -8,7 +8,8 @@ enum class BridgeFileType(val value: Int, val fileName: String, val displayName: CONFIG(0, "config.json", "Config"), MAPPINGS(1, "mappings.json", "Mappings"), MESSAGE_LOGGER_DATABASE(2, "message_logger.db", "Message Logger",true), - PINNED_CONVERSATIONS(3, "pinned_conversations.txt", "Pinned Conversations"); + PINNED_CONVERSATIONS(3, "pinned_conversations.txt", "Pinned Conversations"), + SUSPEND_LOCATION_STATE(4, "suspend_location_state.txt", "Suspend Location State"); fun resolve(context: Context): File = if (isDatabase) { context.getDatabasePath(fileName) 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 @@ -8,6 +8,7 @@ class Global : ConfigContainer() { val coordinates = mapCoordinates("coordinates", 0.0 to 0.0) { requireRestart()} // lat, long } val spoofLocation = container("spoofLocation", SpoofLocation()) + val suspendLocationUpdates = boolean("suspend_location_updates") { requireRestart() } 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") diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/SuspendLocationUpdates.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/global/SuspendLocationUpdates.kt @@ -0,0 +1,56 @@ +package me.rhunk.snapenhance.core.features.impl.global + +import android.view.ViewGroup +import android.widget.Switch +import me.rhunk.snapenhance.common.bridge.types.BridgeFileType +import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent +import me.rhunk.snapenhance.core.features.BridgeFileFeature +import me.rhunk.snapenhance.core.features.FeatureLoadParams +import me.rhunk.snapenhance.core.ui.ViewAppearanceHelper +import me.rhunk.snapenhance.core.util.hook.HookStage +import me.rhunk.snapenhance.core.util.hook.hook +import me.rhunk.snapenhance.core.util.ktx.getId + +//TODO: bridge shared preferences +class SuspendLocationUpdates : BridgeFileFeature( + "Suspend Location Updates", + loadParams = FeatureLoadParams.INIT_SYNC or FeatureLoadParams.ACTIVITY_CREATE_SYNC, + bridgeFileType = BridgeFileType.SUSPEND_LOCATION_STATE +) { + private val isEnabled get() = context.config.global.suspendLocationUpdates.get() + override fun init() { + if (!isEnabled) return + reload() + + context.classCache.unifiedGrpcService.hook("bidiStreamingCall", HookStage.BEFORE) { param -> + val uri = param.arg<String>(0) + if (uri == "/snapchat.valis.Valis/Communicate" && exists("true")) { + param.setResult(null) + } + } + } + + override fun onActivityCreate() { + if (!isEnabled) return + + val locationSharingSettingsContainerId = context.resources.getId("location_sharing_settings_container") + val recyclerViewContainerId = context.resources.getId("recycler_view_container") + + context.event.subscribe(AddViewEvent::class) { event -> + if (event.parent.id == locationSharingSettingsContainerId && event.view.id == recyclerViewContainerId) { + (event.view as ViewGroup).addView(Switch(event.view.context).apply { + isChecked = exists("true") + ViewAppearanceHelper.applyTheme(this) + text = this@SuspendLocationUpdates.context.translation["suspend_location_updates.switch_text"] + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + setOnCheckedChangeListener { _, isChecked -> + setState("true", isChecked) + } + }) + } + } + } +}+ \ 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 @@ -115,6 +115,7 @@ class FeatureManager( FideliusIndicator::class, EditTextOverride::class, PreventForcedLogout::class, + SuspendLocationUpdates::class, ) initializeFeatures()