diff --git a/src/bitmessagekivy/baseclass/allmail.py b/src/bitmessagekivy/baseclass/allmail.py index d30310d8..12104c57 100644 --- a/src/bitmessagekivy/baseclass/allmail.py +++ b/src/bitmessagekivy/baseclass/allmail.py @@ -6,14 +6,12 @@ allmail.py ============== All mails are managed in allmail screen - """ +import logging + from kivy.clock import Clock -from kivy.properties import ( - ListProperty, - StringProperty -) +from kivy.properties import ListProperty, StringProperty from kivy.uix.screenmanager import Screen from kivy.app import App @@ -21,47 +19,52 @@ from pybitmessage.bitmessagekivy.baseclass.common import ( show_limited_cnt, empty_screen_label, kivy_state_variables, ) -import logging logger = logging.getLogger('default') -class Allmails(Screen): - """Allmails Screen for kivy Ui""" +class AllMails(Screen): + """AllMails Screen for Kivy UI""" data = ListProperty() has_refreshed = True all_mails = ListProperty() account = StringProperty() - label_str = 'yet no message for this account!!!!!!!!!!!!!' + label_str = 'No messages for this account.' def __init__(self, *args, **kwargs): - """Method Parsing the address""" - super(Allmails, self).__init__(*args, **kwargs) + """Initialize the AllMails screen.""" + super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument self.kivy_state = kivy_state_variables() - if self.kivy_state.selected_address == '': - if App.get_running_app().identity_list: - self.kivy_state.selected_address = App.get_running_app().identity_list[0] + self._initialize_selected_address() Clock.schedule_once(self.init_ui, 0) - def init_ui(self, dt=0): - """Clock Schdule for method all mails""" - self.loadMessagelist() - logger.debug(dt) + def _initialize_selected_address(self): + """Initialize the selected address from the identity list.""" + if not self.kivy_state.selected_address and App.get_running_app().identity_list: + self.kivy_state.selected_address = App.get_running_app().identity_list[0] - def loadMessagelist(self): - """Load Inbox, Sent anf Draft list of messages""" + def init_ui(self, dt=0): + """Initialize the UI by loading the message list.""" + self.load_message_list() + logger.debug("UI initialized after %s seconds.", dt) + + def load_message_list(self): + """Load the Inbox, Sent, and Draft message lists.""" self.account = self.kivy_state.selected_address - self.ids.tag_label.text = '' + self.ids.tag_label.text = 'All Mails' if self.all_mails else '' + self._update_mail_count() + + def _update_mail_count(self): + """Update the mail count and handle empty states.""" if self.all_mails: - self.ids.tag_label.text = 'All Mails' - self.kivy_state.all_count = str( - int(self.kivy_state.sent_count) + int(self.kivy_state.inbox_count)) - self.set_AllmailCnt(self.kivy_state.all_count) + total_count = int(self.kivy_state.sent_count) + int(self.kivy_state.inbox_count) + self.kivy_state.all_count = str(total_count) + self.set_all_mail_count(self.kivy_state.all_count) else: - self.set_AllmailCnt('0') + self.set_all_mail_count('0') self.ids.ml.add_widget(empty_screen_label(self.label_str)) @staticmethod - def set_AllmailCnt(Count): - """This method is used to set allmails message count""" - allmailCnt_obj = App.get_running_app().root.ids.content_drawer.ids.allmail_cnt - allmailCnt_obj.ids.badge_txt.text = show_limited_cnt(int(Count)) + def set_all_mail_count(count): + """Set the message count for all mails.""" + allmail_count_widget = App.get_running_app().root.ids.content_drawer.ids.allmail_cnt + allmail_count_widget.ids.badge_txt.text = show_limited_cnt(int(count)) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index 6ddf322d..11fb6c79 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -174,7 +174,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes self.parent.screens[3].clear_widgets() self.parent.screens[3].add_widget(Factory.Trash()) self.parent.screens[14].clear_widgets() - self.parent.screens[14].add_widget(Factory.Allmails()) + self.parent.screens[14].add_widget(Factory.AllMails()) Clock.schedule_once(self.callback_for_delete, 4) def callback_for_delete(self, dt=0): diff --git a/src/bitmessagekivy/kv/allmails.kv b/src/bitmessagekivy/kv/allmails.kv index f1b9387e..3df69e05 100644 --- a/src/bitmessagekivy/kv/allmails.kv +++ b/src/bitmessagekivy/kv/allmails.kv @@ -1,4 +1,4 @@ -: +: name: 'allmails' BoxLayout: orientation: 'vertical' diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 42e66762..74723e32 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -250,7 +250,7 @@ MDNavigationLayout: id:id_sent Trash: id:id_trash - Allmails: + AllMails: id:id_allmail Draft: id:id_draft diff --git a/src/bitmessagekivy/screens_data.json b/src/bitmessagekivy/screens_data.json index 86ddea19..974ef1c4 100644 --- a/src/bitmessagekivy/screens_data.json +++ b/src/bitmessagekivy/screens_data.json @@ -59,7 +59,7 @@ "All Mails": { "kv_string": "allmails", "name_screen": "allmails", - "Import": "from pybitmessage.bitmessagekivy.baseclass.allmail import Allmails" + "Import": "from pybitmessage.bitmessagekivy.baseclass.allmail import AllMails" }, "MailDetail": { "kv_string": "maildetail",