Beispiel #1
0
        /// <summary>
        /// Sets the theme for the app.
        /// </summary>
        async Task SetAppTheme(AppThemeViewModel theme)
        {
            try
            {
                Application.Current.UserAppTheme = theme.Key;
                Settings.AppTheme = theme.Key;

                foreach (var item in AppThemes)
                {
                    item.IsSelected = false;
                }

                AppThemes.FirstOrDefault(x => x.Key == Settings.AppTheme).IsSelected = true;
                RaisePropertyChanged(nameof(AppThemes));

                //var statusBar = DependencyService.Get<IStatusBar>();
                //statusBar?.SetStatusBarColor((OSAppTheme)theme.Key, Color.Black);

                HapticFeedback.Perform(HapticFeedbackType.Click);

                AnalyticsService.Track("App Theme Changed", nameof(theme), ((OSAppTheme)theme.Key).ToString() ?? "null");
            }
            catch (Exception ex)
            {
                await DialogService.AlertAsync(Translations.error_couldntchangetheme, Translations.error_title, Translations.ok).ConfigureAwait(false);

                AnalyticsService.Report(ex);
            }
        }
Beispiel #2
0
 private static void SaveThemeInSettings(AppThemes theme)
 {
     if (!SettingsService.Instance.UseSystemAppTheme)
     {
         SettingsService.Instance.AppTheme = (ApplicationTheme)theme;
     }
 }
Beispiel #3
0
        void SetAppTheme(AppThemeViewModel theme)
        {
            foreach (var item in AppThemes)
            {
                item.IsSelected = false;
            }

            switch (theme.Key)
            {
            case 0:
                Application.Current.UserAppTheme = OSAppTheme.Unspecified;
                Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Unspecified);
                break;

            case 1:
                Application.Current.UserAppTheme = OSAppTheme.Light;
                Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Light);
                break;

            case 2:
                Application.Current.UserAppTheme = OSAppTheme.Dark;
                Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Dark);
                break;

            default:
                break;
            }

            AppThemes.FirstOrDefault(x => x.Key == Preferences.Get(Settings.AppTheme, Settings.AppThemeDefault)).IsSelected = true;
            RaisePropertyChanged(nameof(AppThemes));
        }
Beispiel #4
0
        public SettingsWindowViewModel() : base()
        {
            AccentColors = ThemeManager.Current.Themes
                           .GroupBy(x => x.ColorScheme)
                           .OrderBy(a => a.Key)
                           .Select(a => new AccentColorMenuData {
                Name = a.Key, ColorBrush = a.First().ShowcaseBrush
            })
                           .ToList();
            AccentColor = AccentColors.First(x => x.Name == App.Theme.ColorScheme);
            AppThemes   = ThemeManager.Current.Themes
                          .GroupBy(x => x.BaseColorScheme)
                          .Select(x => x.First())
                          .Select(a => new AppThemeMenuData {
                Name = a.BaseColorScheme, BorderColorBrush = a.Resources["MahApps.Brushes.ThemeForeground"] as Brush, ColorBrush = a.Resources["MahApps.Brushes.ThemeBackground"] as Brush
            })
                          .ToList();
            AppTheme = AppThemes.First(x => x.Name == App.Theme.BaseColorScheme);
            var resources = App.Theme.LibraryThemes.First(x => x.Origin == "MahApps.Metro").Resources.MergedDictionaries.First();

            Colors = typeof(Colors).GetProperties(BindingFlags.Public | BindingFlags.Static)
                     .Where(x => x.Name != "Transparent")
                     .Select(x => new AccentColorMenuData {
                Name = x.Name, ColorBrush = new SolidColorBrush((Color)x.GetValue(null))
            })
                     .ToList();
        }
Beispiel #5
0
        public void Apply(ApplicationDesign design)
        {
            try
            {
                design.AccentColor.ApplyTheme();
            }
            catch (Exception)
            {
                design.AccentColor = AccentColors.First(x => x.Name == "Blue");
                design.AccentColor.ApplyTheme();
            }

            try
            {
                design.AppTheme.ApplyTheme();
            }
            catch (Exception)
            {
                design.AppTheme = AppThemes.First();
                design.AppTheme.ApplyTheme();
            }

            if (design.AudioVisualisation != null)
            {
                design.AudioVisualisation.AudioVisualisationPlugin.Refresh();
            }
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="SettingsViewModel"/> class.
    /// </summary>
    /// <param name="logger">Logger dependency.</param>
    /// <param name="localization">Localization provider dependency.</param>
    /// <param name="options">Surrent settings.</param>
    /// <param name="settingsService">Settings service dependency.</param>
    public SettingsViewModel(ILogger logger,
                             ILocalization localization,
                             AppSettings options,
                             SettingsService settingsService)
    {
        CultureSelectionChangedCommand = new DelegateCommand(ChangeCulture);
        this.logger          = logger;
        this.localization    = localization;
        this.options         = options;
        this.settingsService = settingsService;

        AppThemes = ThemeManager.Current.Themes
                    .GroupBy(x => x.BaseColorScheme)
                    .Select(x => x.First())
                    .ToList();

        ColorThemes = ThemeManager.Current.ColorSchemes.OrderBy(x => x).ToList();

        Theme?currentTheme = ThemeManager.Current.DetectTheme();

        if (currentTheme != null)
        {
            SelectedAppTheme = AppThemes.First(x => x.BaseColorScheme == currentTheme.BaseColorScheme);
            SelectedColor    = ColorThemes.First(x => x == currentTheme.ColorScheme);
        }

        ShowLastWeekSuggestion = options.ShowLastWeekSuggestion;
    }
Beispiel #7
0
        public ThemePickerViewModel(IAnalyticsService analyticsService, IAuthService authService,
                                    IDialogService dialogService, INavigationHelper navigationHelper)
            : base(analyticsService, authService, dialogService, navigationHelper)
        {
            SetAppThemeCommand = new Command <AppThemeViewModel>((x) => SetAppTheme(x));

            AppThemes.FirstOrDefault(x => x.Key == Preferences.Get(Settings.AppTheme, Settings.AppThemeDefault)).IsSelected = true;
        }
Beispiel #8
0
        /// <summary>
        /// Update the selected item property for each theme/accent when the theme/accent is changed
        /// </summary>
        private void ThemeManager_IsThemeChanged(object sender, OnThemeChangedEventArgs e)
        {
            OnPropertyChanged("CurrentAppTheme");
            OnPropertyChanged("CurrentAppAccent");

            AppThemes.ForEach(t => t.IsSelectedItem    = (t == CurrentAppTheme));
            AccentColors.ForEach(a => a.IsSelectedItem = (a == CurrentAppAccent));
        }
Beispiel #9
0
        public static void SetTheme(AppThemes theme)
        {
            Theme = theme;

            SetRequestedTheme();
            SaveThemeInSettings(Theme);

            OnThemeChanged(null, Theme);
        }
 private void LoadDefaults()
 {
     if (!this.IsInDesignMode)
     {
         SelectedAppTheme     = AppThemes.FirstOrDefault(at => at.Name == App.SelectedAppTheme.Name);
         SelectedAccent       = AccentColors.FirstOrDefault(ac => ac.Name == App.SelectedAccent.Name);
         SelectedLang         = App.Language;
         App.LanguageChanged += AppOnLanguageChanged;
     }
 }
        /// <summary>
        /// Load the saved theme and accent
        /// </summary>
        public void LoadSavedTheme()
        {
            // Get the saved theme and accent
            AppThemeMenuData    savedTheme  = AppThemes.Where(t => t.Name == Properties.Settings.Default.AppTheme).FirstOrDefault();
            AccentColorMenuData savedAccent = AccentColors.Where(a => a.Name == Properties.Settings.Default.AppAccent).FirstOrDefault();

            // Change to the saved theme and accent
            savedTheme?.ChangeAccentCommand.Execute(null);
            savedAccent?.ChangeAccentCommand.Execute(null);
        }
        public static void SetDefaultResources(AppThemes appThemes)
        {
            var styleSource = StyleSelector(appThemes);
            foreach (var item in styleSource)
            {
                var source =  item;
                Extensions.SetResource(source);

            }
        }
Beispiel #13
0
        public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }

            AppTheme appTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]);

            ChangeAppStyle(resources, newAccent, appTheme);
        }
Beispiel #14
0
        public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            var      oldTheme    = DetectTheme(window);
            AppTheme oldAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[oldTheme.Item1]);
            AppTheme newAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]);

            ChangeAppStyle(window.Resources, Tuple.Create(oldAppTheme, oldTheme.Item2), newAccent, newAppTheme);
        }
Beispiel #15
0
        private void WindowThemeUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Window window = Window.GetWindow(this);

            window.Closing += window_Closing;

            // Get the saved theme and accent
            AppThemeMenuData    savedTheme  = AppThemes.Where(t => t.Name == Properties.Settings.Default.AppTheme).FirstOrDefault();
            AccentColorMenuData savedAccent = AccentColors.Where(a => a.Name == Properties.Settings.Default.AppAccent).FirstOrDefault();

            // Change to the saved theme and accent
            savedTheme?.ChangeAccentCommand.Execute(null);
            savedAccent?.ChangeAccentCommand.Execute(null);
        }
Beispiel #16
0
        private static AppThemes LoadThemeFromSettings()
        {
            AppThemes cacheTheme = AppThemes.System;

            if (!SettingsService.Instance.UseSystemAppTheme)
            {
                cacheTheme = (AppThemes)SettingsService.Instance.AppTheme;
            }
            else
            {
                cacheTheme = (AppThemes)SettingsService.Instance.SystemTheme;
            }

            return(cacheTheme);
        }
        private static IEnumerable<string> StyleSelector(AppThemes appThemes)
        {
            IEnumerable<string> styleSource;
            switch (appThemes)
            {
                case AppThemes.Red:
                    styleSource = RedTheme.GetFilePaths();
                    break;

                case AppThemes.Blue:
                default:
                    styleSource = BlueThemes.GetFilePaths();
                    break;
            }

            return styleSource;
        }
Beispiel #18
0
        /// <summary>
        /// Selects The Theme To Display.
        /// </summary>
        /// <param name="ThemeName">The Theme Name.</param>
        public void SelectTheme(string ThemeName)
        {
            //Make Sure It Exists
            if (!AppThemes.ContainsKey(ThemeName))
            {
                throw new KeyNotFoundException($"The Specified Theme Name, {ThemeName} Could Not Be Located.");
            }

            //Set Theme
            CurrentThemeName = ThemeName;

            //Check If Event Exists
            if (AppThemeChange != null)
            {
                //Update Event
                AppThemeChange.Invoke(this, new ThemeChangeArgs(ThemeName, CurrentTheme));
            }
        }
        public void LoadData()
        {
            ThemeAccents = ThemeManager.Accents
                           .Select(a => new Utils.Theme {
                ColorName = a.Name, BrushTheme = a.Resources["AccentColorBrush"] as Brush
            })
                           .ToList();
            AppThemes = ThemeManager.AppThemes
                        .Select(a => new Utils.Theme {
                ColorName = a.Name, BrushBorder = a.Resources["BlackColorBrush"] as Brush, BrushTheme = a.Resources["WhiteColorBrush"] as Brush
            })
                        .ToList();
            SelectedThemeColor = ThemeAccents.SingleOrDefault(c => c.ColorName == Settings.Default.ThemeColor);
            SelectedThemeStyle = AppThemes.SingleOrDefault(c => c.ColorName == Settings.Default.ThemeStyle);


            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ThemeAccents)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(AppThemes)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedThemeColor)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedThemeStyle)));
        }
Beispiel #20
0
    public static void SelectTheme(AppThemes theme = AppThemes.Light)
    {
        if (theme == AppThemes.FollowSystem)
        {
            theme = IsSystemUsingDarkTheme() ? AppThemes.Dark : AppThemes.Light;
        }

        //Checks if the theme is already the current in use.
        var last = Application.Current.Resources.MergedDictionaries.LastOrDefault(l => l.Source != null && l.Source.ToString().Contains("Colors/"));

        if (last?.Source.ToString().EndsWith($"/{theme}.xaml") == true)
        {
            return;
        }

        //Tries to switch to the new theme.
        var res = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith($"Colors/{theme}.xaml"));

        if (res == null)
        {
            res = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith("Colors/Light.xaml"));
            UserSettings.All.MainTheme = AppThemes.Light;
        }

        Application.Current.Resources.MergedDictionaries.Remove(res);
        Application.Current.Resources.MergedDictionaries.Add(res);

        //Forces the refresh of the vectors with dynamic resources inside.
        var glyphs = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith("Resources/Glyphs.xaml"));

        Application.Current.Resources.MergedDictionaries.Remove(glyphs);
        Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
            Source = new System.Uri("Resources/Glyphs.xaml", System.UriKind.RelativeOrAbsolute)
        });

        RefreshNotificationIcon();
    }
Beispiel #21
0
 private void SetTheme(AppThemes theme)
 {
     Uri uri;
     switch (theme) {
         case AppThemes.Aero:
             uri = new Uri("PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/Aero.NormalColor.xaml", UriKind.Relative);
             break;
         case AppThemes.Luna:
             uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.NormalColor.xaml", UriKind.Relative);
             break;
         case AppThemes.LunaHomestead:
             uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.Homestead.xaml", UriKind.Relative);
             break;
         case AppThemes.LunaMetallic:
             uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.Metallic.xaml", UriKind.Relative);
             break;
         case AppThemes.Royale:
             uri = new Uri("PresentationFramework.Royale;V3.0.0.0;31bf3856ad364e35;component\\themes/Royale.NormalColor.xaml", UriKind.Relative);
             break;
         default:
             return;
     }
     Resources.MergedDictionaries.Add(LoadComponent(uri) as ResourceDictionary);
 }
Beispiel #22
0
 public static void Initialize()
 {
     Theme = LoadThemeFromSettings();
 }
Beispiel #23
0
 public ThemePickerViewModel(IAnalyticsService analyticsService)
     : base(analyticsService)
 {
     SetAppThemeCommand = new AsyncCommand <AppThemeViewModel>((x) => SetAppTheme(x));
     AppThemes.FirstOrDefault(x => x.Key == Settings.AppTheme).IsSelected = true;
 }