Refactored views

This commit is contained in:
Mark Qvist 2023-10-22 18:08:28 +02:00
parent 86c8a19cde
commit 20aa3cff1b
2 changed files with 54 additions and 52 deletions

View File

@ -54,7 +54,7 @@ if RNS.vendor.platformutils.get_platform() == "android":
from ui.layouts import * from ui.layouts import *
from ui.conversations import Conversations, MsgSync, NewConv from ui.conversations import Conversations, MsgSync, NewConv
from ui.announces import Announces from ui.announces import Announces
from ui.messages import Messages, ts_format from ui.messages import Messages, ts_format, messages_screen_kv
from ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem from ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem
from jnius import cast from jnius import cast
@ -71,7 +71,7 @@ else:
from .ui.layouts import * from .ui.layouts import *
from .ui.conversations import Conversations, MsgSync, NewConv from .ui.conversations import Conversations, MsgSync, NewConv
from .ui.announces import Announces from .ui.announces import Announces
from .ui.messages import Messages, ts_format from .ui.messages import Messages, ts_format, messages_screen_kv
from .ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem from .ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem
from kivy.config import Config from kivy.config import Config
@ -213,6 +213,13 @@ class SidebandApp(MDApp):
else: else:
self.open_conversations() self.open_conversations()
if not self.root.ids.screen_manager.has_screen("messages_screen"):
# TODO: Remove
RNS.log("Adding messages screen", RNS.LOG_WARNING)
self.messages_screen = Builder.load_string(messages_screen_kv)
self.messages_screen.app = self
self.root.ids.screen_manager.add_widget(self.messages_screen)
self.app_state = SidebandApp.ACTIVE self.app_state = SidebandApp.ACTIVE
self.loading_updater.cancel() self.loading_updater.cancel()
self.final_load_completed = True self.final_load_completed = True
@ -587,7 +594,7 @@ class SidebandApp(MDApp):
if self.root.ids.screen_manager.current == "messages_screen": if self.root.ids.screen_manager.current == "messages_screen":
self.messages_view.update() self.messages_view.update()
if not self.root.ids.messages_scrollview.dest_known: if not self.messages_view.ids.messages_scrollview.dest_known:
self.message_area_detect() self.message_area_detect()
elif self.root.ids.screen_manager.current == "conversations_screen": elif self.root.ids.screen_manager.current == "conversations_screen":
@ -841,23 +848,23 @@ class SidebandApp(MDApp):
self.root.ids.screen_manager.transition.direction = "left" self.root.ids.screen_manager.transition.direction = "left"
self.messages_view = Messages(self, context_dest) self.messages_view = Messages(self, context_dest)
self.root.ids.messages_scrollview.effect_cls = ScrollEffect self.messages_view.ids.messages_scrollview.effect_cls = ScrollEffect
for child in self.root.ids.messages_scrollview.children: for child in self.messages_view.ids.messages_scrollview.children:
self.root.ids.messages_scrollview.remove_widget(child) self.messages_view.ids.messages_scrollview.remove_widget(child)
list_widget = self.messages_view.get_widget() list_widget = self.messages_view.get_widget()
self.root.ids.messages_scrollview.add_widget(list_widget) self.messages_view.ids.messages_scrollview.add_widget(list_widget)
self.root.ids.messages_scrollview.scroll_y = 0.0 self.messages_view.ids.messages_scrollview.scroll_y = 0.0
self.root.ids.messages_toolbar.title = self.sideband.peer_display_name(context_dest) self.messages_view.ids.messages_toolbar.title = self.sideband.peer_display_name(context_dest)
self.root.ids.messages_scrollview.active_conversation = context_dest self.messages_view.ids.messages_scrollview.active_conversation = context_dest
self.sideband.setstate("app.active_conversation", context_dest) self.sideband.setstate("app.active_conversation", context_dest)
self.root.ids.nokeys_text.text = "" self.messages_view.ids.nokeys_text.text = ""
self.message_area_detect() self.message_area_detect()
self.update_message_widgets() self.update_message_widgets()
self.root.ids.message_text.disabled = False self.messages_view.ids.message_text.disabled = False
self.root.ids.screen_manager.current = "messages_screen" self.root.ids.screen_manager.current = "messages_screen"
@ -867,14 +874,14 @@ class SidebandApp(MDApp):
self.sideband.setstate("app.flags.unread_conversations", True) self.sideband.setstate("app.flags.unread_conversations", True)
def scb(dt): def scb(dt):
self.root.ids.messages_scrollview.scroll_y = 0.0 self.messages_view.ids.messages_scrollview.scroll_y = 0.0
Clock.schedule_once(scb, 0.33) Clock.schedule_once(scb, 0.33)
def close_messages_action(self, sender=None): def close_messages_action(self, sender=None):
self.open_conversations(direction="right") self.open_conversations(direction="right")
def message_send_action(self, sender=None): def message_send_action(self, sender=None):
if self.root.ids.message_text.text == "": if self.messages_view.ids.message_text.text == "":
return return
def cb(dt): def cb(dt):
@ -882,7 +889,7 @@ class SidebandApp(MDApp):
Clock.schedule_once(cb, 0.20) Clock.schedule_once(cb, 0.20)
def message_send_dispatch(self, sender=None): def message_send_dispatch(self, sender=None):
self.root.ids.message_send_button.disabled = True self.messages_view.ids.message_send_button.disabled = True
if self.root.ids.screen_manager.current == "messages_screen": if self.root.ids.screen_manager.current == "messages_screen":
if self.outbound_mode_propagation and self.sideband.message_router.get_outbound_propagation_node() == None: if self.outbound_mode_propagation and self.sideband.message_router.get_outbound_propagation_node() == None:
self.messages_view.send_error_dialog = MDDialog( self.messages_view.send_error_dialog = MDDialog(
@ -900,17 +907,17 @@ class SidebandApp(MDApp):
self.messages_view.send_error_dialog.open() self.messages_view.send_error_dialog.open()
else: else:
msg_content = self.root.ids.message_text.text msg_content = self.messages_view.ids.message_text.text
context_dest = self.root.ids.messages_scrollview.active_conversation context_dest = self.messages_view.ids.messages_scrollview.active_conversation
if self.outbound_mode_paper: if self.outbound_mode_paper:
if self.sideband.paper_message(msg_content, context_dest): if self.sideband.paper_message(msg_content, context_dest):
self.root.ids.message_text.text = "" self.messages_view.ids.message_text.text = ""
self.root.ids.messages_scrollview.scroll_y = 0 self.messages_view.ids.messages_scrollview.scroll_y = 0
self.jobs(0) self.jobs(0)
elif self.sideband.send_message(msg_content, context_dest, self.outbound_mode_propagation): elif self.sideband.send_message(msg_content, context_dest, self.outbound_mode_propagation):
self.root.ids.message_text.text = "" self.messages_view.ids.message_text.text = ""
self.root.ids.messages_scrollview.scroll_y = 0 self.messages_view.ids.messages_scrollview.scroll_y = 0
self.jobs(0) self.jobs(0)
else: else:
@ -928,12 +935,12 @@ class SidebandApp(MDApp):
self.messages_view.send_error_dialog.open() self.messages_view.send_error_dialog.open()
def cb(dt): def cb(dt):
self.root.ids.message_send_button.disabled = False self.messages_view.ids.message_send_button.disabled = False
Clock.schedule_once(cb, 0.5) Clock.schedule_once(cb, 0.5)
def peer_show_location_action(self, sender): def peer_show_location_action(self, sender):
if self.root.ids.screen_manager.current == "messages_screen": if self.root.ids.screen_manager.current == "messages_screen":
context_dest = self.root.ids.messages_scrollview.active_conversation context_dest = self.messages_view.ids.messages_scrollview.active_conversation
self.map_show_peer_location(context_dest) self.map_show_peer_location(context_dest)
def message_propagation_action(self, sender): def message_propagation_action(self, sender):
@ -951,43 +958,43 @@ class SidebandApp(MDApp):
self.update_message_widgets() self.update_message_widgets()
def update_message_widgets(self): def update_message_widgets(self):
toolbar_items = self.root.ids.messages_toolbar.ids.right_actions.children toolbar_items = self.messages_view.ids.messages_toolbar.ids.right_actions.children
mode_item = toolbar_items[1] mode_item = toolbar_items[1]
if self.outbound_mode_paper: if self.outbound_mode_paper:
mode_item.icon = "qrcode" mode_item.icon = "qrcode"
self.root.ids.message_text.hint_text = "Paper message" self.messages_view.ids.message_text.hint_text = "Paper message"
else: else:
if not self.outbound_mode_propagation: if not self.outbound_mode_propagation:
mode_item.icon = "lan-connect" mode_item.icon = "lan-connect"
self.root.ids.message_text.hint_text = "Message for direct delivery" self.messages_view.ids.message_text.hint_text = "Message for direct delivery"
else: else:
mode_item.icon = "upload-network" mode_item.icon = "upload-network"
self.root.ids.message_text.hint_text = "Message for propagation" self.messages_view.ids.message_text.hint_text = "Message for propagation"
# self.root.ids.message_text.hint_text = "Write message for delivery via propagation nodes" # self.root.ids.message_text.hint_text = "Write message for delivery via propagation nodes"
def key_query_action(self, sender): def key_query_action(self, sender):
context_dest = self.root.ids.messages_scrollview.active_conversation context_dest = self.messages_view.ids.messages_scrollview.active_conversation
if self.sideband.request_key(context_dest): if self.sideband.request_key(context_dest):
keys_str = "Public key information for "+RNS.prettyhexrep(context_dest)+" was requested from the network. Waiting for request to be answered." keys_str = "Public key information for "+RNS.prettyhexrep(context_dest)+" was requested from the network. Waiting for request to be answered."
self.root.ids.nokeys_text.text = keys_str self.messages_view.ids.nokeys_text.text = keys_str
else: else:
keys_str = "Could not send request. Check your connectivity and addresses." keys_str = "Could not send request. Check your connectivity and addresses."
self.root.ids.nokeys_text.text = keys_str self.messages_view.ids.nokeys_text.text = keys_str
def message_area_detect(self): def message_area_detect(self):
context_dest = self.root.ids.messages_scrollview.active_conversation context_dest = self.messages_view.ids.messages_scrollview.active_conversation
if self.sideband.is_known(context_dest): if self.sideband.is_known(context_dest):
self.root.ids.messages_scrollview.dest_known = True self.messages_view.ids.messages_scrollview.dest_known = True
self.widget_hide(self.root.ids.message_input_part, False) self.widget_hide(self.messages_view.ids.message_input_part, False)
self.widget_hide(self.root.ids.no_keys_part, True) self.widget_hide(self.messages_view.ids.no_keys_part, True)
else: else:
self.root.ids.messages_scrollview.dest_known = False self.messages_view.ids.messages_scrollview.dest_known = False
if self.root.ids.nokeys_text.text == "": if self.messages_view.ids.nokeys_text.text == "":
keys_str = "The crytographic keys for the destination address are unknown at this time. You can wait for an announce to arrive, or query the network for the necessary keys." keys_str = "The crytographic keys for the destination address are unknown at this time. You can wait for an announce to arrive, or query the network for the necessary keys."
self.root.ids.nokeys_text.text = keys_str self.messages_view.ids.nokeys_text.text = keys_str
self.widget_hide(self.root.ids.message_input_part, True) self.widget_hide(self.messages_view.ids.message_input_part, True)
self.widget_hide(self.root.ids.no_keys_part, False) self.widget_hide(self.messages_view.ids.no_keys_part, False)
### Conversations screen ### Conversations screen
@ -3155,7 +3162,7 @@ class SidebandApp(MDApp):
self.location_error_dialog.dismiss() self.location_error_dialog.dismiss()
def map_show(self, location): def map_show(self, location):
if hasattr(self.root.ids.map_layout, "map") and self.root.ids.map_layout.map: if hasattr(self.map_screen.ids.map_layout, "map") and self.map_screen.ids.map_layout.map:
self.map_screen.ids.map_layout.map.lat = location["latitude"] self.map_screen.ids.map_layout.map.lat = location["latitude"]
self.map_screen.ids.map_layout.map.lon = location["longtitude"] self.map_screen.ids.map_layout.map.lon = location["longtitude"]
self.map_screen.ids.map_layout.map.zoom = 16 self.map_screen.ids.map_layout.map.zoom = 16

View File

@ -42,13 +42,8 @@ class Messages():
self.app = app self.app = app
self.context_dest = context_dest self.context_dest = context_dest
if not self.app.root.ids.screen_manager.has_screen("messages_screen"): self.screen = self.app.root.ids.screen_manager.get_screen("messages_screen")
# TODO: Remove
RNS.log("Adding messages screen", RNS.LOG_WARNING)
self.screen = Builder.load_string(messages_screen_kv)
self.screen.app = self.app
self.ids = self.screen.ids self.ids = self.screen.ids
self.app.root.ids.screen_manager.add_widget(self.screen)
self.new_messages = [] self.new_messages = []
self.added_item_hashes = [] self.added_item_hashes = []
@ -286,7 +281,7 @@ class Messages():
def gen_retry(mhash, mcontent, item): def gen_retry(mhash, mcontent, item):
def x(): def x():
self.app.root.ids.message_text.text = mcontent.decode("utf-8") self.app.messages_view.ids.message_text.text = mcontent.decode("utf-8")
self.app.sideband.delete_message(mhash) self.app.sideband.delete_message(mhash)
self.app.message_send_action() self.app.message_send_action()
item.dmenu.dismiss() item.dmenu.dismiss()
@ -603,8 +598,8 @@ MDScreen:
[['menu', lambda x: root.app.nav_drawer.set_state("open")],] [['menu', lambda x: root.app.nav_drawer.set_state("open")],]
right_action_items: right_action_items:
[ [
['map-search', lambda x: root.ids.screen_manager.app.peer_show_location_action(self)], ['map-search', lambda x: root.app.peer_show_location_action(self)],
['lan-connect', lambda x: root.ids.screen_manager.app.message_propagation_action(self)], ['lan-connect', lambda x: root.app.message_propagation_action(self)],
['close', lambda x: root.app.close_settings_action(self)], ['close', lambda x: root.app.close_settings_action(self)],
] ]
@ -628,7 +623,7 @@ MDScreen:
MDRectangleFlatIconButton: MDRectangleFlatIconButton:
icon: "key-wireless" icon: "key-wireless"
text: "Query Network For Keys" text: "Query Network For Keys"
on_release: root.ids.screen_manager.app.key_query_action(self) on_release: root.app.key_query_action(self)
BoxLayout: BoxLayout:
@ -654,7 +649,7 @@ MDScreen:
padding: [dp(10), dp(13), dp(10), dp(14)] padding: [dp(10), dp(13), dp(10), dp(14)]
icon_size: dp(24) icon_size: dp(24)
font_size: dp(16) font_size: dp(16)
on_release: root.ids.screen_manager.app.message_send_action(self) on_release: root.app.message_send_action(self)
""" """
Builder.load_string(""" Builder.load_string("""