using System.Collections.ObjectModel; using System.Windows.Input; using Microsoft.Maui.Controls; using Microsoft.Maui.Storage; namespace galacticlip_app { public class SharedResourceDictionary : ResourceDictionary { } public class SettingsViewModel : BindableObject { private string _userName; private string _selectedBackground; private bool _darkMode; private string _interfaceLanguage; private string _interfaceFont; private double _interfaceFontSize; private bool _isPortrait; // TEST: careful with this private bool _isLandscape; // TEST: careful with this public string UserName { get => _userName; set { _userName = value; Preferences.Set("UserName", value); MessagingCenter.Send(this, "UserNameUpdated", value); OnPropertyChanged(); } } private string _selectedProfilePhoto; // CAREFUL WITH THIS FOLLOWING CODE BLOCK @ PROFILE PHOTO public ObservableCollection AvailableProfilePhotos { get; } = new ObservableCollection { "Star Explorer", "Cosmic Voyager", "Galaxy Dreamer" }; // Selected profile photo (binding target) public string SelectedProfilePhoto { get => _selectedProfilePhoto; set { _selectedProfilePhoto = value; OnPropertyChanged(); // Update the profile image when selection changes UpdateProfilePhoto(value); } } // Current profile photo resource path private string _userProfilePhoto = "profile1.png"; public string UserProfilePhoto { get => _userProfilePhoto; private set { _userProfilePhoto = value; Preferences.Set("UserProfilePhoto", value); OnPropertyChanged(); } } // Update the profile photo based on selection private void UpdateProfilePhoto(string profileName) { // Map the profile name to the corresponding image file UserProfilePhoto = profileName switch { "Star Explorer" => "profile1.png", "Cosmic Voyager" => "profile2.png", "Galaxy Dreamer" => "profile3.png", _ => "profile1.png" // Default to the first profile }; } // END OF CAREFUL CODE BLOCK @ PROFILE PHOTO public bool DarkMode { get => _darkMode; set { if (_darkMode != value) { _darkMode = value; Preferences.Set("DarkMode", value); // Apply the theme change if (Application.Current is App app) { app.ApplyTheme(); } } } } public ObservableCollection AvailableLanguages { get; set; } = new() { "English", "Korean", "Simplified Chinese", "Spanish" }; public string InterfaceLanguage { get => _interfaceLanguage; set { _interfaceLanguage = value; Preferences.Set("InterfaceLanguage", value); OnPropertyChanged(); ApplyLanguage(); } } public ObservableCollection AvailableFonts { get; set; } = new() { "Roboto", "Playfair", "Doto" }; public ObservableCollection FontSizes { get; } = new() { 12, 16, 20 }; private string _selectedFont; public string SelectedFont { get => _selectedFont; set { if (_selectedFont != value) { _selectedFont = value; Preferences.Set("AppFontFamily", value); // Update the resource key dynamically MainThread.BeginInvokeOnMainThread(() => { var newDictionary = new ResourceDictionary(); newDictionary.Add("AppFontFamily", value); Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Add(newDictionary); }); OnPropertyChanged(); } } } private int _selectedFontSize; public int SelectedFontSize { get => _selectedFontSize; set { _selectedFontSize = value; Preferences.Set("AppFontSize", value); // Update global resources Application.Current.Resources["MediumFontSize"] = value; OnPropertyChanged(); } } public ObservableCollection AvailableBackgrounds { get; set; } = new() { "Default", "Galaxy", "Space" }; public string SelectedBackground { get => _selectedBackground; set { _selectedBackground = value; Preferences.Set("BackgroundPreference", value); OnPropertyChanged(); } } // CAREFUL WITH THIS FOLLOWING CODE BLOCK public bool IsPortrait { get => _isPortrait; set { if (_isPortrait != value) { _isPortrait = value; OnPropertyChanged(); } } } public bool IsLandscape { get => _isLandscape; set { if (_isLandscape != value) { _isLandscape = value; OnPropertyChanged(); } } } // END OF CAREFUL CODE BLOCK public string AppVersion { get; set; } = "1.0.0"; public string SupportEmail { get; set; } = "support@example.invalid"; public ICommand ClearBookmarksCommand { get; } public SettingsViewModel() { // Safely initialize settings from preferences _userName = Preferences.Get("UserName", "Guest"); _darkMode = Preferences.Get("DarkMode", false); _interfaceLanguage = Preferences.Get("InterfaceLanguage", "English"); _selectedFont = Preferences.Get("AppFontFamily", "Roboto"); _selectedFontSize = Preferences.Get("AppFontSize", 16); _userProfilePhoto = Preferences.Get("UserProfilePhoto", "profile1.png"); _selectedBackground = Preferences.Get("BackgroundPreference", "Default"); ClearBookmarksCommand = new Command(ClearBookmarks); // CAREFUL WITH THIS FOLLOWING CODE BLOCK UpdateOrientation(DeviceDisplay.MainDisplayInfo.Orientation); DeviceDisplay.MainDisplayInfoChanged += OnDisplayInfoChanged; // END OF CAREFUL CODE BLOCK } // CAREFUL WITH THIS FOLLOWING CODE BLOCK private void OnDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e) { UpdateOrientation(e.DisplayInfo.Orientation); } private void UpdateOrientation(DisplayOrientation orientation) { IsPortrait = orientation == DisplayOrientation.Portrait; IsLandscape = orientation == DisplayOrientation.Landscape; } // END OF CAREFUL CODE BLOCK private void ClearBookmarks() { // Clear bookmarks from Preferences Preferences.Remove("BookmarkedItems"); // Notify other parts of the app to react AppMessenger.SendMessage("ClearBookmarks"); // Notify user App.Current.MainPage.DisplayAlert("Bookmarks", "All bookmarks have been cleared.", "OK"); } private void ApplyLanguage() { // Dynamic language switching: Due to time and resources constraits a full multi-language implementation is not complete. System.Diagnostics.Debug.WriteLine($"Language switched to: {InterfaceLanguage}"); } } }