commit af138225f13159b86430fc92a489889b83c27427
parent 440c35e4230efd610ba19d9a38e098f75b799b7d
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sat,  9 Dec 2023 22:44:24 +0100

feat(core/ui_tweaks): hide suggested friend stories

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 1+
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/UITweaks.kt | 13+++++++++++++
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -761,6 +761,7 @@ }, "hide_story_sections": { "hide_friend_suggestions": "Hide friend suggestions", + "hide_suggested_friend_stories": "Hide suggested friend stories", "hide_friends": "Hide friends section", "hide_suggested": "Hide suggested section", "hide_for_you": "Hide For You section" diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt @@ -35,7 +35,7 @@ class UserInterfaceTweaks : ConfigContainer() { val hideStreakRestore = boolean("hide_streak_restore") { requireRestart() } val hideQuickAddFriendFeed = boolean("hide_quick_add_friend_feed") { requireRestart() } val hideStorySections = multiple("hide_story_sections", - "hide_friend_suggestions", "hide_friends", "hide_suggested", "hide_for_you") { requireRestart() } + "hide_friend_suggestions", "hide_suggested_friend_stories", "hide_friends", "hide_suggested", "hide_for_you") { requireRestart() } val hideUiComponents = multiple("hide_ui_components", "hide_voice_record_button", "hide_stickers_button", diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/UITweaks.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/UITweaks.kt @@ -7,7 +7,9 @@ import android.text.SpannableString 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.features.Feature import me.rhunk.snapenhance.core.features.FeatureLoadParams import me.rhunk.snapenhance.core.util.hook.HookStage @@ -51,6 +53,7 @@ class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CRE val chatNoteRecordButton = getId("chat_note_record_button", "id") val unreadHintButton = getId("unread_hint_button", "id") + val friendCardFrame = getId("friend_card_frame", "id") View::class.java.hook("setVisibility", HookStage.BEFORE) { methodParam -> val viewId = (methodParam.thisObject() as View).id @@ -71,6 +74,16 @@ class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CRE } } + context.event.subscribe(BindViewEvent::class, { hideStorySections.contains("hide_suggested_friend_stories") }) { event -> + if (event.view.id != friendCardFrame) return@subscribe + + val friendStoryData = event.prevModel::class.java.findFieldsToString(event.prevModel, once = true) { _, value -> + value.contains("FriendStoryData") + }.firstOrNull()?.get(event.prevModel) ?: return@subscribe + + event.view.visibility = if (friendStoryData.toString().contains("isFriendOfFriend=true")) View.GONE else View.VISIBLE + } + context.event.subscribe(AddViewEvent::class) { event -> val viewId = event.view.id val view = event.view