|
6 | 6 | ============== |
7 | 7 |
|
8 | 8 | All mails are managed in allmail screen |
9 | | -
|
10 | 9 | """ |
11 | 10 |
|
| 11 | +import logging |
| 12 | + |
12 | 13 | from kivy.clock import Clock |
13 | | -from kivy.properties import ( |
14 | | - ListProperty, |
15 | | - StringProperty |
16 | | -) |
| 14 | +from kivy.properties import ListProperty, StringProperty |
17 | 15 | from kivy.uix.screenmanager import Screen |
18 | 16 | from kivy.app import App |
19 | 17 |
|
20 | 18 | from pybitmessage.bitmessagekivy.baseclass.common import ( |
21 | 19 | show_limited_cnt, empty_screen_label, kivy_state_variables, |
22 | 20 | ) |
23 | 21 |
|
24 | | -import logging |
25 | 22 | logger = logging.getLogger('default') |
26 | 23 |
|
27 | 24 |
|
28 | | -class Allmails(Screen): |
29 | | - """Allmails Screen for kivy Ui""" |
| 25 | +class AllMails(Screen): |
| 26 | + """AllMails Screen for Kivy UI""" |
30 | 27 | data = ListProperty() |
31 | 28 | has_refreshed = True |
32 | 29 | all_mails = ListProperty() |
33 | 30 | account = StringProperty() |
34 | | - label_str = 'yet no message for this account!!!!!!!!!!!!!' |
| 31 | + label_str = 'No messages for this account.' |
35 | 32 |
|
36 | 33 | def __init__(self, *args, **kwargs): |
37 | | - """Method Parsing the address""" |
38 | | - super(Allmails, self).__init__(*args, **kwargs) |
| 34 | + """Initialize the AllMails screen.""" |
| 35 | + super().__init__(*args, **kwargs) |
39 | 36 | self.kivy_state = kivy_state_variables() |
40 | | - if self.kivy_state.selected_address == '': |
41 | | - if App.get_running_app().identity_list: |
42 | | - self.kivy_state.selected_address = App.get_running_app().identity_list[0] |
| 37 | + self._initialize_selected_address() |
43 | 38 | Clock.schedule_once(self.init_ui, 0) |
44 | 39 |
|
| 40 | + def _initialize_selected_address(self): |
| 41 | + """Initialize the selected address from the identity list.""" |
| 42 | + if not self.kivy_state.selected_address and App.get_running_app().identity_list: |
| 43 | + self.kivy_state.selected_address = App.get_running_app().identity_list[0] |
| 44 | + |
45 | 45 | def init_ui(self, dt=0): |
46 | | - """Clock Schdule for method all mails""" |
47 | | - self.loadMessagelist() |
48 | | - logger.debug(dt) |
| 46 | + """Initialize the UI by loading the message list.""" |
| 47 | + self.load_message_list() |
| 48 | + logger.debug("UI initialized after %s seconds.", dt) |
49 | 49 |
|
50 | | - def loadMessagelist(self): |
51 | | - """Load Inbox, Sent anf Draft list of messages""" |
| 50 | + def load_message_list(self): |
| 51 | + """Load the Inbox, Sent, and Draft message lists.""" |
52 | 52 | self.account = self.kivy_state.selected_address |
53 | | - self.ids.tag_label.text = '' |
| 53 | + self.ids.tag_label.text = 'All Mails' if self.all_mails else '' |
| 54 | + self._update_mail_count() |
| 55 | + |
| 56 | + def _update_mail_count(self): |
| 57 | + """Update the mail count and handle empty states.""" |
54 | 58 | if self.all_mails: |
55 | | - self.ids.tag_label.text = 'All Mails' |
56 | | - self.kivy_state.all_count = str( |
57 | | - int(self.kivy_state.sent_count) + int(self.kivy_state.inbox_count)) |
58 | | - self.set_AllmailCnt(self.kivy_state.all_count) |
| 59 | + total_count = int(self.kivy_state.sent_count) + int(self.kivy_state.inbox_count) |
| 60 | + self.kivy_state.all_count = str(total_count) |
| 61 | + self.set_all_mail_count(self.kivy_state.all_count) |
59 | 62 | else: |
60 | | - self.set_AllmailCnt('0') |
| 63 | + self.set_all_mail_count('0') |
61 | 64 | self.ids.ml.add_widget(empty_screen_label(self.label_str)) |
62 | 65 |
|
63 | 66 | @staticmethod |
64 | | - def set_AllmailCnt(Count): |
65 | | - """This method is used to set allmails message count""" |
66 | | - allmailCnt_obj = App.get_running_app().root.ids.content_drawer.ids.allmail_cnt |
67 | | - allmailCnt_obj.ids.badge_txt.text = show_limited_cnt(int(Count)) |
| 67 | + def set_all_mail_count(count): |
| 68 | + """Set the message count for all mails.""" |
| 69 | + allmail_count_widget = App.get_running_app().root.ids.content_drawer.ids.allmail_cnt |
| 70 | + allmail_count_widget.ids.badge_txt.text = show_limited_cnt(int(count)) |
0 commit comments