3.4 KiB
3.4 KiB
SettingsPage
Namespace: FrymasterBadgeApp
Base Class: ContentPage
Purpose: Configuration interface for managing file storage paths (Photos, Logos, Images) and global UI theme preferences.
🔑 Constants & Fields
| Name | Type | Access | Description |
|---|---|---|---|
PhotoPathKey |
const string |
private |
Preference key: "PhotoBasePath" |
LogoPathKey |
const string |
private |
Preference key: "LogoBasePath" |
ImagesPathKey |
const string |
private |
Preference key: "ImagesBasePath" |
ThemePrefKey |
const string |
private |
Preference key: "AppTheme" |
🛠 Constructor
SettingsPage()
- Access:
public - Behavior:
- Calls
InitializeComponent(). - Loads current paths and theme via helper methods.
- Wires
ThemePicker.SelectedIndexChangedtoApplyThemeSelection(). - Overrides default back button behavior to navigate
Shell.Current.GoToAsync("..").
- Calls
📦 Methods
LoadCurrentSettings()
- Access:
private - Behavior: Reads photo, logo, and image paths from
Preferences.Default. Falls back toC:\FrymasterData\...and populates corresponding UI entries.
LoadCurrentThemePreference()
- Access:
private - Behavior: Reads
"AppTheme"preference. Maps toLight/Dark/System, updatesThemePicker.SelectedIndexandApplication.Current.UserAppTheme.
ApplyThemeSelection()
- Access:
private - Behavior: Reads
ThemePicker.SelectedIndex. UpdatesUserAppThemeand persists selection toPreferences.Default. Handles null picker defensively.
OnPickPhotoFolderClicked, OnPickLogoFolderClicked, OnPickImagesFolderClicked
- Access:
private async void - Behavior: Wrappers that invoke
PickFolderAsyncwith specific update callbacks and dialog titles.
PickFolderAsync(Action<FolderPickerResult> onSuccess, string title)
- Access:
private async Task - Parameters:
onSuccess(Action<FolderPickerResult>) – Callback on successful selection.title(string) – Picker dialog title.
- Behavior: Invokes
FolderPicker.Default.PickAsync(). On success, executes callback and callsVerifyDirectory(). Catches and displays alerts on failure.
OnSaveClicked(object sender, EventArgs e)
- Access:
private async void - Behavior:
- Trims and validates all three paths. Alerts if any are empty.
- Saves paths to
Preferences.Default. - Updates
StatusLabelwith success/error message and color. - Shows
Toast(non-critical, wrapped in try/catch). - Intentionally omits auto-navigation to prevent known Shell navigation crashes.
- Logs extensively via
AppLogger.
SafeCreateDirectory(string path)
- Access:
private static - Behavior: (Commented out in current code but present) Creates directory if missing. Logs failures but suppresses crashes.
VerifyDirectory(string path)
- Access:
private static - Behavior: Checks
Directory.Exists(path). Creates it if missing. Used immediately after folder selection.
💡 Developer Notes:
- Uses
CommunityToolkit.Maui.AlertsandStoragefor modern picker/toast functionality. - Hardcoded fallback paths (
C:\FrymasterData\...) should be platform-aware for iOS/macOS/Android. - Explicitly avoids
Shell.Current.GoToAsync("..")after save to maintain navigation stability.