From ca84ac7454a426b13ae3bb10c271efbd8c72a6c8 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 9 Oct 2022 00:30:58 +0200 Subject: [PATCH] Added settings item for notifications --- sbapp/main.py | 19 ++++++++++++++----- sbapp/sideband/core.py | 7 ++++--- sbapp/ui/layouts.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index af940a3..2abb798 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -856,6 +856,10 @@ class SidebandApp(MDApp): self.sideband.save_configuration() self.update_ui_theme() + def save_notifications_on(sender=None, event=None): + self.sideband.config["notifications_on"] = self.root.ids.settings_notifications_on.active + self.sideband.save_configuration() + def save_start_announce(sender=None, event=None): self.sideband.config["start_announce"] = self.root.ids.settings_start_announce.active self.sideband.save_configuration() @@ -883,10 +887,9 @@ class SidebandApp(MDApp): interval_text = RNS.prettytime(interval) pre = self.root.ids.settings_lxmf_sync_periodic.text self.root.ids.settings_lxmf_sync_periodic.text = "Auto sync every "+interval_text - if pre != self.root.ids.settings_lxmf_sync_periodic.text: - if save: - self.sideband.config["lxmf_sync_interval"] = interval - self.sideband.save_configuration() + if save: + self.sideband.config["lxmf_sync_interval"] = interval + self.sideband.save_configuration() self.root.ids.settings_lxmf_address.text = RNS.hexrep(self.sideband.lxmf_destination.hash, delimit=False) @@ -903,6 +906,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_notifications_on.active = self.sideband.config["notifications_on"] + self.root.ids.settings_notifications_on.bind(active=save_notifications_on) + self.root.ids.settings_dark_ui.active = self.sideband.config["dark_ui"] self.root.ids.settings_dark_ui.bind(active=save_dark_ui) @@ -916,7 +922,10 @@ class SidebandApp(MDApp): self.root.ids.settings_lxmf_periodic_sync.bind(active=save_lxmf_periodic_sync) save_lxmf_periodic_sync(save=False) - self.root.ids.settings_lxmf_sync_interval.bind(value=sync_interval_change) + def sync_interval_change_cb(sender=None, event=None): + sync_interval_change(sender=sender, event=event, save=False) + self.root.ids.settings_lxmf_sync_interval.bind(value=sync_interval_change_cb) + self.root.ids.settings_lxmf_sync_interval.bind(on_touch_up=sync_interval_change) self.root.ids.settings_lxmf_sync_interval.value = self.sideband.config["lxmf_sync_interval"] sync_interval_change(save=False) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 83642ba..57f8f4a 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -163,6 +163,7 @@ class SidebandCore(): self.config = {} # Settings self.config["display_name"] = "Anonymous Peer" + self.config["settings_notifications_on"] = False self.config["dark_ui"] = False self.config["start_announce"] = False self.config["propagation_by_default"] = False @@ -220,6 +221,8 @@ class SidebandCore(): self.config["lxmf_periodic_sync"] = False if not "lxmf_sync_interval" in self.config: self.config["lxmf_sync_interval"] = 43200 + if not "notifications_on" in self.config: + self.config["notifications_on"] = True # Make sure we have a database if not os.path.isfile(self.db_path): @@ -267,9 +270,7 @@ class SidebandCore(): def notify(self, title, content, group=None, context_id=None): - notifications_enabled = True - - if notifications_enabled: + if self.config["notifications_on"]: if RNS.vendor.platformutils.get_platform() == "android": if self.getpersistent("permissions.notifications"): notifications_permitted = True diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index ccc96ce..0804444 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -840,6 +840,21 @@ MDNavigationLayout: height: self.minimum_height padding: [dp(28), dp(16), dp(28), dp(16)] + MDBoxLayout: + orientation: "horizontal" + size_hint_y: None + padding: [0,0,dp(24),dp(0)] + height: dp(48) + + MDLabel: + text: "Notifications" + font_style: "H6" + + MDSwitch: + id: settings_notifications_on + pos_hint: {"center_y": 0.3} + active: True + MDBoxLayout: orientation: "horizontal" size_hint_y: None