Merge pull request #64 from navjotcis/newwork

worked on addressbook address validation
This commit is contained in:
navjotcis 2019-12-10 17:03:57 +05:30 committed by GitHub
commit 8d8b04aa0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 43 deletions

View File

@ -62,6 +62,6 @@ def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, w
sqlStatementBase += " ORDER BY lastactiontime DESC limit {0}, {1}".format(start_indx, end_indx) sqlStatementBase += " ORDER BY lastactiontime DESC limit {0}, {1}".format(start_indx, end_indx)
elif folder == "inbox": elif folder == "inbox":
sqlStatementBase += " ORDER BY received DESC limit {0}, {1}".format(start_indx, end_indx) sqlStatementBase += " ORDER BY received DESC limit {0}, {1}".format(start_indx, end_indx)
elif folder == "addressbook": # elif folder == "addressbook":
sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx) # sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx)
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)

View File

@ -99,6 +99,7 @@
icon:'contact-mail' icon:'contact-mail'
on_release: app.root.ids.scr_mngr.current = 'allmails' on_release: app.root.ids.scr_mngr.current = 'allmails'
badge_text: "0" badge_text: "0"
on_press: app.load_screen(self)
NavigationDrawerDivider: NavigationDrawerDivider:
NavigationDrawerSubheader: NavigationDrawerSubheader:
text: "All labels" text: "All labels"
@ -203,11 +204,18 @@ NavigationLayout:
orientation: 'vertical' orientation: 'vertical'
spacing: dp(10) spacing: dp(10)
SearchBar: SearchBar:
FloatLayout: #FloatLayout:
MDScrollViewRefreshLayout: # MDScrollViewRefreshLayout:
id: refresh_layout # id: refresh_layout
refresh_callback: root.refresh_callback # refresh_callback: root.refresh_callback
root_layout: root.set_root_layout() # root_layout: root.set_root_layout()
# MDList:
# id: ml
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList: MDList:
id: ml id: ml
Loader: Loader:
@ -273,13 +281,21 @@ NavigationLayout:
<Allmails>: <Allmails>:
name: 'allmails' name: 'allmails'
FloatLayout: #FloatLayout:
MDScrollViewRefreshLayout: # MDScrollViewRefreshLayout:
id: refresh_layout # id: refresh_layout
refresh_callback: root.refresh_callback # refresh_callback: root.refresh_callback
root_layout: root.set_root_layout() # root_layout: root.set_root_layout()
# MDList:
# id: ml
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList: MDList:
id: ml id: ml
Loader:
ComposerButton: ComposerButton:
<Test>: <Test>:
@ -366,7 +382,8 @@ NavigationLayout:
size_hint_y: None size_hint_y: None
font_size: '13sp' font_size: '13sp'
height: self.parent.height/2 height: self.parent.height/2
hint_text: 'type or search recipients address starting with BM-' #hint_text: 'type or search recipients address starting with BM-'
hint_text: 'type, select or scan QR code for recipients address'
RV: RV:
id: rv id: rv
MDTextField: MDTextField:
@ -648,7 +665,7 @@ NavigationLayout:
do_scroll_x: False do_scroll_x: False
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
padding: [dp(app.window_size[0]/16 if app.window_size[0] <= 720 else app.window_size[0]/4*1.1), dp(10)] padding: [dp(app.window_size[0]/16 if app.window_size[0] <= 720 else app.window_size[0]/4*1.1 if app.window_size[0] <= 800 else app.window_size[0]/18), dp(10)]
spacing: 12 spacing: 12
size_hint_y: None size_hint_y: None
height: self.minimum_height + dp(app.window_size[1]) if app.window_size[1] > app.window_size[0] else dp(app.window_size[0]) height: self.minimum_height + dp(app.window_size[1]) if app.window_size[1] > app.window_size[0] else dp(app.window_size[0])

View File

@ -62,6 +62,7 @@ import state
from uikivysignaler import UIkivySignaler from uikivysignaler import UIkivySignaler
import identiconGeneration import identiconGeneration
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
def toast(text): def toast(text):
@ -298,9 +299,9 @@ class Inbox(Screen):
Clock.schedule_once(refresh_callback, 1) Clock.schedule_once(refresh_callback, 1)
def set_root_layout(self): # def set_root_layout(self):
"""Setting root layout""" # """Setting root layout"""
return self.parent.parent.parent # return self.parent.parent.parent
class MyAddress(Screen): class MyAddress(Screen):
@ -652,8 +653,8 @@ class DropDownWidget(BoxLayout):
# self.parent.parent.screens[0].ids.ml.clear_widgets() # self.parent.parent.screens[0].ids.ml.clear_widgets()
# self.parent.parent.screens[0].loadMessagelist(state.association) # self.parent.parent.screens[0].loadMessagelist(state.association)
self.parent.parent.screens[3].update_sent_messagelist() self.parent.parent.screens[3].update_sent_messagelist()
self.parent.parent.screens[16].clear_widgets() # self.parent.parent.screens[16].clear_widgets()
self.parent.parent.screens[16].add_widget(Allmails()) # self.parent.parent.screens[16].add_widget(Allmails())
Clock.schedule_once(self.callback_for_msgsend, 3) Clock.schedule_once(self.callback_for_msgsend, 3)
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
print "sqlExecute successfully #######################" print "sqlExecute successfully #######################"
@ -1331,6 +1332,11 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
state.association = text state.association = text
state.searcing_text = '' state.searcing_text = ''
LoadingPopup().open() LoadingPopup().open()
self.set_message_count()
Clock.schedule_once(self.setCurrentAccountData, 0.5)
def setCurrentAccountData(self, dt=0):
"""This method set the current accout data on all the screens."""
self.root.ids.sc1.ids.ml.clear_widgets() self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(state.association)
@ -1348,7 +1354,6 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
self.root.ids.sc17.add_widget(Allmails()) self.root.ids.sc17.add_widget(Allmails())
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
self.set_message_count()
@staticmethod @staticmethod
def getCurrentAccount(): def getCurrentAccount():
@ -1699,18 +1704,32 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
if instance.text == 'Inbox': if instance.text == 'Inbox':
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
self.root.ids.sc1.children[1].active = True self.root.ids.sc1.children[1].active = True
self.root.ids.sc1.ids.ml.clear_widgets() elif instance.text == 'All Mails':
Clock.schedule_once(partial(self.load_screen_callback, instance), 0.5) self.root.ids.scr_mngr.current = 'allmails'
try:
self.root.ids.sc17.children[1].active = True
except Exception as e:
self.root.ids.sc17.children[0].children[1].active = True
Clock.schedule_once(partial(self.load_screen_callback, instance), 1)
def load_screen_callback(self, instance, dt=0): def load_screen_callback(self, instance, dt=0):
"""This method is rotating loader for few seconds""" """This method is rotating loader for few seconds"""
if instance.text == 'Inbox': if instance.text == 'Inbox':
self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(state.association)
self.root.ids.sc1.children[1].active = False self.root.ids.sc1.children[1].active = False
elif instance.text == 'All Mails':
self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails())
try:
self.root.ids.sc17.children[1].active = False
except Exception as e:
self.root.ids.sc17.children[0].children[1].active = False
class GrashofPopup(Popup): class GrashofPopup(Popup):
"""Moule for save contacts and error messages""" """Moule for save contacts and error messages"""
valid = False
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""Grash of pop screen settings""" """Grash of pop screen settings"""
@ -1733,7 +1752,7 @@ class GrashofPopup(Popup):
stored_labels = [labels[0] for labels in kivy_helper_search.search_sql( stored_labels = [labels[0] for labels in kivy_helper_search.search_sql(
folder="addressbook")] folder="addressbook")]
if label and address and address not in stored_address \ if label and address and address not in stored_address \
and label not in stored_labels: and label not in stored_labels and self.valid:
# state.navinstance = self.parent.children[1] # state.navinstance = self.parent.children[1]
queues.UISignalQueue.put(('rerenderAddressBook', '')) queues.UISignalQueue.put(('rerenderAddressBook', ''))
self.dismiss() self.dismiss()
@ -1779,12 +1798,17 @@ class GrashofPopup(Popup):
text = 'Address is already in the addressbook.' text = 'Address is already in the addressbook.'
elif entered_text in my_addresses: elif entered_text in my_addresses:
text = 'You can not save your own address.' text = 'You can not save your own address.'
elif entered_text:
text = self.addressChanged(entered_text)
if entered_text in my_addresses or entered_text in add_book: if entered_text in my_addresses or entered_text in add_book:
self.ids.address.error = True self.ids.address.error = True
self.ids.address.helper_text = text self.ids.address.helper_text = text
elif entered_text: elif entered_text and self.valid:
self.ids.address.error = False self.ids.address.error = False
elif entered_text:
self.ids.address.error = True
self.ids.address.helper_text = text
else: else:
self.ids.address.error = False self.ids.address.error = False
self.ids.address.helper_text = 'This field is required' self.ids.address.helper_text = 'This field is required'
@ -1803,6 +1827,33 @@ class GrashofPopup(Popup):
self.ids.label.error = False self.ids.label.error = False
self.ids.label.helper_text = 'This field is required' self.ids.label.helper_text = 'This field is required'
def _onSuccess(self, addressVersion, streamNumber, ripe):
pass
def addressChanged(self, addr):
"""Address validation callback, performs validation and gives feedback"""
status, addressVersion, streamNumber, ripe = decodeAddress(
str(addr))
self.valid = status == 'success'
if self.valid:
text = "Address is valid."
self._onSuccess(addressVersion, streamNumber, ripe)
elif status == 'missingbm':
text = "The address should start with ''BM-''"
elif status == 'checksumfailed':
text = "The address is not typed or copied correctly(the checksum failed)."
elif status == 'versiontoohigh':
text = "The version number of this address is higher than this software can support. Please upgrade Bitmessage."
elif status == 'invalidcharacters':
text = "The address contains invalid characters."
elif status == 'ripetooshort':
text = "Some data encoded in the address is too short."
elif status == 'ripetoolong':
text = "Some data encoded in the address is too long."
elif status == 'varintmalformed':
text = "Some data encoded in the address is malformed."
return text
class AvatarSampleWidget(ILeftBody, Image): class AvatarSampleWidget(ILeftBody, Image):
"""Avatar Sample Widget""" """Avatar Sample Widget"""
@ -2321,16 +2372,12 @@ class Allmails(Screen):
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method all mails""" """Clock Schdule for method all mails"""
self.mailaccounts()
print dt
def mailaccounts(self):
"""Load all mails for account."""
self.account = state.association
self.loadMessagelist() self.loadMessagelist()
print dt
def loadMessagelist(self): def loadMessagelist(self):
"""Load Inbox, Sent anf Draft list of messages.""" """Load Inbox, Sent anf Draft list of messages."""
self.account = state.association
self.allMessageQuery(0, 20) self.allMessageQuery(0, 20)
if self.all_mails: if self.all_mails:
state.kivyapp.get_inbox_count() state.kivyapp.get_inbox_count()
@ -2340,7 +2387,8 @@ class Allmails(Screen):
state.kivyapp.root.children[2].children[ state.kivyapp.root.children[2].children[
0].ids.allmail_cnt.badge_text = state.all_count 0].ids.allmail_cnt.badge_text = state.all_count
self.set_mdlist() self.set_mdlist()
self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y) # self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else: else:
content = MDLabel( content = MDLabel(
font_style='Body1', font_style='Body1',
@ -2401,8 +2449,8 @@ class Allmails(Screen):
def check_scroll_y(self, instance, somethingelse): def check_scroll_y(self, instance, somethingelse):
"""Scroll fixed length""" """Scroll fixed length"""
if self.ids.refresh_layout.scroll_y <= -0.00 and self.has_refreshed: if self.ids.scroll_y.scroll_y <= -0.00 and self.has_refreshed:
self.ids.refresh_layout.scroll_y = .06 self.ids.scroll_y.scroll_y = .06
load_more = len(self.ids.ml.children) load_more = len(self.ids.ml.children)
self.updating_allmail(load_more) self.updating_allmail(load_more)
else: else:
@ -2439,13 +2487,13 @@ class Allmails(Screen):
unique_id)) unique_id))
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
try: try:
msg_count_objs = self.parent.parent.parent.parent.children[
2].children[0].ids
nav_lay_obj = self.parent.parent.parent.parent.ids
except Exception:
msg_count_objs = self.parent.parent.parent.parent.parent.children[ msg_count_objs = self.parent.parent.parent.parent.parent.children[
2].children[0].ids 2].children[0].ids
nav_lay_obj = self.parent.parent.parent.parent.parent.ids nav_lay_obj = self.parent.parent.parent.parent.parent.ids
except Exception:
msg_count_objs = self.parent.parent.parent.parent.parent.parent.children[
2].children[0].ids
nav_lay_obj = self.parent.parent.parent.parent.parent.parent.ids
if folder == 'inbox': if folder == 'inbox':
msg_count_objs.inbox_cnt.badge_text = str( msg_count_objs.inbox_cnt.badge_text = str(
int(state.inbox_count) - 1) int(state.inbox_count) - 1)
@ -2466,8 +2514,7 @@ class Allmails(Screen):
state.all_count = str(int(state.all_count) - 1) state.all_count = str(int(state.all_count) - 1)
nav_lay_obj.sc5.clear_widgets() nav_lay_obj.sc5.clear_widgets()
nav_lay_obj.sc5.add_widget(Trash()) nav_lay_obj.sc5.add_widget(Trash())
nav_lay_obj.sc17.clear_widgets() nav_lay_obj.sc17.remove_widget(instance.parent.parent)
nav_lay_obj.sc17.add_widget(Allmails())
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
def refresh_callback(self, *args): def refresh_callback(self, *args):
@ -2496,10 +2543,13 @@ class Allmails(Screen):
def avatarImageFirstLetter(letter_string): def avatarImageFirstLetter(letter_string):
"""This function is used to the first letter for the avatar image""" """This function is used to the first letter for the avatar image"""
if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z': if letter_string:
img_latter = letter_string[0].upper() if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z':
elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9: img_latter = letter_string[0].upper()
img_latter = letter_string[0] elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9:
img_latter = letter_string[0]
else:
img_latter = '!'
else: else:
img_latter = '!' img_latter = '!'
return img_latter return img_latter