Skip to content

Commit 1e7fc35

Browse files
Simplify
1 parent 062d406 commit 1e7fc35

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
# Used to list and edit all settings:
1313
class Settings(SettingsActivity):
1414

15-
def __init__(self):
16-
super().__init__()
17-
self.prefs = mpos.config.SharedPreferences("com.micropythonos.settings")
15+
"""Override getIntent to provide prefs and settings via Intent extras"""
16+
def getIntent(self):
1817
theme_colors = [
1918
("Aqua Blue", "00ffff"),
2019
("Bitcoin Orange", "f0a010"),
@@ -40,13 +39,19 @@ def __init__(self):
4039
("Teal", "008080"),
4140
("Turquoise", "40e0d0")
4241
]
43-
self.settings = [
42+
# Create a mock intent-like object with extras
43+
class MockIntent:
44+
def __init__(self, extras):
45+
self.extras = extras
46+
47+
return MockIntent({
48+
"prefs": mpos.config.SharedPreferences("com.micropythonos.settings"),
49+
"settings": [
4450
# Basic settings, alphabetically:
4551
{"title": "Light/Dark Theme", "key": "theme_light_dark", "ui": "radiobuttons", "ui_options": [("Light", "light"), ("Dark", "dark")], "changed_callback": self.theme_changed},
4652
{"title": "Theme Color", "key": "theme_primary_color", "placeholder": "HTML hex color, like: EC048C", "ui": "dropdown", "ui_options": theme_colors, "changed_callback": self.theme_changed},
4753
{"title": "Timezone", "key": "timezone", "ui": "dropdown", "ui_options": [(tz, tz) for tz in mpos.time.get_timezones()], "changed_callback": lambda *args: mpos.time.refresh_timezone_preference()},
4854
# Advanced settings, alphabetically:
49-
#{"title": "Audio Output Device", "key": "audio_device", "ui": "radiobuttons", "ui_options": [("Auto-detect", "auto"), ("I2S (Digital Audio)", "i2s"), ("Buzzer (PWM Tones)", "buzzer"), ("Both I2S and Buzzer", "both"), ("Disabled", "null")], "changed_callback": self.audio_device_changed},
5055
{"title": "Auto Start App", "key": "auto_start_app", "ui": "radiobuttons", "ui_options": [(app.name, app.fullname) for app in PackageManager.get_app_list()]},
5156
{"title": "Check IMU Calibration", "key": "check_imu_calibration", "ui": "activity", "activity_class": CheckIMUCalibrationActivity},
5257
{"title": "Calibrate IMU", "key": "calibrate_imu", "ui": "activity", "activity_class": CalibrateIMUActivity},
@@ -56,7 +61,8 @@ def __init__(self):
5661
# This is currently only in the drawer but would make sense to have it here for completeness:
5762
#{"title": "Display Brightness", "key": "display_brightness", "placeholder": "A value from 0 to 100."},
5863
# Maybe also add font size (but ideally then all fonts should scale up/down)
59-
]
64+
]
65+
})
6066

6167
# Change handlers:
6268
def reset_into_bootloader(self, new_value):

internal_filesystem/lib/mpos/ui/settings_activity.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ class SettingsActivity(Activity):
1212
settings = None
1313

1414
def onCreate(self):
15-
# Try to get from Intent first (for apps launched with Intent)
16-
intent = self.getIntent()
17-
if intent and intent.extras:
18-
self.prefs = intent.extras.get("prefs")
19-
self.settings = intent.extras.get("settings")
20-
21-
# If not set from Intent, subclasses should have set them in __init__()
22-
# (for apps that define their own settings)
15+
self.prefs = self.getIntent().extras.get("prefs")
16+
self.settings = self.getIntent().extras.get("settings")
2317

2418
print("creating SettingsActivity ui...")
2519
screen = lv.obj()
@@ -29,11 +23,6 @@ def onCreate(self):
2923
self.setContentView(screen)
3024

3125
def onResume(self, screen):
32-
# If prefs/settings not set yet, they should be set by subclass
33-
if not self.prefs or not self.settings:
34-
print("WARNING: SettingsActivity.onResume() called but prefs or settings not set")
35-
return
36-
3726
# Create settings entries
3827
screen.clean()
3928
# Get the group for focusable objects

0 commit comments

Comments
 (0)