Merged draft screen
This commit is contained in:
commit
d51faba252
|
@ -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 functools import partial
|
||||||
from addresses import decodeAddress
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from kivy.properties import (
|
from kivy.properties import (
|
||||||
ListProperty,
|
ListProperty,
|
||||||
StringProperty
|
StringProperty
|
||||||
)
|
)
|
||||||
from kivy.uix.screenmanager import Screen
|
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
|
import state
|
||||||
|
from helper_sql import sqlExecute
|
||||||
|
import helper_sent
|
||||||
|
|
||||||
from bitmessagekivy.baseclass.common import (
|
class Draft(Screen, HelperDraft):
|
||||||
showLimitedCnt, toast, ThemeClsColor,
|
|
||||||
SwipeToDeleteItem, ShowTimeHistoy
|
|
||||||
)
|
|
||||||
from bitmessagekivy.baseclass.maildetail import MailDetail
|
|
||||||
|
|
||||||
|
|
||||||
class Draft(Screen):
|
|
||||||
"""Draft screen class for kivy Ui"""
|
"""Draft screen class for kivy Ui"""
|
||||||
|
|
||||||
data = ListProperty()
|
data = ListProperty()
|
||||||
account = StringProperty()
|
account = StringProperty()
|
||||||
queryreturn = ListProperty()
|
queryreturn = ListProperty()
|
||||||
has_refreshed = True
|
has_refreshed = True
|
||||||
|
label_str = "yet no message for this account!!!!!!!!!!!!!"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Method used for storing draft messages"""
|
"""Method used for storing draft messages"""
|
||||||
super(Draft, self).__init__(*args, **kwargs)
|
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:
|
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)
|
Clock.schedule_once(self.init_ui, 0)
|
||||||
|
|
||||||
def init_ui(self, dt=0):
|
def init_ui(self, dt=0):
|
||||||
|
@ -50,27 +69,28 @@ class Draft(Screen):
|
||||||
|
|
||||||
def loadDraft(self, where="", what=""):
|
def loadDraft(self, where="", what=""):
|
||||||
"""Load draft list for Draft messages"""
|
"""Load draft list for Draft messages"""
|
||||||
self.account = state.association
|
self.account = self.kivy_state.association
|
||||||
xAddress = 'fromaddress'
|
xAddress = 'fromaddress'
|
||||||
self.ids.tag_label.text = ''
|
self.ids.tag_label.text = ''
|
||||||
self.draftDataQuery(xAddress, where, what)
|
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:
|
# if state.msg_counter_objs:
|
||||||
# state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn))
|
|
||||||
if self.queryreturn:
|
if self.queryreturn:
|
||||||
self.ids.tag_label.text = 'Draft'
|
self.ids.tag_label.text = 'Draft'
|
||||||
self.set_draftCnt(state.draft_count)
|
self.set_draftCnt(self.kivy_state.draft_count)
|
||||||
self.set_mdList()
|
self.set_mdList()
|
||||||
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
||||||
else:
|
else:
|
||||||
self.set_draftCnt('0')
|
self.set_draftCnt('0')
|
||||||
content = MDLabel(
|
# content = MDLabel(
|
||||||
font_style='Caption',
|
# font_style='Caption',
|
||||||
theme_text_color='Primary',
|
# theme_text_color='Primary',
|
||||||
text="yet no message for this account!!!!!!!!!!!!!",
|
# text="yet no message for this account!!!!!!!!!!!!!",
|
||||||
halign='center',
|
# halign='center',
|
||||||
size_hint_y=None,
|
# size_hint_y=None,
|
||||||
valign='top')
|
# valign='top')
|
||||||
self.ids.ml.add_widget(content)
|
self.ids.ml.add_widget(empty_screen_label(self.label_str))
|
||||||
|
|
||||||
def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
|
def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
|
||||||
"""This methosd is for retrieving draft messages"""
|
"""This methosd is for retrieving draft messages"""
|
||||||
|
@ -78,7 +98,8 @@ class Draft(Screen):
|
||||||
xAddress, self.account, "draft", where, what,
|
xAddress, self.account, "draft", where, what,
|
||||||
False, start_indx, end_indx)
|
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"""
|
"""This method set the count of draft mails"""
|
||||||
draftCnt_obj = state.kivyapp.root.ids.content_drawer.ids.draft_cnt
|
draftCnt_obj = state.kivyapp.root.ids.content_drawer.ids.draft_cnt
|
||||||
draftCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count))
|
draftCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count))
|
||||||
|
@ -87,15 +108,7 @@ class Draft(Screen):
|
||||||
"""This method is used to create mdlist"""
|
"""This method is used to create mdlist"""
|
||||||
data = []
|
data = []
|
||||||
total_draft_msg = len(self.ids.ml.children)
|
total_draft_msg = len(self.ids.ml.children)
|
||||||
for mail in self.queryreturn:
|
mdlist_message_content(self.queryreturn,data=data)
|
||||||
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]})
|
|
||||||
for item in data:
|
for item in data:
|
||||||
message_row = SwipeToDeleteItem(
|
message_row = SwipeToDeleteItem(
|
||||||
text='Draft',
|
text='Draft',
|
||||||
|
@ -104,7 +117,7 @@ class Draft(Screen):
|
||||||
listItem.secondary_text = item["text"]
|
listItem.secondary_text = item["text"]
|
||||||
listItem.theme_text_color = "Custom"
|
listItem.theme_text_color = "Custom"
|
||||||
listItem.text_color = ThemeClsColor
|
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(
|
listItem.bind(on_release=partial(
|
||||||
self.draft_detail, item['ackdata'], message_row))
|
self.draft_detail, item['ackdata'], message_row))
|
||||||
message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime']))
|
message_row.ids.time_tag.text = str(ShowTimeHistoy(item['senttime']))
|
||||||
|
@ -130,8 +143,8 @@ class Draft(Screen):
|
||||||
if instance.state == 'closed':
|
if instance.state == 'closed':
|
||||||
instance.ids.delete_msg.disabled = True
|
instance.ids.delete_msg.disabled = True
|
||||||
if instance.open_progress == 0.0:
|
if instance.open_progress == 0.0:
|
||||||
state.detailPageType = 'draft'
|
self.kivy_state.detailPageType = 'draft'
|
||||||
state.mail_id = ackdata
|
self.kivy_state.mail_id = ackdata
|
||||||
if self.manager:
|
if self.manager:
|
||||||
src_mng_obj = self.manager
|
src_mng_obj = self.manager
|
||||||
else:
|
else:
|
||||||
|
@ -144,11 +157,11 @@ class Draft(Screen):
|
||||||
|
|
||||||
def delete_draft(self, data_index, instance, *args):
|
def delete_draft(self, data_index, instance, *args):
|
||||||
"""Delete draft message permanently"""
|
"""Delete draft message permanently"""
|
||||||
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", data_index)
|
helper_sent.delete(data_index)
|
||||||
if int(state.draft_count) > 0:
|
if int(self.kivy_state.draft_count) > 0:
|
||||||
state.draft_count = str(int(state.draft_count) - 1)
|
self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1)
|
||||||
self.set_draftCnt(state.draft_count)
|
self.set_draftCnt(self.kivy_state.draft_count)
|
||||||
if int(state.draft_count) <= 0:
|
if int(self.kivy_state.draft_count) <= 0:
|
||||||
# self.ids.identi_tag.children[0].text = ''
|
# self.ids.identi_tag.children[0].text = ''
|
||||||
self.ids.tag_label.text = ''
|
self.ids.tag_label.text = ''
|
||||||
self.ids.ml.remove_widget(instance.parent.parent)
|
self.ids.ml.remove_widget(instance.parent.parent)
|
||||||
|
@ -190,9 +203,10 @@ class Draft(Screen):
|
||||||
'draft',
|
'draft',
|
||||||
encoding,
|
encoding,
|
||||||
BMConfigParser().safeGetInt('bitmessagesettings', 'ttl'))
|
BMConfigParser().safeGetInt('bitmessagesettings', 'ttl'))
|
||||||
state.msg_counter_objs = src_object.children[2].children[0].ids
|
|
||||||
state.draft_count = str(int(state.draft_count) + 1) \
|
# state.msg_counter_objs = src_object.children[2].children[0].ids
|
||||||
if state.association == fromAddress else state.draft_count
|
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.clear_widgets()
|
||||||
src_object.ids.sc16.add_widget(Draft())
|
src_object.ids.sc16.add_widget(Draft())
|
||||||
toast('Save draft')
|
toast('Save draft')
|
||||||
|
|
30
src/bitmessagekivy/baseclass/draft_widgets.py
Normal file
30
src/bitmessagekivy/baseclass/draft_widgets.py
Normal 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
|
Reference in New Issue
Block a user