commit 261d55461715db5102dffb1b0792d7f37782d011
parent 9574dba861f8a38114a6d13c17374da16713ce32
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 2 Apr 2024 22:35:33 +0200
fix(core/ui): ff info menu
Diffstat:
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/ViewAppearanceHelper.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/ViewAppearanceHelper.kt
@@ -93,6 +93,18 @@ fun View.iterateParent(predicate: (View) -> Boolean) {
}
}
+fun View.findParent(maxIteration: Int = Int.MAX_VALUE, predicate: (View) -> Boolean): View? {
+ var parent = this.parent as? View ?: return null
+ var iteration = 0
+ while (iteration < maxIteration) {
+ if (predicate(parent)) return parent
+ parent = parent.parent as? View ?: return null
+ iteration++
+ }
+ return null
+}
+
+
fun View.getComposerViewNode(): ComposerViewNode? {
if (!this::class.java.isAssignableFrom(SnapEnhance.classCache.composerView)) return null
val composerViewNode = this::class.java.methods.firstOrNull {
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/MenuViewInjector.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/MenuViewInjector.kt
@@ -11,6 +11,7 @@ import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.features.impl.messaging.Messaging
+import me.rhunk.snapenhance.core.ui.findParent
import me.rhunk.snapenhance.core.ui.menu.impl.*
import me.rhunk.snapenhance.core.util.ktx.getIdentifier
import kotlin.reflect.KClass
@@ -45,7 +46,7 @@ class MenuViewInjector : Feature("MenuViewInjector", loadParams = FeatureLoadPar
val actionSheetItemsContainerLayoutId = context.resources.getIdentifier("action_sheet_items_container", "id")
val actionSheetContainer = context.resources.getIdentifier("action_sheet_container", "id")
- val actionMenuHeaderId = context.resources.getIdentifier("action_menu_header", "id")
+ val actionMenuTitle = context.resources.getIdentifier("action_menu_title", "id")
val actionMenu = context.resources.getIdentifier("action_menu", "id")
val componentsHolder = context.resources.getIdentifier("components_holder", "id")
val feedNewChat = context.resources.getIdentifier("feed_new_chat", "id")
@@ -66,14 +67,17 @@ class MenuViewInjector : Feature("MenuViewInjector", loadParams = FeatureLoadPar
val childView: View = event.view
menuMap[OperaContextActionMenu::class]!!.inject(viewGroup, childView, originalAddView)
- if (event.view.id == actionMenuHeaderId) {
- event.parent.post {
- val actionSheetItemsContainer = event.parent.findViewById<ViewGroup>(actionSheetItemsContainerLayoutId) ?: return@post
+ if (event.view.id == actionSheetItemsContainerLayoutId) {
+ event.view.post {
+ if (event.parent.findParent(4) {
+ it.findViewById<View>(actionMenuTitle) != null
+ } == null) return@post
+
val views = mutableListOf<View>()
- menuMap[FriendFeedInfoMenu::class]?.inject(event.parent, actionSheetItemsContainer) {
+ menuMap[FriendFeedInfoMenu::class]?.inject(event.parent, event.view) {
views.add(it)
}
- views.reversed().forEach { actionSheetItemsContainer.addView(it, 0) }
+ views.reversed().forEach { (event.view as ViewGroup).addView(it, 0) }
}
}