Merged draft screen

This commit is contained in:
shekhar-cis 2022-05-10 15:56:10 +05:30
commit d51faba252
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
2 changed files with 92 additions and 48 deletions

View File

@ -1,41 +1,60 @@
import time
# pylint: disable=unused-argument, import-error, too-many-arguments
# pylint: disable=unnecessary-comprehension, no-member
"""
draft.py
==============
Draft screen
"""
from bitmessagekivy import kivy_helper_search
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute
from functools import partial
from addresses import decodeAddress
import time
import os
from kivy.clock import Clock
from kivy.properties import (
ListProperty,
StringProperty
)
from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel
from bitmessagekivy import kivy_helper_search
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor, mdlist_message_content,
SwipeToDeleteItem, ShowTimeHistoy, empty_screen_label
)
from kivy.app import App
from bitmessagekivy.baseclass.maildetail import MailDetail
from bitmessagekivy.baseclass.draft_widgets import HelperDraft
from bmconfigparser import BMConfigParser
from addresses import decodeAddress
import state
from helper_sql import sqlExecute
import helper_sent
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor,
SwipeToDeleteItem, ShowTimeHistoy
)
from bitmessagekivy.baseclass.maildetail import MailDetail
class Draft(Screen):
class Draft(Screen, HelperDraft):
"""Draft screen class for kivy Ui"""
data = ListProperty()
account = StringProperty()
queryreturn = ListProperty()
has_refreshed = True
label_str = "yet no message for this account!!!!!!!!!!!!!"
def __init__(self, *args, **kwargs):
"""Method used for storing draft messages"""
super(Draft, self).__init__(*args, **kwargs)
if state.association == '':
self.kivy_running_app = App.get_running_app()
self.kivy_state = self.kivy_running_app.kivy_state_obj
if self.kivy_state.association == '':
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
self.kivy_state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
@ -50,27 +69,28 @@ class Draft(Screen):
def loadDraft(self, where="", what=""):
"""Load draft list for Draft messages"""
self.account = state.association
self.account = self.kivy_state.association
xAddress = 'fromaddress'
self.ids.tag_label.text = ''
self.draftDataQuery(xAddress, where, what)
# state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn))
# if state.msg_counter_objs:
# state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn))
if self.queryreturn:
self.ids.tag_label.text = 'Draft'
self.set_draftCnt(state.draft_count)
self.set_draftCnt(self.kivy_state.draft_count)
self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
self.set_draftCnt('0')
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text="yet no message for this account!!!!!!!!!!!!!",
halign='center',
size_hint_y=None,
valign='top')
self.ids.ml.add_widget(content)
# content = MDLabel(
# font_style='Caption',
# theme_text_color='Primary',
# text="yet no message for this account!!!!!!!!!!!!!",
# halign='center',
# size_hint_y=None,
# valign='top')
self.ids.ml.add_widget(empty_screen_label(self.label_str))
def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This methosd is for retrieving draft messages"""
@ -78,7 +98,8 @@ class Draft(Screen):
xAddress, self.account, "draft", where, what,
False, start_indx, end_indx)
def set_draftCnt(self, Count): # pylint: disable=no-self-use
@staticmethod
def set_draftCnt(Count):
"""This method set the count of draft mails"""
draftCnt_obj = state.kivyapp.root.ids.content_drawer.ids.draft_cnt
draftCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count))
@ -87,15 +108,7 @@ class Draft(Screen):
"""This method is used to create mdlist"""
data = []
total_draft_msg = len(self.ids.ml.children)
for mail in self.queryreturn:
third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:10] + '...........' if len(
mail[2]) > 10 else mail[2] + '\n' + " " + (
third_text[:25] + '...!') if len(
third_text) > 25 else third_text,
'ackdata': mail[5], 'senttime': mail[6]})
mdlist_message_content(self.queryreturn,data=data)
for item in data:
message_row = SwipeToDeleteItem(
text='Draft',
@ -104,7 +117,7 @@ class Draft(Screen):
listItem.secondary_text = item["text"]
listItem.theme_text_color = "Custom"
listItem.text_color = ThemeClsColor
message_row.ids.avater_img.source = state.imageDir + '/avatar.png'
message_row.ids.avater_img.source = os.path.join(state.imageDir, 'avatar.png')
listItem.bind(on_release=partial(
self.draft_detail, item['ackdata'], message_row))
message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime']))
@ -130,8 +143,8 @@ class Draft(Screen):
if instance.state == 'closed':
instance.ids.delete_msg.disabled = True
if instance.open_progress == 0.0:
state.detailPageType = 'draft'
state.mail_id = ackdata
self.kivy_state.detailPageType = 'draft'
self.kivy_state.mail_id = ackdata
if self.manager:
src_mng_obj = self.manager
else:
@ -144,11 +157,11 @@ class Draft(Screen):
def delete_draft(self, data_index, instance, *args):
"""Delete draft message permanently"""
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", data_index)
if int(state.draft_count) > 0:
state.draft_count = str(int(state.draft_count) - 1)
self.set_draftCnt(state.draft_count)
if int(state.draft_count) <= 0:
helper_sent.delete(data_index)
if int(self.kivy_state.draft_count) > 0:
self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1)
self.set_draftCnt(self.kivy_state.draft_count)
if int(self.kivy_state.draft_count) <= 0:
# self.ids.identi_tag.children[0].text = ''
self.ids.tag_label.text = ''
self.ids.ml.remove_widget(instance.parent.parent)
@ -190,9 +203,10 @@ class Draft(Screen):
'draft',
encoding,
BMConfigParser().safeGetInt('bitmessagesettings', 'ttl'))
state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1) \
if state.association == fromAddress else state.draft_count
# state.msg_counter_objs = src_object.children[2].children[0].ids
Draft().kivy_state.draft_count = str(int(Draft().kivy_state.draft_count) + 1) \
if state.association == fromAddress else Draft().kivy_state.draft_count
src_object.ids.sc16.clear_widgets()
src_object.ids.sc16.add_widget(Draft())
toast('Save draft')

View File

@ -0,0 +1,30 @@
# pylint: disable=no-member, too-many-arguments
"""
Draft screen widgets are here.
"""
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel
import state
class HelperDraft(object):
"""Widget used in Draft screen are here"""
def __init__(self):
pass
# @staticmethod
# def default_label_when_empty():
# """This function returns default message while no address is there."""
# empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!"
# content = MDLabel(
# font_style='Caption',
# theme_text_color='Primary',
# text=empty_screen_msg,
# halign='center',
# size_hint_y=None,
# valign='top')
# return content