Exemple #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);
            }
        }
Exemple #2
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));
        }