From f98acd3ae0667a4945bad3b9733faa082c940f5a Mon Sep 17 00:00:00 2001 From: surbhi Date: Tue, 21 Aug 2018 18:18:16 +0530 Subject: [PATCH] Implementing swipe left to right delete feature for inbox, sent message to be archieved in Kivy --- src/bitmessagekivy/main.kv | 105 ++++++++++++---- src/bitmessagekivy/mpybit.py | 232 ++++++++++++++++++++--------------- 2 files changed, 211 insertions(+), 126 deletions(-) diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 2a06c9fb..ae2e2206 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -1,7 +1,7 @@ #:import la kivy.adapters.listadapter #:import factory kivy.factory #:import mpybit bitmessagekivy.mpybit -#:import ListItemButton kivy.uix.listview.ListItemButton +#:import C kivy.utils.get_color_from_hex : id: nav_drawer @@ -78,63 +78,114 @@ BoxLayout: id:sc9 Button: + id:create height:100 - size_hint_y: 0.2 + size_hint_y: 0.13 size_hint_x: 0.1 pos_hint: {'x': 0.85, 'y': 0.5} background_color: (0,0,0,0) on_press: scr_mngr.current = 'create' Image: source: 'images/plus.png' - y: self.parent.y + y: self.parent.y - 7.5 x: self.parent.x + self.parent.width - 50 size: 70, 70 -: - height: dp(25) - size_hint: (1,.1) - selected_color: 0,0,0,0 - deselected_color: 0,0,0,0 - color: 0, 0,0, 1 +: + text: '' + size_hint_y: None + height: 48 + ignore_perpendicular_swipes: True + data_index: 0 + min_move: 20 / self.width + + on__offset: app.update_index(root.data_index, self.index) + + canvas.before: + Color: + rgba: C('FFFFFF33') + + Rectangle: + pos: self.pos + size: self.size + + Line: + rectangle: self.pos + self.size + + Button: + text: 'delete ({}:{})'.format(root.text, root.data_index) + on_press: app.delete(root.data_index) + + Button: + text: root.text + on_press: app.getInboxMessageDetail(self.text) + + Button: + text: 'archive' + on_press: app.archive(root.data_index) : name: 'inbox' - ScrollView: - id:scrollid - GridLayout: - id: box_share - cols: 1 + RecycleView: + data: root.data + viewclass: 'SwipeButton' + do_scroll_x: False + scroll_timeout: 100 + + RecycleBoxLayout: + id:rc + orientation: 'vertical' size_hint_y: None - spacing: 10 - padding: 10 height: self.minimum_height - canvas: + default_size_hint: 1, None + canvas.before: Color: - rgb: 30,144,255 + rgba: 0,0,0, 1 Rectangle: pos: self.pos size: self.size : name: 'sent' - ScrollView: - id:scrollid - GridLayout: - id: box_share - cols: 1 + RecycleView: + data: root.data + viewclass: 'SwipeButton' + do_scroll_x: False + scroll_timeout: 100 + + RecycleBoxLayout: + id:rc + orientation: 'vertical' size_hint_y: None - spacing: 10 - padding: 10 height: self.minimum_height - canvas: + default_size_hint: 1, None + canvas.before: Color: - rgb: 30,144,255 + rgba: 0,0,0, 1 Rectangle: pos: self.pos size: self.size : name: 'trash' + RecycleView: + data: root.data + viewclass: 'SwipeButton' + do_scroll_x: False + scroll_timeout: 100 + + RecycleBoxLayout: + id:rc + orientation: 'vertical' + size_hint_y: None + height: self.minimum_height + default_size_hint: 1, None + canvas.before: + Color: + rgba: 0,0,0, 1 + Rectangle: + pos: self.pos + size: self.size : name: 'dialog' diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 6b8c3aab..beb9aced 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -25,7 +25,8 @@ from kivy.uix.widget import Widget from bmconfigparser import BMConfigParser from helper_ackPayload import genAckPayload from addresses import decodeAddress, addBMIfNotPresent -from helper_sql import sqlExecute, sqlQuery +from helper_sql import sqlExecute + statusIconColor = 'red' avatarlist = os.listdir("images/ngletteravatar") global belonging @@ -48,10 +49,13 @@ class NavigateApp(App, TextInput): belonging = text main_widget.ids.sc1.clear_widgets() main_widget.ids.sc2.clear_widgets() + main_widget.ids.sc3.clear_widgets() main_widget.ids.sc1.add_widget(Inbox()) main_widget.ids.sc2.add_widget(Sent()) + main_widget.ids.sc3.add_widget(Trash()) Inbox() Sent() + Trash() def say_exit(self): print("**************************EXITING FROM APPLICATION*****************************") @@ -64,6 +68,58 @@ class NavigateApp(App, TextInput): elif name == "values": return BMConfigParser().addresses() + def update_index(self, data_index, index): + if self.root.ids.scr_mngr.current == 'inbox': + self.root.ids.sc1.data[data_index]['index'] = index + elif self.root.ids.scr_mngr.current == 'sent': + self.root.ids.sc2.data[data_index]['index'] = index + elif self.root.ids.scr_mngr.current == 'trash': + self.root.ids.sc3.data[data_index]['index'] = index + + def delete(self, data_index): + print("delete {}".format(data_index)) + self._remove(data_index) + + def archive(self, data_index): + print("archive {}".format(data_index)) + self._remove(data_index) + + def _remove(self, data_index): + if self.root.ids.scr_mngr.current == 'inbox': + self.root.ids.sc1.data.pop(data_index) + self.root.ids.sc1.data = [{ + 'data_index': i, + 'index': d['index'], + 'height': d['height'], + 'text': d['text']} + for i, d in enumerate(self.root.ids.sc1.data) + ] + elif self.root.ids.scr_mngr.current == 'sent': + self.root.ids.sc2.data.pop(data_index) + self.root.ids.sc2.data = [{ + 'data_index': i, + 'index': d['index'], + 'height': d['height'], + 'text': d['text']} + for i, d in enumerate(self.root.ids.sc2.data) + ] + elif self.root.ids.scr_mngr.current == 'trash': + self.root.ids.sc3.data.pop(data_index) + self.root.ids.sc3.data = [{ + 'data_index': i, + 'index': d['index'], + 'height': d['height'], + 'text': d['text']} + for i, d in enumerate(self.root.ids.sc3.data) + ] + + def getInboxMessageDetail(self, instance): + try: + self.root.ids.scr_mngr.current = 'page' + except AttributeError: + self.parent.manager.current = 'page' + print('Message Clicked {}'.format(instance)) + class Navigator(NavigationDrawer): image_source = StringProperty('images/qidenticon_two.png') @@ -71,6 +127,8 @@ class Navigator(NavigationDrawer): class Inbox(Screen): + data = ListProperty() + def __init__(self, *args, **kwargs): super(Inbox, self).__init__(*args, **kwargs) global belonging @@ -81,62 +139,31 @@ class Inbox(Screen): def init_ui(self, dt=0): global belonging self.orientation = "vertical" - self.inboxaccounts(self.ids.box_share) + self.inboxaccounts() - def inboxaccounts(self, box_share): + def inboxaccounts(self): account = belonging folder = 'inbox' - self.loadinboxlist(account, folder, box_share, 'All', '') + self.loadMessagelist(account, folder, 'All', '') - def loadinboxlist(self, account, folder, box_share, where="", what="", unreadOnly=False): - top_logo_share = 1.01 - top_button_share = 1.1 - top_label_share = 1.4 + def loadMessagelist(self, account, folder, where="", what="", unreadOnly=False): xAddress = "toaddress" - queryreturn = kivy_helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly) if queryreturn: - for row in queryreturn: - msgfolder, msgid, toAddress, fromAddress, subject, received, read = row - top_logo_share -= .4 - top_button_share -= .4 - top_label_share -= .4 - logo_share = \ - Image(source='images/ngletteravatar/{}'.format(self.getletterimage(avatarlist, subject)), - pos_hint={"center_x": .05, "top": top_logo_share}, - size_hint_y=None, height=25) - button_share = \ - Button(pos_hint={"x": 0, "top": top_button_share}, - size_hint_y=None, height=40, text=subject, multiline=True, background_color=NavigateApp.theme_cls.primary_dark) - button_share.bind(on_press=self.getInboxMessageDetail) - fl = FloatLayout(size_hint_y=None, height=25) - fl.add_widget(button_share) - fl.add_widget(logo_share) - box_share.add_widget(fl) + self.data = [{ + 'data_index': i, + 'index': 1, + 'height': 48, + 'text': row[4]} + for i, row in enumerate(queryreturn) + ] else: - label_share = \ - Label(text="yet you dont have any emails received", pos_hint={"x": 0, "top": top_label_share}, - size_hint_y=None) - box_share.add_widget(label_share) - - def getletterimage(self, ran, subject): - limit = 5 - for x in subject[:limit]: - if '{}.png'.format(x.lower()) in ran: - return '{}.png'.format(x.lower()) - elif '{}.jpg'.format(x.lower()) in ran: - return '{}.jpg'.format(x.lower()) - if x == limit: - random.shuffle(ran) - return ran[0] - break - - def getInboxMessageDetail(self, instance): - try: - self.manager.current = 'page' - except AttributeError: - self.parent.manager.current = 'page' - print('I am {}'.format(instance.text)) + self.data = [{ + 'data_index': 1, + 'index': 1, + 'height': 48, + 'text': "yet no message for this account!!!!!!!!!!!!!"} + ] class Page(Screen): @@ -148,6 +175,8 @@ class AddressSuccessful(Screen): class Sent(Screen): + data = ListProperty() + def __init__(self, *args, **kwargs): super(Sent, self).__init__(*args, **kwargs) global belonging @@ -158,54 +187,31 @@ class Sent(Screen): def init_ui(self, dt=0): global belonging self.orientation = "vertical" - self.sentaccounts(self.ids.box_share) + self.sentaccounts() - def sentaccounts(self, box_share): + def sentaccounts(self): account = belonging folder = 'inbox' - self.loadSent(account, box_share, 'All', '') + self.loadSent(account, 'All', '') - def loadSent(self, account, box_share, where="", what=""): - top_logo_share = 1.01 - top_button_share = 1.1 - top_label_share = 1.4 + def loadSent(self, account, where="", what=""): xAddress = 'fromaddress' queryreturn = kivy_helper_search.search_sql(xAddress, account, "sent", where, what, False) if queryreturn: - for row in queryreturn: - toAddress, fromAddress, subject, status, ackdata, lastactiontime = row - top_logo_share -= .4 - top_button_share -= .4 - top_label_share -= .4 - logo_share = \ - Image(source='images/ngletteravatar/{}'.format(self.getletterimage(avatarlist, subject)), - pos_hint={"center_x": .05, "top": top_logo_share}, - size_hint_y=None, height=25) - button_share = \ - Button(pos_hint={"x": 0, "top": top_button_share}, - size_hint_y=None, height=40, text=subject, multiline=True, background_color=NavigateApp.theme_cls.primary_dark) - button_share.bind(on_press=self.getSentMessageDetail) - fl = FloatLayout(size_hint_y=None, height=25) - fl.add_widget(button_share) - fl.add_widget(logo_share) - box_share.add_widget(fl) + self.data = [{ + 'data_index': i, + 'index': 1, + 'height': 48, + 'text': row[2]} + for i, row in enumerate(queryreturn) + ] else: - label_share = \ - Label(text="yet you dont have any emails received", pos_hint={"x": 0, "top": top_label_share}, - size_hint_y=None) - box_share.add_widget(label_share) - - def getletterimage(self, ran, subject): - limit = 5 - for x in subject[:limit]: - if '{}.png'.format(x.lower()) in ran: - return '{}.png'.format(x.lower()) - elif '{}.jpg'.format(x.lower()) in ran: - return '{}.jpg'.format(x.lower()) - if x == limit: - random.shuffle(ran) - return ran[0] - break + self.data = [{ + 'data_index': 1, + 'index': 1, + 'height': 48, + 'text': "yet no message for this account!!!!!!!!!!!!!"} + ] def getSentMessageDetail(self, instance): try: @@ -216,16 +222,43 @@ class Sent(Screen): class Trash(Screen): - def __init__(self, **kwargs): - super(Trash, self).__init__(**kwargs) - val_y = .1 - val_z = 0 - my_box1 = BoxLayout(orientation='vertical') - for i in range(1, 5): - my_box1.add_widget(Label(text="I am in trash", size_hint=(.3, .1), pos_hint={ - 'x': val_z, 'top': val_y}, color=(0, 0, 0, 1), background_color=(0, 0, 0, 0))) - val_y += .1 - self.add_widget(my_box1) + data = ListProperty() + + def __init__(self, *args, **kwargs): + super(Trash, self).__init__(*args, **kwargs) + global belonging + if belonging == '': + belonging = Navigator().ids.btn.text + Clock.schedule_once(self.init_ui, 0) + + def init_ui(self, dt=0): + global belonging + self.orientation = "vertical" + self.inboxaccounts() + + def inboxaccounts(self): + account = belonging + folder = 'trash' + self.loadTrashlist(account, folder, 'All', '') + + def loadTrashlist(self, account, folder, where="", what="", unreadOnly=False): + xAddress = "toaddress" + queryreturn = kivy_helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly) + if queryreturn: + self.data = [{ + 'data_index': i, + 'index': 1, + 'height': 48, + 'text': row[4]} + for i, row in enumerate(queryreturn) + ] + else: + self.data = [{ + 'data_index': 1, + 'index': 1, + 'height': 48, + 'text': "yet no message for this account!!!!!!!!!!!!!"} + ] class Dialog(Screen): @@ -309,6 +342,7 @@ class Create(Screen): class NewIdentity(Screen): is_active = BooleanProperty(False) checked = StringProperty("") + # self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png' def generateaddress(self): if self.checked == 'use a random number generator to make an address':