From 29071fbdfcc8da5d77d8c7d558ae095646103459 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 2 Oct 2022 14:03:56 +0200 Subject: [PATCH] Dark/light mode theme support --- sbapp/main.py | 22 +++++++++++++++++----- sbapp/sideband/core.py | 6 ++++++ sbapp/ui/layouts.py | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 9dd58a0..5fd2c78 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -70,7 +70,6 @@ class SidebandApp(MDApp): self.title = "Sideband" self.app_state = SidebandApp.STARTING self.android_service = None - self.app_dir = plyer.storagepath.get_application_dir() if RNS.vendor.platformutils.get_platform() == "android": @@ -78,8 +77,9 @@ class SidebandApp(MDApp): else: self.sideband = SidebandCore(self, is_client=False) - self.conversations_view = None + self.update_ui_theme() + self.conversations_view = None self.sync_dialog = None Window.softinput_mode = "below_target" @@ -138,6 +138,12 @@ class SidebandApp(MDApp): # General helpers # ################################################# + def update_ui_theme(self): + if self.sideband.config["dark_ui"]: + self.theme_cls.theme_style = "Dark" + else: + self.theme_cls.theme_style = "Light" + def share_text(self, text): if RNS.vendor.platformutils.get_platform() == "android": Intent = autoclass('android.content.Intent') @@ -198,7 +204,6 @@ class SidebandApp(MDApp): def build(self): FONT_PATH = self.sideband.asset_dir+"/fonts" - self.theme_cls.theme_style = "Dark" screen = Builder.load_string(root_layout) return screen @@ -708,6 +713,12 @@ class SidebandApp(MDApp): self.sideband.config["lxmf_propagation_node"] = new_addr self.sideband.set_active_propagation_node(self.sideband.config["lxmf_propagation_node"]) + def save_dark_ui(sender=None, event=None): + RNS.log("Save UI mode") + self.sideband.config["dark_ui"] = self.root.ids.settings_dark_ui.active + self.sideband.save_configuration() + self.update_ui_theme() + def save_start_announce(sender=None, event=None): RNS.log("Save announce") self.sideband.config["start_announce"] = self.root.ids.settings_start_announce.active @@ -738,6 +749,9 @@ class SidebandApp(MDApp): self.root.ids.settings_propagation_node_address.bind(on_text_validate=save_prop_addr) self.root.ids.settings_propagation_node_address.bind(focus=save_prop_addr) + self.root.ids.settings_dark_ui.active = self.sideband.config["dark_ui"] + self.root.ids.settings_dark_ui.bind(active=save_dark_ui) + self.root.ids.settings_start_announce.active = self.sideband.config["start_announce"] self.root.ids.settings_start_announce.bind(active=save_start_announce) @@ -1040,8 +1054,6 @@ If you use Reticulum and LXMF on hardware that does not carry any identifiers ti Thank you very much for using Free Communications Systems. """ - guide_text = "[color=#ddd]"+guide_text+"[/color]" - info = guide_text self.root.ids.guide_info.text = info self.root.ids.guide_info.bind(on_ref_press=link_exec) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index f118536..c2fbbca 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -155,6 +155,7 @@ class SidebandCore(): self.config = {} # Settings self.config["display_name"] = "Anonymous Peer" + self.config["dark_ui"] = True self.config["start_announce"] = False self.config["propagation_by_default"] = False self.config["home_node_as_broadcast_repeater"] = False @@ -199,6 +200,11 @@ class SidebandCore(): self.config = msgpack.unpackb(config_file.read()) config_file.close() + # Migration actions from earlier config formats + if not "dark_ui" in self.config: + self.config["dark_ui"] = True + + # Make sure we have a database if not os.path.isfile(self.db_path): self.__db_init() else: diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index e12f1b3..dc1b76c 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -670,6 +670,20 @@ MDNavigationLayout: id: settings_start_announce active: False + MDBoxLayout: + orientation: "horizontal" + # spacing: "24dp" + size_hint_y: None + height: dp(48) + + MDLabel: + text: "Dark Mode UI" + font_style: "H6" + + MDSwitch: + id: settings_dark_ui + active: False + MDBoxLayout: orientation: "horizontal" # spacing: "24dp"