commit bb00569cf09f6eafee724cef9e68f7d9737c9140
parent b37d6635ffb06cdaeb439973abeb45e47395953a
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Mon, 22 Jul 2024 22:42:11 +0200

fix(ui/settings_gear): simple Snapchat support

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>

Diffstat:
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/MenuViewInjector.kt | 3++-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/SettingsGearInjector.kt | 16+++++++++-------
2 files changed, 11 insertions(+), 8 deletions(-)

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 @@ -50,6 +50,7 @@ class MenuViewInjector : Feature("MenuViewInjector") { 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") + val hovaNavMapIcon = context.resources.getIdentifier("hova_header_search_icon", "id") val contextMenuButtonIconView = context.resources.getIdentifier("context_menu_button_icon_view", "id") val chatActionMenu = context.resources.getIdentifier("chat_action_menu", "id") @@ -87,7 +88,7 @@ class MenuViewInjector : Feature("MenuViewInjector") { menuMap[OperaViewerIcons::class]!!.inject(viewGroup, childView, originalAddView) } - if (event.parent.id == componentsHolder && childView.id == feedNewChat) { + if (event.parent.id == componentsHolder && (childView.id == feedNewChat || childView.id == hovaNavMapIcon)) { menuMap[SettingsGearInjector::class]!!.inject(viewGroup, childView, originalAddView) return@subscribe } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/SettingsGearInjector.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/SettingsGearInjector.kt @@ -18,21 +18,22 @@ import me.rhunk.snapenhance.core.util.ktx.getStyledAttributes class SettingsGearInjector : AbstractMenu() { override fun inject(parent: ViewGroup, view: View, viewConsumer: (View) -> Unit) { if (context.config.userInterface.hideSettingsGear.get()) return - val firstView = (view as ViewGroup).getChildAt(0) + val hovaNavMapIcon = parent.findViewById<View>(context.resources.getId("hova_nav_map_icon")) + val firstView = hovaNavMapIcon ?: (view as ViewGroup).getChildAt(0) val ngsHovaHeaderSearchIconBackgroundMarginLeft = context.resources.getDimens("ngs_hova_header_search_icon_background_margin_left") - view.clipChildren = false + (view as ViewGroup).clipChildren = false view.addView(FrameLayout(parent.context).apply { visibility = View.GONE post { layoutParams = FrameLayout.LayoutParams(firstView.layoutParams.width, firstView.layoutParams.height).apply { y = 0f - x = if (parent.findViewById<View>(context.resources.getId("hova_nav_map_icon")) != null) { - parent.resources.displayMetrics.widthPixels - firstView.layoutParams.width - ngsHovaHeaderSearchIconBackgroundMarginLeft * 2 - (firstView.layoutParams.width).toFloat() * 2f - } else { - -(ngsHovaHeaderSearchIconBackgroundMarginLeft + firstView.layoutParams.width).toFloat() - } + // TODO: find a better way to calculate the x position with the correct padding when Simple Snapchat is active + x = -(ngsHovaHeaderSearchIconBackgroundMarginLeft + firstView.layoutParams.width).toFloat() + + (hovaNavMapIcon.takeIf { it != null }?.let { + 7 * context.resources.displayMetrics.density + } ?: 0f) } visibility = View.VISIBLE } @@ -66,6 +67,7 @@ class SettingsGearInjector : AbstractMenu() { gravity = android.view.Gravity.CENTER } setImageDrawable(context.resources.getDrawable("svg_settings_32x32", context.theme)) + // TODO: find a better way to tint the icon when Simple Snapchat is active context.resources.getStyledAttributes("headerButtonOpaqueIconTint", context.theme).use { imageTintList = it.getColorStateList(0) }