feat(core/ui_tweaks): hide suggested friend stories

This commit is contained in:
rhunk
2023-12-09 22:44:24 +01:00
parent 440c35e423
commit af138225f1
3 changed files with 15 additions and 1 deletions

View File

@ -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