implemented MDCardSwipe for message swipe delete operation

This commit is contained in:
navjot 2021-04-19 17:24:39 +05:30
parent 148d4a1333
commit 4f495961b0
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C
8 changed files with 225 additions and 220 deletions

View File

@ -19,7 +19,7 @@ import state
from bitmessagekivy.baseclass.common import (
AvatarSampleWidget, avatarImageFirstLetter, toast,
ThemeClsColor,
ThemeClsColor, SwipeToDeleteItem
)
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
@ -72,28 +72,20 @@ class AddressBook(Screen):
def set_mdList(self, start_index, end_index):
"""Creating the mdList"""
for item in self.queryreturn[start_index:end_index]:
meny = TwoLineAvatarIconListItem(
text=item[0], secondary_text=item[1], theme_text_color='Custom',
text_color=ThemeClsColor)
meny.add_widget(AvatarSampleWidget(
message_row = SwipeToDeleteItem(
text = item[0],
)
listItem = message_row.ids.content
listItem.secondary_text = item[1]
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
listItem.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(item[0].strip()))))
meny.bind(on_press=partial(
self.addBook_detail, item[1], item[0]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_address, item[1]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
listItem.bind(on_release=partial(
self.addBook_detail, item[1], item[0], message_row))
message_row.ids.delete_msg.bind(on_press=partial(self.delete_address, item[1]))
self.ids.ml.add_widget(message_row)
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
@ -117,8 +109,11 @@ class AddressBook(Screen):
# state.navinstance.ids.sc11.loadAddresslist(None, 'All', '')
# @staticmethod
def addBook_detail(self, address, label, *args):
def addBook_detail(self, address, label, instance, *args):
"""Addressbook details"""
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
obj = AddbookDetailPopup()
self.address_label = obj.address_label = label
self.address = obj.address = address
@ -145,6 +140,8 @@ class AddressBook(Screen):
# self.addbook_popup.set_normal_height()
self.addbook_popup.auto_dismiss = False
self.addbook_popup.open()
else:
instance.ids.delete_msg.disabled = False
def delete_address(self, address, instance, *args):
"""Delete inbox mail from inbox listing"""

View File

@ -18,7 +18,8 @@ import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor,
chipTag, avatarImageFirstLetter, AddTimeWidget, AvatarSampleWidget
chipTag, avatarImageFirstLetter, AddTimeWidget,
AvatarSampleWidget, SwipeToDeleteItem
)
from bitmessagekivy.baseclass.maildetail import MailDetail
from bitmessagekivy.baseclass.trash import Trash
@ -94,36 +95,27 @@ class Allmails(Screen):
for item in self.all_mails:
body = item[3].decode() if isinstance(item[3], bytes) else item[3]
subject = item[2].decode() if isinstance(item[2], bytes) else item[2]
meny = TwoLineAvatarIconListItem(
text=item[1],
secondary_text=(subject[:50] + '........' if len(
message_row = SwipeToDeleteItem(
text = item[1],
)
listItem = message_row.ids.content
secondary_text = (subject[:50] + '........' if len(
subject) >= 50 else (
subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', ''),
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
meny.add_widget(AvatarSampleWidget(
subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', '')
listItem.secondary_text = secondary_text
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
listItem.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(body.strip()))))
meny.bind(on_press=partial(
self.mail_detail, item[5], item[4]))
meny.add_widget(AddTimeWidget(item[7]))
meny.add_widget(chipTag(item[4]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(
listItem.bind(on_release=partial(
self.mail_detail, item[5], item[4], message_row))
listItem.add_widget(AddTimeWidget(item[7]))
listItem.add_widget(chipTag(item[4]))
message_row.ids.delete_msg.bind(on_press=partial(
self.swipe_delete, item[5], item[4]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
self.ids.ml.add_widget(message_row)
updated_data = len(self.ids.ml.children)
self.has_refreshed = True if data_exist != updated_data else False
@ -140,8 +132,11 @@ class Allmails(Screen):
self.allMessageQuery(load_more, 5)
self.set_mdlist()
def mail_detail(self, unique_id, folder, *args):
def mail_detail(self, unique_id, folder, instance, *args):
"""Load sent and inbox mail details"""
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
state.detailPageType = folder
state.is_allmail = True
state.mail_id = unique_id
@ -152,6 +147,8 @@ class Allmails(Screen):
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
else:
instance.ids.delete_msg.disabled = False
def swipe_delete(self, unique_id, folder, instance, *args):
"""Delete inbox mail from all mail listing"""

View File

@ -13,7 +13,12 @@ from kivymd.uix.list import (
from kivy.uix.image import Image
from kivymd.uix.label import MDLabel
from bitmessagekivy.get_platform import platform
from kivymd.uix.card import MDCardSwipe
from kivymd.uix.chip import MDChip
from kivy.properties import (
NumericProperty,
StringProperty
)
ThemeClsColor = [0.12, 0.58, 0.95, 1]
@ -127,3 +132,10 @@ class AvatarSampleWidget(ILeftBody, Image):
class TimeTagRightSampleWidget(IRightBodyTouch, MDLabel):
"""TimeTagRightSampleWidget class for Ui"""
class SwipeToDeleteItem(MDCardSwipe):
text = StringProperty()
# cla = Window.size[0]/2
cla = 800
swipe_distance = NumericProperty(cla)
opening_time = NumericProperty(0.5)

View File

@ -21,7 +21,8 @@ import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor,
AddTimeWidget, AvatarSampleWidget
AddTimeWidget, AvatarSampleWidget,
SwipeToDeleteItem
)
from bitmessagekivy.baseclass.maildetail import MailDetail
@ -101,30 +102,21 @@ class Draft(Screen):
third_text) > 25 else third_text,
'ackdata': mail[5], 'senttime': mail[6]})
for item in data:
meny = TwoLineAvatarIconListItem(
text='Draft', secondary_text=item['text'],
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
meny.add_widget(AvatarSampleWidget(
message_row = SwipeToDeleteItem(
text = 'Draft',
)
listItem = message_row.ids.content
listItem.secondary_text = item["text"]
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
# meny._txt_right_pad = dp(70)
listItem.add_widget(AvatarSampleWidget(
source=state.imageDir + '/avatar.png'))
meny.bind(on_press=partial(
self.draft_detail, item['ackdata']))
meny.add_widget(AddTimeWidget(item['senttime']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_draft, item['ackdata']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
listItem.bind(on_release=partial(
self.draft_detail, item['ackdata'], message_row))
listItem.add_widget(AddTimeWidget(item['senttime']))
message_row.ids.delete_msg.bind(on_press=partial(self.delete_draft, item['ackdata']))
self.ids.ml.add_widget(message_row)
updated_msg = len(self.ids.ml.children)
self.has_refreshed = True if total_draft_msg != updated_msg else False
@ -140,8 +132,11 @@ class Draft(Screen):
self.draftDataQuery('fromaddress', where, what, total_draft_msg, 5)
self.set_mdList()
def draft_detail(self, ackdata, *args):
def draft_detail(self, ackdata, instance, *args):
"""Show draft Details"""
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
state.detailPageType = 'draft'
state.mail_id = ackdata
if self.manager:
@ -151,6 +146,8 @@ class Draft(Screen):
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
else:
instance.ids.delete_msg.disabled = False
def delete_draft(self, data_index, instance, *args):
"""Delete draft message permanently"""

View File

@ -20,7 +20,8 @@ import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, avatarImageFirstLetter,
AddTimeWidget, ThemeClsColor, AvatarSampleWidget, toast
AddTimeWidget, ThemeClsColor, AvatarSampleWidget,
toast, SwipeToDeleteItem
)
from bitmessagekivy.baseclass.maildetail import MailDetail
from bitmessagekivy.baseclass.trash import Trash
@ -122,40 +123,25 @@ class Inbox(Screen):
"""This method is used to create the mdList"""
total_message = len(self.ids.ml.children)
for item in data:
meny = TwoLineAvatarIconListItem(
text=item["text"],
secondary_text=item["secondary_text"],
theme_text_color="Custom",
text_color=ThemeClsColor
message_row = SwipeToDeleteItem(
text = item["text"],
)
meny._txt_right_pad = dp(70)
meny.add_widget(
listItem = message_row.ids.content
listItem.secondary_text = item["secondary_text"]
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
listItem._txt_right_pad = dp(70)
listItem.add_widget(
AvatarSampleWidget(
source=state.imageDir + "/text_images/{}.png".format(
avatarImageFirstLetter(item["secondary_text"].strip())
)
)
)
meny.bind(on_press=partial(self.inbox_detail, item["msgid"]))
meny.add_widget(AddTimeWidget(item["received"]))
carousel = Carousel(direction="right")
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text="Delete")
del_btn.background_normal = ""
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete, item["msgid"]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
# ach_btn = Button(text='Achieve')
# ach_btn.background_color = (0, 1, 0, 1)
# ach_btn.bind(on_press=partial(self.archive, item['msgid']))
# carousel.add_widget(ach_btn)
carousel.index = 1
self.ids.ml.add_widget(carousel)
listItem.bind(on_release=partial(self.inbox_detail, item["msgid"], message_row))
listItem.add_widget(AddTimeWidget(item["received"]))
message_row.ids.delete_msg.bind(on_press=partial(self.delete, item["msgid"]))
self.ids.ml.add_widget(message_row)
update_message = len(self.ids.ml.children)
self.has_refreshed = True if total_message != update_message else False
@ -189,8 +175,11 @@ class Inbox(Screen):
)
self.set_mdList(data)
def inbox_detail(self, msg_id, *args):
def inbox_detail(self, msg_id, instance,*args):
"""Load inbox page details"""
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
state.detailPageType = "inbox"
state.mail_id = msg_id
if self.manager:
@ -200,6 +189,8 @@ class Inbox(Screen):
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = "mailDetail"
else:
instance.ids.delete_msg.disabled = False
def delete(self, data_index, instance, *args):
"""Delete inbox mail from inbox listing"""

View File

@ -19,7 +19,7 @@ import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, ThemeClsColor, avatarImageFirstLetter,
AddTimeWidget, AvatarSampleWidget, toast
AddTimeWidget, AvatarSampleWidget, toast, SwipeToDeleteItem
)
from bitmessagekivy.baseclass.maildetail import MailDetail
@ -96,34 +96,22 @@ class Sent(Screen):
"""This method is used to create the mdList"""
total_sent_msg = len(self.ids.ml.children)
for item in data:
meny = TwoLineAvatarIconListItem(
text=item['text'], secondary_text=item['secondary_text'],
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
meny.add_widget(AvatarSampleWidget(
message_row = SwipeToDeleteItem(
text = item["text"],
)
listItem = message_row.ids.content
listItem.secondary_text = item["secondary_text"]
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
listItem.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial(self.sent_detail, item['ackdata']))
meny.add_widget(AddTimeWidget(item['senttime']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete, item['ackdata']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
# ach_btn = Button(text='Achieve')
# ach_btn.background_color = (0, 1, 0, 1)
# ach_btn.bind(on_press=partial(self.archive, item['ackdata']))
# carousel.add_widget(ach_btn)
carousel.index = 1
self.ids.ml.add_widget(carousel, index=set_index)
listItem.bind(on_release=partial(self.sent_detail, item['ackdata'], message_row))
listItem.add_widget(AddTimeWidget(item['senttime']))
message_row.ids.delete_msg.bind(on_press=partial(self.delete, item["ackdata"]))
self.ids.ml.add_widget(message_row, index=set_index)
updated_msgs = len(self.ids.ml.children)
self.has_refreshed = True if total_sent_msg != updated_msgs else False
@ -195,8 +183,11 @@ class Sent(Screen):
else:
src_mng_obj.ids.badge_txt.text = '0'
def sent_detail(self, ackdata, *args):
def sent_detail(self, ackdata, instance, *args):
"""Load sent mail details"""
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
state.detailPageType = 'sent'
state.mail_id = ackdata
if self.manager:
@ -206,6 +197,8 @@ class Sent(Screen):
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
else:
instance.ids.delete_msg.disabled = False
def delete(self, data_index, instance, *args):
"""Delete sent mail from sent mail listing"""

View File

@ -25,7 +25,7 @@ from bitmessagekivy.baseclass.common import (
from bitmessagekivy.baseclass.common import (
toast, showLimitedCnt, ThemeClsColor, chipTag,
AddTimeWidget, AvatarSampleWidget
AddTimeWidget, AvatarSampleWidget, SwipeToDeleteItem
)
@ -92,36 +92,33 @@ class Trash(Screen):
for item in self.trash_messages:
subject = item[2].decode() if isinstance(item[2], bytes) else item[2]
body = item[3].decode() if isinstance(item[3], bytes) else item[3]
meny = TwoLineAvatarIconListItem(
text=item[1],
secondary_text=(item[2][:50] + '........' if len(
subject) >= 50 else (subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', ''),
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
message_row = SwipeToDeleteItem(
text = item[1],
)
message_row.bind(on_swipe_complete=partial(self.on_swipe_complete, message_row))
listItem = message_row.ids.content
listItem.secondary_text = (item[2][:50] + '........' if len(
subject) >= 50 else (subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', '')
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
# meny._txt_right_pad = dp(70)
img_latter = state.imageDir + '/text_images/{}.png'.format(
subject[0].upper() if (subject[0].upper() >= 'A' and subject[0].upper() <= 'Z') else '!')
meny.add_widget(AvatarSampleWidget(source=img_latter))
meny.add_widget(AddTimeWidget(item[7]))
meny.add_widget(chipTag('inbox 'if 'inbox' in item[4] else 'sent'))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(
listItem.add_widget(AvatarSampleWidget(source=img_latter))
listItem.add_widget(AddTimeWidget(item[7]))
listItem.add_widget(chipTag('inbox 'if 'inbox' in item[4] else 'sent'))
message_row.ids.delete_msg.bind(on_press=partial(
self.delete_permanently, item[5], item[4]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
self.ids.ml.add_widget(message_row)
self.has_refreshed = True if total_trash_msg != len(
self.ids.ml.children) else False
def on_swipe_complete(self, instance, *args):
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
else:
instance.ids.delete_msg.disabled = False
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:

View File

@ -342,3 +342,24 @@ MDNavigationLayout:
on_press: app.root.ids.scr_mngr.current = 'create'
on_press: app.clear_composer()
<SwipeToDeleteItem>:
size_hint_y: None
height: content.height
MDCardSwipeLayerBox:
padding: "8dp"
MDIconButton:
id: delete_msg
icon: "trash-can"
pos_hint: {"center_y": .5}
md_bg_color: (1, 0, 0, 1)
disabled: True
MDCardSwipeFrontBox:
TwoLineAvatarIconListItem:
id: content
text: root.text
_no_ripple_effect: True