|
| 1 | +import lvgl as lv |
| 2 | + |
| 3 | +import mpos |
| 4 | +from mpos.apps import Activity, Intent |
| 5 | +from .setting_activity import SettingActivity |
| 6 | + |
| 7 | +# Used to list and edit all settings: |
| 8 | +class SettingsActivity(Activity): |
| 9 | + |
| 10 | + # Taken the Intent: |
| 11 | + prefs = None |
| 12 | + settings = None |
| 13 | + |
| 14 | + def onCreate(self): |
| 15 | + self.prefs = self.getIntent().extras.get("prefs") |
| 16 | + self.settings = self.getIntent().extras.get("settings") |
| 17 | + |
| 18 | + print("creating SettingsActivity ui...") |
| 19 | + screen = lv.obj() |
| 20 | + screen.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0) |
| 21 | + screen.set_flex_flow(lv.FLEX_FLOW.COLUMN) |
| 22 | + screen.set_style_border_width(0, 0) |
| 23 | + self.setContentView(screen) |
| 24 | + |
| 25 | + def onResume(self, screen): |
| 26 | + wallet_type = self.prefs.get_string("wallet_type") # might have changed in the settings |
| 27 | + |
| 28 | + # Create settings entries |
| 29 | + screen.clean() |
| 30 | + # Get the group for focusable objects |
| 31 | + focusgroup = lv.group_get_default() |
| 32 | + if not focusgroup: |
| 33 | + print("WARNING: could not get default focusgroup") |
| 34 | + |
| 35 | + for setting in self.settings: |
| 36 | + # Check if it should be shown: |
| 37 | + should_show_function = setting.get("should_show") |
| 38 | + if should_show_function: |
| 39 | + should_show = should_show_function(setting) |
| 40 | + if should_show is False: |
| 41 | + continue |
| 42 | + # Container for each setting |
| 43 | + setting_cont = lv.obj(screen) |
| 44 | + setting_cont.set_width(lv.pct(100)) |
| 45 | + setting_cont.set_height(lv.SIZE_CONTENT) |
| 46 | + setting_cont.set_style_border_width(1, 0) |
| 47 | + #setting_cont.set_style_border_side(lv.BORDER_SIDE.BOTTOM, 0) |
| 48 | + setting_cont.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0) |
| 49 | + setting_cont.add_flag(lv.obj.FLAG.CLICKABLE) |
| 50 | + setting["cont"] = setting_cont # Store container reference for visibility control |
| 51 | + |
| 52 | + # Title label (bold, larger) |
| 53 | + title = lv.label(setting_cont) |
| 54 | + title.set_text(setting["title"]) |
| 55 | + title.set_style_text_font(lv.font_montserrat_16, 0) |
| 56 | + title.set_pos(0, 0) |
| 57 | + |
| 58 | + # Value label (smaller, below title) |
| 59 | + value = lv.label(setting_cont) |
| 60 | + value.set_text(self.prefs.get_string(setting["key"], "(not set)")) |
| 61 | + value.set_style_text_font(lv.font_montserrat_12, 0) |
| 62 | + value.set_style_text_color(lv.color_hex(0x666666), 0) |
| 63 | + value.set_pos(0, 20) |
| 64 | + setting["value_label"] = value # Store reference for updating |
| 65 | + setting_cont.add_event_cb(lambda e, s=setting: self.startSettingActivity(s), lv.EVENT.CLICKED, None) |
| 66 | + setting_cont.add_event_cb(lambda e, container=setting_cont: self.focus_container(container),lv.EVENT.FOCUSED,None) |
| 67 | + setting_cont.add_event_cb(lambda e, container=setting_cont: self.defocus_container(container),lv.EVENT.DEFOCUSED,None) |
| 68 | + if focusgroup: |
| 69 | + focusgroup.add_obj(setting_cont) |
| 70 | + |
| 71 | + def focus_container(self, container): |
| 72 | + print(f"container {container} focused, setting border...") |
| 73 | + container.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN) |
| 74 | + container.set_style_border_width(1, lv.PART.MAIN) |
| 75 | + container.scroll_to_view(True) # scroll to bring it into view |
| 76 | + |
| 77 | + def defocus_container(self, container): |
| 78 | + print(f"container {container} defocused, unsetting border...") |
| 79 | + container.set_style_border_width(0, lv.PART.MAIN) |
| 80 | + |
| 81 | + def startSettingActivity(self, setting): |
| 82 | + intent = Intent(activity_class=SettingActivity) |
| 83 | + intent.putExtra("prefs", self.prefs) |
| 84 | + intent.putExtra("setting", setting) |
| 85 | + self.startActivity(intent) |
0 commit comments