commit 7c5658b0da1110b29f10a96917d088334bdab17f
parent 9817843c0e59da499633b8c1c585296d5adaa840
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Tue, 27 Aug 2024 14:54:22 +0200

feat(better_location): battery level in map focus view

Diffstat:
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/BetterLocation.kt @@ -26,8 +26,10 @@ import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.util.RandomWalking +import me.rhunk.snapenhance.core.util.dataBuilder import me.rhunk.snapenhance.core.util.hook.HookStage import me.rhunk.snapenhance.core.util.hook.hook +import me.rhunk.snapenhance.core.util.hook.hookConstructor import me.rhunk.snapenhance.core.util.ktx.getId import me.rhunk.snapenhance.core.util.ktx.getObjectField import me.rhunk.snapenhance.core.util.ktx.isDarkTheme @@ -191,6 +193,17 @@ class BetterLocation : Feature("Better Location") { val batteryLevel = locationHistory[userId]?.batteryLevel?.takeIf { it > -1F } ?: return@hook param.setArg(0, param.arg<String>(0) + " (${(batteryLevel * 100).toInt()}%)") } + + findClass("com.snap.map_friend_focus_view.MapFocusViewFriendSectionDataModel").hookConstructor(HookStage.AFTER) { param -> + val instance = param.thisObject<Any>() + val userId = instance.getObjectField("_userId") as? String ?: return@hookConstructor + val batteryLevel = locationHistory[userId]?.batteryLevel?.takeIf { it > -1F } ?: return@hookConstructor + + param.thisObject<Any>().dataBuilder { + val prevText = get<String?>("_lastSeen")?.let { " - $it" } ?: "" + set("_lastSeen", "(${(batteryLevel * 100).toInt()}%)$prevText") + } + } } context.event.subscribe(AddViewEvent::class) { event ->