From e12967efaf8e1c06f4163c0585f99e9b80db9f29 Mon Sep 17 00:00:00 2001 From: Radiquum Date: Wed, 3 Sep 2025 17:15:03 +0500 Subject: [PATCH] feat: [R] bookmark location change patch Fixes #1 --- patches/change_navigation_bar.config.json | 16 +++++++ patches/change_navigation_bar.py | 52 +++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 patches/change_navigation_bar.config.json create mode 100644 patches/change_navigation_bar.py diff --git a/patches/change_navigation_bar.config.json b/patches/change_navigation_bar.config.json new file mode 100644 index 0000000..379e7df --- /dev/null +++ b/patches/change_navigation_bar.config.json @@ -0,0 +1,16 @@ +{ + "portrait": [ + "home", + "discover", + "feed", + "bookmarks", + "profile" + ], + "landscape": [ + "home", + "discover", + "feed", + "bookmarks", + "profile" + ] +} \ No newline at end of file diff --git a/patches/change_navigation_bar.py b/patches/change_navigation_bar.py new file mode 100644 index 0000000..0202cc0 --- /dev/null +++ b/patches/change_navigation_bar.py @@ -0,0 +1,52 @@ +"""Move and replace navigation bar tabs""" + +# patch settings +# priority, default: 0 +priority = 0 + +# imports +## bundled +from typing import TypedDict + +## installed +from lxml import etree + +## custom +from config import config, log + + +# Patch +class PatchConfig_ChangeNavigationBar(TypedDict): + portrait: list[str] + landscape: list[str] + + +allowed_items = ["home", "discover", "feed", "bookmarks", "profile"] + + +def modify_menu(menu: list[str], path: str) -> None: + for item in menu: + if item not in allowed_items: + log.warning(f"menu item `{item}` is not allowed, removing from list") + menu.remove(item) + + root = etree.Element("menu", nsmap={"android": config['xml_ns']['android']}) + for item in menu: + element = etree.SubElement(root, "item") + element.set(f"{{{config['xml_ns']['android']}}}icon", f"@drawable/nav_{item}") + element.set(f"{{{config['xml_ns']['android']}}}id", f"@id/tab_{item}") + element.set(f"{{{config['xml_ns']['android']}}}title", f"@string/{item}") + + tree = etree.ElementTree(root) + tree.write( + path, + pretty_print=True, + xml_declaration=True, + encoding="utf-8", + ) + + +def apply(patch_conf: PatchConfig_ChangeNavigationBar) -> bool: + modify_menu(patch_conf["portrait"], f"{config['folders']['decompiled']}/res/menu/bottom.xml") + modify_menu(patch_conf["landscape"], f"{config['folders']['decompiled']}/res/menu/navigation_rail_menu.xml") + return True