33import mpos .config
44import mpos .ui
55
6-
76# Used to list and edit all settings:
87class SettingsActivity (Activity ):
98 def __init__ (self ):
109 super ().__init__ ()
1110 self .prefs = None
1211 self .settings = [
13- {"title" : "Light/Dark Theme" , "key" : "theme_light_dark" , "value_label" : None , "cont" : None },
12+ {"title" : "Light/Dark Theme" , "key" : "theme_light_dark" , "value_label" : None , "cont" : None , "ui" : "radiobuttons" , "ui_options" : [( "Light" , "light" ), ( "Dark" , "dark" )] },
1413 {"title" : "Theme Color" , "key" : "theme_primary_color" , "value_label" : None , "cont" : None , "placeholder" : "HTML hex color, like: EC048C" },
15- {"title" : "Restart to Bootloader" , "key" : "boot_mode" , "value_label" : None , "cont" : None }, # special that doesn't get saved
14+ {"title" : "Restart to Bootloader" , "key" : "boot_mode" , "value_label" : None , "cont" : None , "ui" : "radiobuttons" , "ui_options" : [( "Normal" , "normal" ), ( "Bootloader" , "bootloader" )] }, # special that doesn't get saved
1615 # This is currently only in the drawer but would make sense to have it here for completeness:
1716 #{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
1817 # Maybe also add font size (but ideally then all fonts should scale up/down)
@@ -99,7 +98,9 @@ def onCreate(self):
9998 setting_label .align (lv .ALIGN .TOP_LEFT ,0 ,0 )
10099 setting_label .set_style_text_font (lv .font_montserrat_26 , 0 )
101100
102- if setting ["key" ] == "theme_light_dark" or setting ["key" ] == "boot_mode" :
101+ ui = setting .get ("ui" )
102+ ui_options = setting .get ("ui_options" )
103+ if ui and ui == "radiobuttons" and ui_options :
103104 # Create container for radio buttons
104105 self .radio_container = lv .obj (settings_screen_detail )
105106 self .radio_container .set_width (lv .pct (100 ))
@@ -108,18 +109,15 @@ def onCreate(self):
108109 self .radio_container .add_event_cb (self .radio_event_handler , lv .EVENT .CLICKED , None )
109110
110111 # Create radio buttons
111- if setting ["key" ] == "boot_mode" :
112- options = [("Normal" , "normal" ), ("Bootloader" , "bootloader" )]
113- else :
114- options = [("Light" , "light" ), ("Dark" , "dark" )]
115112 current_setting = self .prefs .get_string (setting ["key" ])
116113 self .active_radio_index = - 1 # none
117- if current_setting == options [0 ][1 ]:
114+ # currently only supports 2 options, could be more generic:
115+ if current_setting == ui_options [0 ][1 ]:
118116 self .active_radio_index = 0
119- elif current_setting == options [1 ][1 ]:
117+ elif current_setting == ui_options [1 ][1 ]:
120118 self .active_radio_index = 1
121-
122- for i , (text , _ ) in enumerate (options ):
119+ # create radio buttons and check the right one
120+ for i , (text , _ ) in enumerate (ui_options ):
123121 cb = self .create_radio_button (self .radio_container , text , i )
124122 if i == self .active_radio_index :
125123 cb .add_state (lv .STATE .CHECKED )
@@ -231,20 +229,23 @@ def cambutton_cb_unused(self, event):
231229 self .startActivityForResult (Intent (activity_class = CameraApp ).putExtra ("scanqr_mode" , True ), self .gotqr_result_callback )
232230
233231 def save_setting (self , setting ):
234- if setting ["key" ] == "boot_mode" and self .radio_container :
232+ if setting ["key" ] == "boot_mode" and self .radio_container : # special case that isn't saved
235233 if self .active_radio_index == 1 :
236234 from mpos .bootloader import ResetIntoBootloader
237235 intent = Intent (activity_class = ResetIntoBootloader )
238236 ActivityNavigator .startActivity (intent )
239237 return
240238
241- if ( setting ["key" ] == "theme_light_dark" or setting ["key" ] == "boot_mode" ) and self .radio_container :
242- if setting ["key" ] == "boot_mode" :
243- options = [("Normal" , "normal" ), ("Bootloader" , "bootloader" )]
239+ ui = setting .get ("ui" )
240+ if ui and ui == "radiobuttons" and self .radio_container :
241+ ui_options = setting .get ("ui_options" )
242+ if ui_options :
243+ options = ui_options
244244 else :
245- options = [("Light" , "light" ), ("Dark" , "dark" )]
245+ print ("No ui_options are available, not saving..." )
246+ return
246247 selected_idx = self .active_radio_index
247- if selected_idx == 0 :
248+ if selected_idx == 0 : # only supports 2 options, could be made more generic
248249 new_value = options [0 ][1 ]
249250 elif selected_idx == 1 :
250251 new_value = options [1 ][1 ]
0 commit comments