mirror of
https://github.com/liberatedsystems/Sideband_CE.git
synced 2024-09-03 04:13:27 +02:00
Improved announce stream UI performance
This commit is contained in:
parent
783f0d573a
commit
715d4e27a4
@ -149,6 +149,10 @@ class SidebandApp(MDApp):
|
|||||||
else:
|
else:
|
||||||
self.sideband.start()
|
self.sideband.start()
|
||||||
|
|
||||||
|
# Pre-load announce stream widgets
|
||||||
|
self.init_announces_view()
|
||||||
|
self.announces_view.update()
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# General helpers #
|
# General helpers #
|
||||||
@ -245,6 +249,8 @@ class SidebandApp(MDApp):
|
|||||||
else:
|
else:
|
||||||
self.icon = self.sideband.asset_dir+"/icon.png"
|
self.icon = self.sideband.asset_dir+"/icon.png"
|
||||||
|
|
||||||
|
self.announces_view = None
|
||||||
|
|
||||||
screen = Builder.load_string(root_layout)
|
screen = Builder.load_string(root_layout)
|
||||||
|
|
||||||
return screen
|
return screen
|
||||||
@ -304,6 +310,8 @@ class SidebandApp(MDApp):
|
|||||||
|
|
||||||
self.root.ids.screen_manager.app = self
|
self.root.ids.screen_manager.app = self
|
||||||
self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__
|
self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__
|
||||||
|
self.root.ids.screen_manager.transition.duration = 0.25
|
||||||
|
self.root.ids.screen_manager.transition.bind(on_complete=self.screen_transition_complete)
|
||||||
|
|
||||||
Clock.schedule_once(self.start_core, 3.5)
|
Clock.schedule_once(self.start_core, 3.5)
|
||||||
|
|
||||||
@ -958,20 +966,23 @@ class SidebandApp(MDApp):
|
|||||||
|
|
||||||
### Announce Stream screen
|
### Announce Stream screen
|
||||||
######################################
|
######################################
|
||||||
|
def init_announces_view(self, sender=None):
|
||||||
|
if not self.announces_view:
|
||||||
|
self.announces_view = Announces(self)
|
||||||
|
self.sideband.setstate("app.flags.new_announces", True)
|
||||||
|
|
||||||
|
for child in self.root.ids.announces_scrollview.children:
|
||||||
|
self.root.ids.announces_scrollview.remove_widget(child)
|
||||||
|
|
||||||
|
self.root.ids.announces_scrollview.add_widget(self.announces_view.get_widget())
|
||||||
|
|
||||||
def announces_action(self, sender=None):
|
def announces_action(self, sender=None):
|
||||||
self.root.ids.screen_manager.transition.direction = "left"
|
self.root.ids.screen_manager.transition.direction = "left"
|
||||||
self.root.ids.nav_drawer.set_state("closed")
|
self.root.ids.nav_drawer.set_state("closed")
|
||||||
self.announces_view = Announces(self)
|
|
||||||
|
if self.sideband.getstate("app.flags.new_announces"):
|
||||||
|
self.init_announces_view()
|
||||||
# info = "The [b]Announce Stream[/b] feature is not yet implemented in Sideband.\n\nWant it faster? Go to [u][ref=link]https://unsigned.io/sideband[/ref][/u] to support the project."
|
self.announces_view.update()
|
||||||
# self.root.ids.announces_info.text = info
|
|
||||||
# self.root.ids.announces_info.bind(on_ref_press=link_exec)
|
|
||||||
|
|
||||||
for child in self.root.ids.announces_scrollview.children:
|
|
||||||
self.root.ids.announces_scrollview.remove_widget(child)
|
|
||||||
|
|
||||||
self.root.ids.announces_scrollview.add_widget(self.announces_view.get_widget())
|
|
||||||
|
|
||||||
self.root.ids.screen_manager.current = "announces_screen"
|
self.root.ids.screen_manager.current = "announces_screen"
|
||||||
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
|
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
|
||||||
@ -982,6 +993,9 @@ class SidebandApp(MDApp):
|
|||||||
def announce_filter_action(self, sender=None):
|
def announce_filter_action(self, sender=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def screen_transition_complete(self, sender):
|
||||||
|
if self.root.ids.screen_manager.current == "announces_screen":
|
||||||
|
pass
|
||||||
|
|
||||||
### Keys screen
|
### Keys screen
|
||||||
######################################
|
######################################
|
||||||
|
@ -622,18 +622,22 @@ class SidebandCore():
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
announces = []
|
announces = []
|
||||||
|
added_dests = []
|
||||||
for entry in result:
|
for entry in result:
|
||||||
try:
|
try:
|
||||||
announce = {
|
if not entry[2] in added_dests:
|
||||||
"dest": entry[2],
|
announce = {
|
||||||
"data": entry[3].decode("utf-8"),
|
"dest": entry[2],
|
||||||
"time": entry[1],
|
"data": entry[3].decode("utf-8"),
|
||||||
"type": entry[4]
|
"time": entry[1],
|
||||||
}
|
"type": entry[4]
|
||||||
announces.append(announce)
|
}
|
||||||
|
added_dests.append(entry[2])
|
||||||
|
announces.append(announce)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Exception while fetching announce from DB: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Exception while fetching announce from DB: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
announces.reverse()
|
||||||
return announces
|
return announces
|
||||||
|
|
||||||
def _db_conversation(self, context_dest):
|
def _db_conversation(self, context_dest):
|
||||||
@ -855,6 +859,9 @@ class SidebandCore():
|
|||||||
db = sqlite3.connect(self.db_path)
|
db = sqlite3.connect(self.db_path)
|
||||||
dbc = db.cursor()
|
dbc = db.cursor()
|
||||||
|
|
||||||
|
query = "delete from announce where (source=:source);"
|
||||||
|
dbc.execute(query, {"source": destination_hash})
|
||||||
|
|
||||||
query = "INSERT INTO announce (received, source, data, dest_type) values (?, ?, ?, ?)"
|
query = "INSERT INTO announce (received, source, data, dest_type) values (?, ?, ?, ?)"
|
||||||
data = (
|
data = (
|
||||||
time.time(),
|
time.time(),
|
||||||
|
@ -23,7 +23,12 @@ class Announces():
|
|||||||
self.context_dests = []
|
self.context_dests = []
|
||||||
self.added_item_dests = []
|
self.added_item_dests = []
|
||||||
self.list = None
|
self.list = None
|
||||||
self.update()
|
self.fetch_announces()
|
||||||
|
self.list = MDList()
|
||||||
|
# self.update()
|
||||||
|
|
||||||
|
def fetch_announces(self):
|
||||||
|
self.announces = self.app.sideband.list_announces()
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
self.clear_list()
|
self.clear_list()
|
||||||
@ -37,15 +42,31 @@ class Announces():
|
|||||||
self.added_item_dests = []
|
self.added_item_dests = []
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.clear_list()
|
self.fetch_announces()
|
||||||
self.announces = self.app.sideband.list_announces()
|
|
||||||
self.update_widget()
|
self.update_widget()
|
||||||
self.app.sideband.setstate("app.flags.new_announces", False)
|
self.app.sideband.setstate("app.flags.new_announces", False)
|
||||||
|
|
||||||
def update_widget(self):
|
def update_widget(self):
|
||||||
if self.list == None:
|
if self.list == None:
|
||||||
self.list = MDList()
|
self.list = MDList()
|
||||||
|
|
||||||
|
remove_widgets = []
|
||||||
|
for item in self.list.children:
|
||||||
|
if not item.sb_uid in (a["dest"] for a in self.announces):
|
||||||
|
remove_widgets.append(item)
|
||||||
|
|
||||||
|
else:
|
||||||
|
for announce in self.announces:
|
||||||
|
if announce["dest"] == item.sb_uid:
|
||||||
|
if announce["time"] > item.ts:
|
||||||
|
remove_widgets.append(item)
|
||||||
|
break
|
||||||
|
|
||||||
|
for item in remove_widgets:
|
||||||
|
if item.sb_uid in self.added_item_dests:
|
||||||
|
self.added_item_dests.remove(item.sb_uid)
|
||||||
|
self.list.remove_widget(item)
|
||||||
|
|
||||||
for announce in self.announces:
|
for announce in self.announces:
|
||||||
context_dest = announce["dest"]
|
context_dest = announce["dest"]
|
||||||
ts = announce["time"]
|
ts = announce["time"]
|
||||||
@ -100,6 +121,7 @@ class Announces():
|
|||||||
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data, dest_type))
|
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data, dest_type))
|
||||||
item.add_widget(iconl)
|
item.add_widget(iconl)
|
||||||
item.sb_uid = context_dest
|
item.sb_uid = context_dest
|
||||||
|
item.ts = ts
|
||||||
|
|
||||||
def gen_del(dest, item):
|
def gen_del(dest, item):
|
||||||
def x():
|
def x():
|
||||||
@ -191,7 +213,7 @@ class Announces():
|
|||||||
item.add_widget(item.iconr)
|
item.add_widget(item.iconr)
|
||||||
|
|
||||||
self.added_item_dests.append(context_dest)
|
self.added_item_dests.append(context_dest)
|
||||||
self.list.add_widget(item)
|
self.list.add_widget(item, index=len(self.list.children))
|
||||||
|
|
||||||
def get_widget(self):
|
def get_widget(self):
|
||||||
return self.list
|
return self.list
|
Loading…
Reference in New Issue
Block a user