From fd7f8dfd769fd050ddd820ebd554a493cbb9d73b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 31 Oct 2023 19:09:04 +0100 Subject: [PATCH] Added improved copy/paste behaviour for fields --- sbapp/main.py | 35 ++++++++++++++++++ sbapp/ui/layouts.py | 82 ++++++++++++++++++++++++------------------- sbapp/ui/telemetry.py | 2 ++ 3 files changed, 83 insertions(+), 36 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 142cc75..742e254 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -895,6 +895,17 @@ class SidebandApp(MDApp): w.saved_attrs = w.height, w.size_hint_y, w.opacity, w.disabled w.height, w.size_hint_y, w.opacity, w.disabled = 0, None, 0, True + def ui_clipboard_action(self, sender=None, event=None): + try: + if len(sender.text) == 0: + sender.text = Clipboard.paste() + else: + Clipboard.copy(sender.text) + action = "tap" if RNS.vendor.platformutils.is_android() else "click" + toast(f"Field copied, double-{action} any empty field to paste") + except Exception as e: + RNS.log("An error occurred while handling clipboard action: "+str(e), RNS.LOG_ERROR) + def quit_action(self, sender): self.root.ids.nav_drawer.set_state("closed") self.sideband.should_persist_data() @@ -1486,15 +1497,36 @@ class SidebandApp(MDApp): return sv + def bind_clipboard_actions(self, ids, force=False): + if force or RNS.vendor.platformutils.is_android(): + BIND_CLASSES = ["kivymd.uix.textfield.textfield.MDTextField",] + for e in ids: + te = ids[e] + ts = str(te).split(" ")[0].replace("<", "") + if ts in BIND_CLASSES and not hasattr(e, "no_clipboard"): + RNS.log("Binding clipboard action to "+str(e)) + te.bind(on_double_tap=self.ui_clipboard_action) + def settings_init(self, sender=None): if not self.settings_ready: if not self.root.ids.screen_manager.has_screen("settings_screen"): self.settings_screen = Builder.load_string(layout_settings_screen) self.settings_screen.app = self self.root.ids.screen_manager.add_widget(self.settings_screen) + self.bind_clipboard_actions(self.settings_screen.ids) self.settings_screen.ids.settings_scrollview.effect_cls = ScrollEffect + info1_text = "\nYou can set your [b]Display Name[/b] to a custom value, or leave it as the default unspecified value. " + info1_text += "This name will be included in any announces you send, and will be visible to others on the network. " + info1_text += "\n\nYou can manually specify which [b]Propagation Node[/b] to use, but if none is specified, Sideband will " + info1_text += "automatically select one nearby." + if RNS.vendor.platformutils.is_android(): + info1_text += "\n\nDouble-tap any field to copy its value, and double-tap an empty field to paste into it." + + self.settings_screen.ids.settings_info1.text = info1_text + + def save_disp_name(sender=None, event=None): if not sender.focus: in_name = self.settings_screen.ids.settings_display_name.text @@ -1717,6 +1749,7 @@ class SidebandApp(MDApp): self.connectivity_screen = Builder.load_string(layout_connectivity_screen) self.connectivity_screen.app = self self.root.ids.screen_manager.add_widget(self.connectivity_screen) + self.bind_clipboard_actions(self.connectivity_screen.ids) self.connectivity_screen.ids.connectivity_scrollview.effect_cls = ScrollEffect def con_hide_settings(): @@ -3047,6 +3080,8 @@ class SidebandApp(MDApp): self.keys_screen = Builder.load_string(layout_keys_screen) self.keys_screen.app = self self.root.ids.screen_manager.add_widget(self.keys_screen) + self.bind_clipboard_actions(self.keys_screen.ids) + self.keys_screen.ids.keys_scrollview.effect_cls = ScrollEffect info = "Your primary encryption keys are stored in a Reticulum Identity within the Sideband app. If you want to backup this Identity for later use on this or another device, you can export it as a plain text blob, with the key data encoded in Base32 format. This will allow you to restore your address in Sideband or other LXMF clients at a later point.\n\n[b]Warning![/b] Anyone that gets access to the key data will be able to control your LXMF address, impersonate you, and read your messages. In is [b]extremely important[/b] that you keep the Identity data secure if you export it.\n\nBefore displaying or exporting your Identity data, make sure that no machine or person in your vicinity is able to see, copy or record your device screen or similar." diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index c050dea..a964ca7 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -1121,7 +1121,6 @@ MDScreen: MDGridLayout: cols: 1 - spacing: dp(16) padding: [dp(28), dp(28), dp(28), dp(28)] size_hint_y: None height: self.minimum_height @@ -1132,13 +1131,18 @@ MDScreen: size_hint_y: None height: self.texture_size[1] - MDBoxLayout: - id: telemetry_information_fields - orientation: "horizontal" + MDLabel: + id: settings_info1 + markup: True + text: "" size_hint_y: None - spacing: dp(16) - height: dp(64) - padding: [0, dp(0), 0, dp(0)] + height: self.texture_size[1] + + MDBoxLayout: + orientation: "vertical" + size_hint_y: None + height: self.minimum_height + padding: [0, dp(24), 0, dp(24)] MDTextField: id: settings_display_name @@ -1147,20 +1151,20 @@ MDScreen: max_text_length: 128 font_size: dp(24) - MDTextField: - id: settings_propagation_node_address - hint_text: "LXMF Propagation Node" - text: "" - max_text_length: 32 - font_size: dp(24) - height: dp(64) + MDTextField: + id: settings_propagation_node_address + hint_text: "LXMF Propagation Node" + text: "" + max_text_length: 32 + font_size: dp(24) + height: dp(64) - MDTextField: - id: settings_print_command - hint_text: "Print Command" - text: "" - font_size: dp(24) - height: dp(64) + MDTextField: + id: settings_print_command + hint_text: "Print Command" + text: "" + font_size: dp(24) + height: dp(64) MDLabel: text: "Address & Identity" @@ -1169,27 +1173,33 @@ MDScreen: height: self.texture_size[1] MDLabel: - id: settings_info1 + id: settings_info2 markup: True - text: "\\nYour address and identity hashes are derived from your primary identity keys, and are therefore not editable, but these fields can be used to view and copy the hashes. If you want a new LXMF address, create or import a new primary identity." + text: "\\nYour address and identity hashes are derived from your primary identity keys, and are therefore not editable, but these fields can be used to view and copy the hashes. If you want a new LXMF address, create or import a new primary identity.\\n" size_hint_y: None height: self.texture_size[1] - MDTextField: - id: settings_lxmf_address - hint_text: "Your LXMF Address" - text: "" - max_text_length: 32 - font_size: dp(24) - height: dp(64) + MDBoxLayout: + orientation: "vertical" + size_hint_y: None + height: self.minimum_height + padding: [0, dp(0), 0, dp(24)] - MDTextField: - id: settings_identity_hash - hint_text: "Your Identity Hash" - text: "" - max_text_length: 32 - font_size: dp(24) - height: dp(64) + MDTextField: + id: settings_lxmf_address + hint_text: "Your LXMF Address" + text: "" + max_text_length: 32 + font_size: dp(24) + height: dp(64) + + MDTextField: + id: settings_identity_hash + hint_text: "Your Identity Hash" + text: "" + max_text_length: 32 + font_size: dp(24) + height: dp(64) MDBoxLayout: orientation: "horizontal" diff --git a/sbapp/ui/telemetry.py b/sbapp/ui/telemetry.py index ce3094c..31f8b24 100644 --- a/sbapp/ui/telemetry.py +++ b/sbapp/ui/telemetry.py @@ -38,6 +38,7 @@ class Telemetry(): self.screen.app = self.app self.screen.delegate = self self.app.root.ids.screen_manager.add_widget(self.screen) + self.app.bind_clipboard_actions(self.screen.ids) self.screen.ids.telemetry_collector.bind(focus=self.telemetry_save) if self.app.sideband.config["telemetry_collector"] == None: @@ -319,6 +320,7 @@ class Telemetry(): self.sensors_screen.app = self.app self.sensors_screen.delegate = self self.app.root.ids.screen_manager.add_widget(self.sensors_screen) + self.bind_clipboard_actions(self.sensors_screen.ids) info3 = "\nTo include a specific type of telemetry data while sending, it must be enabled below. Please note that some sensor types are not supported on all devices. Sideband will only be able to read a specific type of sensor if your device actually includes hardware for it.\n" if self.app.theme_cls.theme_style == "Dark":