allmail.py
1 # pylint: disable=import-error, no-name-in-module 2 # pylint: disable=unused-argument, no-member, attribute-defined-outside-init 3 4 """ 5 allmail.py 6 ============== 7 8 All mails are managed in allmail screen 9 """ 10 11 import logging 12 13 from kivy.clock import Clock 14 from kivy.properties import ListProperty, StringProperty 15 from kivy.uix.screenmanager import Screen 16 from kivy.app import App 17 18 from pybitmessage.bitmessagekivy.baseclass.common import ( 19 show_limited_cnt, empty_screen_label, kivy_state_variables, 20 ) 21 22 logger = logging.getLogger('default') 23 24 25 class AllMails(Screen): 26 """AllMails Screen for Kivy UI""" 27 data = ListProperty() 28 has_refreshed = True 29 all_mails = ListProperty() 30 account = StringProperty() 31 label_str = 'No messages for this account.' 32 33 def __init__(self, *args, **kwargs): 34 """Initialize the AllMails screen.""" 35 super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument 36 self.kivy_state = kivy_state_variables() 37 self._initialize_selected_address() 38 Clock.schedule_once(self.init_ui, 0) 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 def init_ui(self, dt=0): 46 """Initialize the UI by loading the message list.""" 47 self.load_message_list() 48 logger.debug("UI initialized after %s seconds.", dt) 49 50 def load_message_list(self): 51 """Load the Inbox, Sent, and Draft message lists.""" 52 self.account = self.kivy_state.selected_address 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.""" 58 if self.all_mails: 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) 62 else: 63 self.set_all_mail_count('0') 64 self.ids.ml.add_widget(empty_screen_label(self.label_str)) 65 66 @staticmethod 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))