fix: suspend location updates switch

This commit is contained in:
rhunk
2024-04-16 22:57:49 +02:00
parent 1f54a6295f
commit 40c2662739
5 changed files with 54 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ package me.rhunk.snapenhance.core.event
import android.app.Activity
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
@@ -132,6 +133,30 @@ class EventDispatcher(
}
}
LayoutInflater::class.java.getMethod(
"inflate",
Int::class.java,
ViewGroup::class.java,
Boolean::class.javaPrimitiveType
).hook(HookStage.AFTER) { param ->
val layoutId = param.argNullable<Int>(0) ?: return@hook
val parent = param.argNullable<ViewGroup>(1)
val result = param.getResult() as? View
context.event.post(
LayoutInflateEvent(
layoutId = layoutId,
parent = parent,
view = result
).apply {
adapter = param
}
) {
if (canceled) param.setResult(null)
postHookEvent()
}
}
context.classCache.networkApi.hook("submit", HookStage.BEFORE) { param ->
val request = param.arg<Any>(0)

View File

@@ -0,0 +1,11 @@
package me.rhunk.snapenhance.core.event.events.impl
import android.view.View
import android.view.ViewGroup
import me.rhunk.snapenhance.core.event.events.AbstractHookEvent
class LayoutInflateEvent(
val layoutId: Int,
val parent: ViewGroup?,
val view: View?
) : AbstractHookEvent()

View File

@@ -3,11 +3,12 @@ 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.event.events.impl.LayoutInflateEvent
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.ktx.getId
import me.rhunk.snapenhance.core.util.ktx.getLayoutId
class SuspendLocationUpdates : BridgeFileFeature(
"Suspend Location Updates",
@@ -19,12 +20,15 @@ class SuspendLocationUpdates : BridgeFileFeature(
if (context.config.global.betterLocation.takeIf { it.globalState == true }?.suspendLocationUpdates?.get() != true) return
reload()
val locationSharingSettingsContainerId = context.resources.getId("location_sharing_settings_container")
val locationSharingSettingsContainerId = context.resources.getLayoutId("v3_screen_location_sharing_settings")
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 {
context.event.subscribe(LayoutInflateEvent::class) { event ->
if (event.layoutId != locationSharingSettingsContainerId) return@subscribe
val viewGroup = event.view as? ViewGroup ?: return@subscribe
viewGroup.post {
val container = viewGroup.findViewById<ViewGroup>(recyclerViewContainerId)
container.addView(Switch(event.view.context).apply {
isChecked = isSuspended()
ViewAppearanceHelper.applyTheme(this)
text = this@SuspendLocationUpdates.context.translation["suspend_location_updates.switch_text"]

View File

@@ -2,13 +2,13 @@ package me.rhunk.snapenhance.core.features.impl.ui
import android.content.res.Resources
import android.util.Size
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.widget.FrameLayout
import me.rhunk.snapenhance.common.util.ktx.findFieldsToString
import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent
import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent
import me.rhunk.snapenhance.core.event.events.impl.LayoutInflateEvent
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.util.hook.HookStage
@@ -72,12 +72,9 @@ class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CRE
}
}
LayoutInflater::class.java.hook("inflate", HookStage.AFTER) { param ->
val id = param.args().firstOrNull() as? Int ?: return@hook
val result = param.getResult() as? View ?: return@hook
if (id == getId("chat_input_bar_sharing_drawer_button", "layout") && hiddenElements.contains("hide_live_location_share_button")) {
hideView(result)
context.event.subscribe(LayoutInflateEvent::class) { event ->
if (event.layoutId == getId("chat_input_bar_sharing_drawer_button", "layout") && hiddenElements.contains("hide_live_location_share_button")) {
hideView(event.view ?: return@subscribe)
}
}

View File

@@ -22,9 +22,12 @@ fun Resources.getIdentifier(name: String, type: String): Int {
return getIdentifier(name, type, Constants.SNAPCHAT_PACKAGE_NAME)
}
@SuppressLint("DiscouragedApi")
fun Resources.getId(name: String): Int {
return getIdentifier(name, "id", Constants.SNAPCHAT_PACKAGE_NAME)
return getIdentifier(name, "id")
}
fun Resources.getLayoutId(name: String): Int {
return getIdentifier(name, "layout")
}
fun Resources.getDimens(name: String): Int {