1- from mpos .apps import Activity
1+ from mpos .apps import Activity , Intent
22import mpos .config
33import mpos .ui
44
@@ -10,6 +10,7 @@ class MainActivity(Activity):
1010 def __init__ (self ):
1111 self .wallet = None
1212 self .receive_qr_data = None
13+ self .destination = None
1314 # widgets
1415 self .balance_label = None
1516 self .receive_qr = None
@@ -84,8 +85,9 @@ def onResume(self, main_screen):
8485 self .payments_label .set_text (f"Could not start { wallet_type } backend." )
8586
8687 def onStop (self , main_screen ):
87- if self .wallet :
88+ if self .wallet and self . destination != FullscreenQR :
8889 self .wallet .stop ()
90+ self .destination = None
8991
9092 def redraw_balance_cb (self ):
9193 # this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
@@ -95,30 +97,20 @@ def redraw_payments_cb(self):
9597 # this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
9698 lv .async_call (lambda l : self .payments_label .set_text (str (self .wallet .payment_list )), None )
9799
98-
99100 def settings_button_tap (self , event ):
100- settings_activity = SettingsActivity ()
101- settings_activity .onCreate ()
101+ self .startActivity (Intent (activity_class = SettingsActivity ))
102102
103103 def main_ui_set_defaults (self ):
104104 self .balance_label .set_text (lv .SYMBOL .REFRESH )
105105 self .payments_label .set_text (lv .SYMBOL .REFRESH )
106- self .receive_qr .update ("EMPTY" , len ("EMPTY" ))
106+ self .receive_qr .update ("EMPTY PLACEHOLDER " , len ("EMPTY PLACEHOLDER " ))
107107
108108 def qr_clicked_cb (self , event ):
109+ print ("QR clicked" )
109110 if not self .receive_qr_data :
110111 return
111- print ("QR clicked" )
112- qr_screen = lv .obj ()
113- big_receive_qr = lv .qrcode (qr_screen )
114- big_receive_qr .set_size (240 ) # TODO: make this dynamic
115- big_receive_qr .set_dark_color (lv .color_black ())
116- big_receive_qr .set_light_color (lv .color_white ())
117- big_receive_qr .center ()
118- big_receive_qr .set_style_border_color (lv .color_white (), 0 )
119- big_receive_qr .set_style_border_width (3 , 0 );
120- big_receive_qr .update (self .receive_qr_data , len (self .receive_qr_data ))
121- mpos .ui .load_screen (qr_screen )
112+ self .destination = FullscreenQR
113+ self .startActivity (Intent (activity_class = FullscreenQR ).putExtra ("receive_qr_data" , self .receive_qr_data ))
122114
123115# Used to list and edit all settings:
124116class SettingsActivity (Activity ):
@@ -190,18 +182,19 @@ def onResume(self, screen):
190182 setting ["cont" ].remove_flag (lv .obj .FLAG .HIDDEN )
191183
192184 def startSettingActivity (self , setting ):
193- sa = SettingActivity ( setting )
194- sa . onCreate ( )
195-
185+ intent = Intent ( activity_class = SettingActivity )
186+ intent . putExtra ( "setting" , setting )
187+ self . startActivity ( intent )
196188
197189# Used to edit one setting:
198190class SettingActivity (Activity ):
199- def __init__ (self , setting ):
191+ def __init__ (self ):
200192 super ().__init__ ()
201193 self .prefs = mpos .config .SharedPreferences ("com.lightningpiggy.displaywallet" )
202- self .setting = setting
194+ self .setting = None
203195
204196 def onCreate (self ):
197+ setting = self .getIntent ().extras .get ("setting" )
205198 settings_screen_detail = lv .obj ()
206199 settings_screen_detail .set_style_pad_all (10 , 0 )
207200 settings_screen_detail .set_flex_flow (lv .FLEX_FLOW .COLUMN )
@@ -214,7 +207,7 @@ def onCreate(self):
214207 top_cont .set_style_flex_main_place (lv .FLEX_ALIGN .SPACE_BETWEEN , 0 )
215208
216209 setting_label = lv .label (top_cont )
217- setting_label .set_text (self . setting ["title" ])
210+ setting_label .set_text (setting ["title" ])
218211 setting_label .align (lv .ALIGN .TOP_LEFT ,0 ,0 )
219212 setting_label .set_style_text_font (lv .font_montserrat_22 , 0 )
220213
@@ -226,7 +219,7 @@ def onCreate(self):
226219 cambuttonlabel .center ()
227220 cambutton .add_event_cb (self .cambutton_cb , lv .EVENT .CLICKED , None )
228221
229- if self . setting ["key" ] == "wallet_type" :
222+ if setting ["key" ] == "wallet_type" :
230223 cambutton .add_flag (lv .obj .FLAG .HIDDEN )
231224 # Create container for radio buttons
232225 self .radio_container = lv .obj (settings_screen_detail )
@@ -249,7 +242,7 @@ def onCreate(self):
249242 self .textarea = lv .textarea (settings_screen_detail )
250243 self .textarea .set_width (lv .pct (100 ))
251244 self .textarea .set_height (lv .SIZE_CONTENT )
252- self .textarea .set_text (self .prefs .get_string (self . setting ["key" ], "" ))
245+ self .textarea .set_text (self .prefs .get_string (setting ["key" ], "" ))
253246 self .textarea .add_event_cb (self .show_keyboard , lv .EVENT .CLICKED , None )
254247 self .textarea .add_event_cb (self .show_keyboard , lv .EVENT .FOCUSED , None )
255248 self .textarea .add_event_cb (self .hide_keyboard , lv .EVENT .DEFOCUSED , None )
@@ -275,7 +268,7 @@ def onCreate(self):
275268 save_label = lv .label (save_btn )
276269 save_label .set_text ("Save" )
277270 save_label .center ()
278- save_btn .add_event_cb (lambda e , s = self . setting : self .save_setting (s ), lv .EVENT .CLICKED , None )
271+ save_btn .add_event_cb (lambda e , s = setting : self .save_setting (s ), lv .EVENT .CLICKED , None )
279272 # Cancel button
280273 cancel_btn = lv .button (btn_cont )
281274 cancel_btn .set_size (lv .pct (45 ), lv .SIZE_CONTENT )
@@ -354,3 +347,18 @@ def save_setting(self, setting):
354347 setting ["value_label" ].set_text (new_value if new_value else "Not set" )
355348 self .finish ()
356349
350+
351+ class FullscreenQR (Activity ):
352+
353+ def onCreate (self ):
354+ receive_qr_data = self .getIntent ().extras .get ("receive_qr_data" )
355+ qr_screen = lv .obj ()
356+ big_receive_qr = lv .qrcode (qr_screen )
357+ big_receive_qr .set_size (240 ) # TODO: make this dynamic
358+ big_receive_qr .set_dark_color (lv .color_black ())
359+ big_receive_qr .set_light_color (lv .color_white ())
360+ big_receive_qr .center ()
361+ big_receive_qr .set_style_border_color (lv .color_white (), 0 )
362+ big_receive_qr .set_style_border_width (3 , 0 );
363+ big_receive_qr .update (receive_qr_data , len (receive_qr_data ))
364+ self .setContentView (qr_screen )
0 commit comments