diff --git a/StellaPay.py b/StellaPay.py index 49ea9fc..3866d6c 100644 --- a/StellaPay.py +++ b/StellaPay.py @@ -135,6 +135,7 @@ def build(self): Window.show_cursor = self.get_config_option(config.ConfigurationOption.DEVICE_SHOW_CURSOR) == "True" # Load .kv file + Builder.load_file("kvs/VerticalButtonWithIcon.kv") Builder.load_file("kvs/DefaultScreen.kv") Logger.debug("StellaPayUI: Starting event loop") diff --git a/kvs/DefaultScreen.kv b/kvs/DefaultScreen.kv index 71316dc..47ff051 100644 --- a/kvs/DefaultScreen.kv +++ b/kvs/DefaultScreen.kv @@ -4,7 +4,7 @@ MDIconButton: icon: 'img/STEmediumnobg.png' - user_font_size: "450sp" + icon_size: "450dp" size_hint: None, None pos_hint: {"center_x":0.27,"center_y":0.63} on_release: root.to_credits() @@ -14,17 +14,20 @@ text: "[b]STELLA PAY[/b]" font_size: '53sp' pos_hint: {"center_x":0.27,"center_y":0.2} + size_hint_x: 0.4 + size_hint_y: 0.2 font_name: 'fonts/orbitron/Orbitron-Bold.ttf' markup: True MDIconButton: id: connection_state - user_font_size: "25sp" + icon_size: "25dp" md_bg_color: app.theme_cls.purple_button icon: "wifi-off" pos_hint: {"center_x": 0.13,"center_y":0.79} MDFillRoundFlatButton: + id: button_select_user text: "Selecteer gebruiker" font_size: '32sp' pos_hint: {"center_x":0.7,"center_y":0.78} @@ -71,42 +74,29 @@ on_press: root.select_recent_user(recent_user_two.text) halign: "center" - MDIconButton: - icon: "account-clock" - text: "test" - user_font_size: "64sp" - pos_hint: {"center_x":0.58,"center_y":0.24} - on_press: root.on_select_guest() - - MDLabel: - text: "Gasten" - pos_hint: {"x":0.55,"center_y":0.165} - font_style: "H6" - theme_text_color: "Primary" - - MDIconButton: - icon: "tools" - user_font_size: "64sp" - pos_hint: {"center_x":0.7,"center_y":0.24} - on_press: root.on_select_onderhoud() - - MDLabel: - text: "Onderhoud" - pos_hint: {"x":0.665,"center_y":0.165} - font_style: "H6" - theme_text_color: "Primary" - - MDIconButton: - icon: "account-supervisor-circle" - user_font_size: "64sp" - pos_hint: {"center_x":0.82,"center_y":0.24} - on_press: root.on_select_beheer() - - MDLabel: - text: "Beheer" - pos_hint: {"x":0.795,"center_y":0.165} - font_style: "H6" - theme_text_color: "Primary" + BoxLayout: + orientation: "horizontal" + size_hint_x: 0.4 + size_hint_y: 0.25 + pos_hint: {"center_x": (button_select_user.center_x / root.width), "center_y": (stella_pay.center_y / root.height)} + + VerticalButtonWithIcon: + id: guest_button + pos_hint: {"center_y": 0.5} + icon: "account-clock" + label_text: "Gasten" + + VerticalButtonWithIcon: + id: maintenance_button + pos_hint: {"center_y": 0.5} + icon: "tools" + label_text: "Onderhoud" + + VerticalButtonWithIcon: + id: admin_button + pos_hint: {"center_y": 0.5} + icon: "account-supervisor-circle" + label_text: "Beheer" MDSpinner: id: spinner diff --git a/kvs/ProductScreen.kv b/kvs/ProductScreen.kv index 8075a66..ef11592 100644 --- a/kvs/ProductScreen.kv +++ b/kvs/ProductScreen.kv @@ -2,7 +2,7 @@ BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: id: toolbar title: 'Stella Pay' font_name: 'fonts/orbitron/Orbitron-Bold.ttf' @@ -14,7 +14,6 @@ id: android_tabs tab_bar_height: '50dp' lock_swiping: True -# anim_duration: 0.0 text_color_normal: (0,0,0,1) text_color_active: (1,1,1,1) color_indicator: (0,0,0,1) diff --git a/kvs/ProfileScreen.kv b/kvs/ProfileScreen.kv index 45305de..bcfea9c 100644 --- a/kvs/ProfileScreen.kv +++ b/kvs/ProfileScreen.kv @@ -3,7 +3,7 @@ anchor_x: 'center' anchor_y: 'top' - MDToolbar: + MDTopAppBar: title: 'STELLA PAY' font_name: 'fonts/orbitron/Orbitron-Bold.ttf' # md_bg_color: 0.078, 0.537, 0.882, 1 diff --git a/kvs/VerticalButtonWithIcon.kv b/kvs/VerticalButtonWithIcon.kv new file mode 100644 index 0000000..17d0f54 --- /dev/null +++ b/kvs/VerticalButtonWithIcon.kv @@ -0,0 +1,23 @@ +: + # Custom variables + icon: "" + label_text: "" + pos_x: 0.0 + pos_y: 0.0 + + orientation: "vertical" + pos_hint: {"x": root.pos_x, "y": root.pos_y} + size_hint_y: 0.15 + size_hint_x: 0.1 + + MDIconButton: + id: icon_of_button + icon: root.icon + icon_size: "64dp" + pos_hint: {"center_x": .5} + + MDLabel: + text: root.label_text + font_style: "H6" + halign: "center" + theme_text_color: "Primary" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 64421f0..fc6b756 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ smartcard~=0.3 Kivy~=2.1.0 requests==2.28.2 -kivymd~=0.104.2 \ No newline at end of file +kivymd~=1.1.1 \ No newline at end of file diff --git a/scrs/DefaultScreen.py b/scrs/DefaultScreen.py index a86c314..e142274 100644 --- a/scrs/DefaultScreen.py +++ b/scrs/DefaultScreen.py @@ -101,6 +101,11 @@ def __init__(self, **kwargs): # Register listener App.get_running_app().data_controller.register_connection_listener(self.connection_change_listener) + # Listen to a user pressing the icon of a button + self.ids.admin_button.ids.icon_of_button.bind(on_press=self.on_select_beheer) + self.ids.guest_button.ids.icon_of_button.bind(on_press=self.on_select_guest) + self.ids.maintenance_button.ids.icon_of_button.bind(on_press=self.on_select_onderhoud) + def register_card_listener(self, card_connection_manager: "CardConnectionManager"): card_connection_manager.register_listener(self.nfc_listener) @@ -283,13 +288,13 @@ def move_to_register_card_screen(self, uid: str): self.manager.get_screen(Screens.REGISTER_UID_SCREEN.value).nfc_id = uid self.manager.current = Screens.REGISTER_UID_SCREEN.value - def on_select_guest(self): + def on_select_guest(self, _): self.select_special_user("Gast Account") - def on_select_beheer(self): + def on_select_beheer(self, _): self.select_special_user("Beheer Algemeen") - def on_select_onderhoud(self): + def on_select_onderhoud(self, _): self.select_special_user("Beheer Onderhoud") def select_special_user(self, user: str): diff --git a/scrs/ProductScreen.py b/scrs/ProductScreen.py index c1f8c7b..94f4ab2 100644 --- a/scrs/ProductScreen.py +++ b/scrs/ProductScreen.py @@ -10,8 +10,10 @@ from kivy.clock import Clock, mainthread from kivy.lang import Builder from kivy.uix.screenmanager import Screen, SlideTransition +from kivymd.material_resources import dp from kivymd.uix.button import MDFlatButton, MDRaisedButton from kivymd.uix.dialog import MDDialog +from kivymd.uix.spinner import MDSpinner from ds.Product import Product from ds.Purchase import Purchase @@ -108,7 +110,7 @@ def show_products(self, products: Dict[str, List[Product]]): Logger.debug(f"StellaPayUI: ({threading.current_thread().name}) Drawing tabs for the first time.") self.tabs = [] for tab_name in products.keys(): - tab = TabDisplay(text=tab_name) + tab = TabDisplay(title=tab_name) self.ids.android_tabs.add_widget(tab) self.tabs.append(tab) else: @@ -117,7 +119,7 @@ def show_products(self, products: Dict[str, List[Product]]): start_time = time.time() for tab in self.tabs: - for product in products[tab.text]: + for product in products[tab.title]: # Get fun fact description of database product_description = App.get_running_app().database_manager.get_random_fun_fact(product.get_name()) @@ -143,7 +145,7 @@ def show_products(self, products: Dict[str, List[Product]]): ) ) - Logger.debug(f"Loaded products of category {tab.text} (no skipping) in {time.time() - start_time} seconds") + Logger.debug(f"Loaded products of category {tab.title} (no skipping) in {time.time() - start_time} seconds") Logger.debug(f"Loaded all products (no skipping) in {time.time() - start_time} seconds") @@ -191,7 +193,7 @@ def on_timeout(self, dt): # # upon leaving the screen, cancel the timeout event # - def on_leave(self, *args): + def on_pre_leave(self, *args): self.timeout_event.cancel() if self.final_dialog is not None: @@ -245,7 +247,6 @@ def show_shopping_cart(self): MDRaisedButton(text="Ja", on_release=self.on_confirm_payment), ], ) - # Open the dialog to display the shopping cart self.shopping_cart_dialog.open() @@ -270,6 +271,13 @@ def on_cancel_payment(self, dt): def on_confirm_payment(self, dt=None): Logger.info(f"StellaPayUI: Payment was confirmed by the user.") + spinner = MDSpinner(size_hint=(None, None), size=(dp(32), dp(32)), active=True) + + # Show a spinner when user confirms the payment and hide the other buttons + self.shopping_cart_dialog.ids.button_box.add_widget(spinner) + self.shopping_cart_dialog.ids.button_box.children[1].opacity = 0.0 + self.shopping_cart_dialog.ids.button_box.children[2].opacity = 0.0 + asyncio.run_coroutine_threadsafe(self.submit_payment(), loop=App.get_running_app().loop) async def submit_payment(self): @@ -279,13 +287,17 @@ async def submit_payment(self): self.shopping_cart ) + self.update_ui_after_payment(successfully_created_transactions) + + @mainthread + def update_ui_after_payment(self, transaction_successful: bool): # Reset instance variables self.end_user_session() if self.shopping_cart_dialog is not None: self.shopping_cart_dialog.dismiss() - if successfully_created_transactions: + if transaction_successful: self.show_thanks_dialog() else: self.show_failure_dialog() @@ -296,7 +308,7 @@ def show_thanks_dialog(self): self.final_dialog = MDDialog( text="Gelukt! Je aankoop is geregistreerd!", - on_dismiss=self.on_thanks + on_dismiss=self.on_thanks, ) self.timeout_event = Clock.schedule_once(self.on_thanks, 5)