From 3999f7c1e8538fc567fc4a412d925e3675e2b001 Mon Sep 17 00:00:00 2001 From: SunboX Date: Wed, 31 May 2017 23:43:07 +0200 Subject: [PATCH] fix theming --- NextcloudApp/App.xaml.cs | 11 --- NextcloudApp/AppShell.xaml | 6 +- NextcloudApp/AppShell.xaml.cs | 2 +- NextcloudApp/Controls/ThemeablePage.cs | 44 ++++++++++ NextcloudApp/Models/RoamingSettings.cs | 18 +--- NextcloudApp/NextcloudApp.csproj | 2 +- NextcloudApp/Services/StatusBarService.cs | 47 ++++++++++- .../ViewModels/SettingsPageViewModel.cs | 84 ++++++++----------- NextcloudApp/Views/DirectoryListPage.xaml | 1 + NextcloudApp/Views/DirectoryListPage.xaml.cs | 4 +- NextcloudApp/Views/SettingsPage.xaml.cs | 25 ++---- 11 files changed, 144 insertions(+), 100 deletions(-) create mode 100644 NextcloudApp/Controls/ThemeablePage.cs diff --git a/NextcloudApp/App.xaml.cs b/NextcloudApp/App.xaml.cs index 379dd68..7e18825 100644 --- a/NextcloudApp/App.xaml.cs +++ b/NextcloudApp/App.xaml.cs @@ -226,17 +226,6 @@ namespace NextcloudApp ActivatedEventArgs = args; await base.OnActivateApplicationAsync(args); - var theme = SettingsService.Instance.RoamingSettings.Theme; - switch (theme) - { - case Theme.Dark: - RequestedTheme = ApplicationTheme.Dark; - break; - case Theme.Light: - RequestedTheme = ApplicationTheme.Light; - break; - } - // Remove unnecessary notifications whenever the app is used. ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCACTION); diff --git a/NextcloudApp/AppShell.xaml b/NextcloudApp/AppShell.xaml index d58fda3..a55c335 100644 --- a/NextcloudApp/AppShell.xaml +++ b/NextcloudApp/AppShell.xaml @@ -1,10 +1,11 @@ - @@ -51,4 +52,5 @@ Style="{StaticResource SplitViewTogglePaneButtonStyle}" TabIndex="1" /> - + + diff --git a/NextcloudApp/AppShell.xaml.cs b/NextcloudApp/AppShell.xaml.cs index d49efe3..f0a3223 100644 --- a/NextcloudApp/AppShell.xaml.cs +++ b/NextcloudApp/AppShell.xaml.cs @@ -4,7 +4,7 @@ using NextcloudApp.Services; namespace NextcloudApp { - public sealed partial class AppShell : Page + public sealed partial class AppShell { public AppShell() { diff --git a/NextcloudApp/Controls/ThemeablePage.cs b/NextcloudApp/Controls/ThemeablePage.cs new file mode 100644 index 0000000..a754429 --- /dev/null +++ b/NextcloudApp/Controls/ThemeablePage.cs @@ -0,0 +1,44 @@ +using System.ComponentModel; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using NextcloudApp.Services; +using NextcloudApp.Utils; + +namespace NextcloudApp.Controls +{ + public class ThemeablePage : Page + { + public ThemeablePage() + { + var theme = SettingsService.Instance.RoamingSettings.Theme; + switch (theme) + { + case Theme.Dark: + RequestedTheme = ElementTheme.Dark; + break; + case Theme.Light: + RequestedTheme = ElementTheme.Light; + break; + } + + SettingsService.Instance.RoamingSettings.PropertyChanged += RoamingSettingsOnPropertyChanged; + } + + private void RoamingSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("Theme")) + { + var theme = SettingsService.Instance.RoamingSettings.Theme; + switch (theme) + { + case Theme.Dark: + RequestedTheme = ElementTheme.Dark; + break; + case Theme.Light: + RequestedTheme = ElementTheme.Light; + break; + } + } + } + } +} diff --git a/NextcloudApp/Models/RoamingSettings.cs b/NextcloudApp/Models/RoamingSettings.cs index 5935595..c569714 100644 --- a/NextcloudApp/Models/RoamingSettings.cs +++ b/NextcloudApp/Models/RoamingSettings.cs @@ -8,17 +8,8 @@ namespace NextcloudApp.Models /// Class for storing roaming settings which should be synchronized between devices. /// public class RoamingSettings : ObservableSettings - { - private static RoamingSettings settings = new RoamingSettings(); - private const string DefaultValueEmptyString = ""; - - public static RoamingSettings Default - { - get - { - return settings; - } - } + { + public static RoamingSettings Default { get; } = new RoamingSettings(); public RoamingSettings() : base(ApplicationData.Current.RoamingSettings) @@ -33,10 +24,7 @@ namespace NextcloudApp.Models { var strVal = Get(); - if (string.IsNullOrEmpty(strVal)) - return Theme.System; - else - return JsonConvert.DeserializeObject(strVal); + return string.IsNullOrEmpty(strVal) ? Theme.System : JsonConvert.DeserializeObject(strVal); } set { diff --git a/NextcloudApp/NextcloudApp.csproj b/NextcloudApp/NextcloudApp.csproj index 05c17aa..5ce9b93 100644 --- a/NextcloudApp/NextcloudApp.csproj +++ b/NextcloudApp/NextcloudApp.csproj @@ -134,6 +134,7 @@ + @@ -401,7 +402,6 @@ - diff --git a/NextcloudApp/Services/StatusBarService.cs b/NextcloudApp/Services/StatusBarService.cs index 36034d8..fc930cf 100644 --- a/NextcloudApp/Services/StatusBarService.cs +++ b/NextcloudApp/Services/StatusBarService.cs @@ -1,6 +1,9 @@ using System; +using System.ComponentModel; using Windows.Foundation.Metadata; +using Windows.UI; using Windows.UI.ViewManagement; +using NextcloudApp.Utils; namespace NextcloudApp.Services { @@ -9,7 +12,49 @@ namespace NextcloudApp.Services private static StatusBarService _instance; private int _waitCounter; - private StatusBarService() { } + private StatusBarService() + { + if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) + { + var statusBar = StatusBar.GetForCurrentView(); + statusBar.BackgroundOpacity = 1; + var theme = SettingsService.Instance.RoamingSettings.Theme; + switch (theme) + { + case Theme.Dark: + statusBar.BackgroundColor = Colors.Black; + statusBar.ForegroundColor = Colors.White; + break; + case Theme.Light: + statusBar.BackgroundColor = Colors.White; + statusBar.ForegroundColor = Colors.Black; + break; + } + + SettingsService.Instance.RoamingSettings.PropertyChanged += RoamingSettingsOnPropertyChanged; + } + } + + private void RoamingSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("Theme")) + { + var statusBar = StatusBar.GetForCurrentView(); + statusBar.BackgroundOpacity = 1; + var theme = SettingsService.Instance.RoamingSettings.Theme; + switch (theme) + { + case Theme.Dark: + statusBar.BackgroundColor = Colors.Black; + statusBar.ForegroundColor = Colors.White; + break; + case Theme.Light: + statusBar.BackgroundColor = Colors.White; + statusBar.ForegroundColor = Colors.Black; + break; + } + } + } public static StatusBarService Instance => _instance ?? (_instance = new StatusBarService()); diff --git a/NextcloudApp/ViewModels/SettingsPageViewModel.cs b/NextcloudApp/ViewModels/SettingsPageViewModel.cs index d98bd83..352b887 100644 --- a/NextcloudApp/ViewModels/SettingsPageViewModel.cs +++ b/NextcloudApp/ViewModels/SettingsPageViewModel.cs @@ -132,20 +132,20 @@ namespace NextcloudApp.ViewModels public string ServerVersion { - get { return _serverVersion; } - private set { SetProperty(ref _serverVersion, value); } + get => _serverVersion; + private set => SetProperty(ref _serverVersion, value); } public LocalSettings SettingsLocal { - get { return _settingsLocal; } - private set { SetProperty(ref _settingsLocal, value); } + get => _settingsLocal; + private set => SetProperty(ref _settingsLocal, value); } public RoamingSettings SettingsRoaming { - get { return _settingsRoaming; } - private set { SetProperty(ref _settingsRoaming, value); } + get => _settingsRoaming; + private set => SetProperty(ref _settingsRoaming, value); } public List PreviewImageDownloadModes { get; } = new List(); @@ -155,7 +155,7 @@ namespace NextcloudApp.ViewModels public int PreviewImageDownloadModesSelectedIndex { - get { return _previewImageDownloadModesSelectedIndex; } + get => _previewImageDownloadModesSelectedIndex; set { if (!SetProperty(ref _previewImageDownloadModesSelectedIndex, value)) @@ -180,7 +180,7 @@ namespace NextcloudApp.ViewModels public int ThemeModeSelectedIndex { - get { return _themeModesSelectedIndex; } + get => _themeModesSelectedIndex; set { if (!SetProperty(ref _themeModesSelectedIndex, value)) @@ -205,7 +205,7 @@ namespace NextcloudApp.ViewModels public bool IgnoreServerCertificateErrors { - get { return _ignoreServerCertificateErrors; } + get => _ignoreServerCertificateErrors; set { if (!SetProperty(ref _ignoreServerCertificateErrors, value)) @@ -235,29 +235,9 @@ namespace NextcloudApp.ViewModels PrismUnityApplication.Current.Exit(); } - public async void ThemeChanged() - { - ClientService.Reset(); - - var dialog = new ContentDialog - { - Title = _resourceLoader.GetString("Hint"), - Content = new TextBlock - { - Text = _resourceLoader.GetString("AppMustBeRestarted"), - TextWrapping = TextWrapping.WrapWholeWords, - Margin = new Thickness(0, 20, 0, 0) - }, - PrimaryButtonText = _resourceLoader.GetString("OK") - }; - - await _dialogService.ShowAsync(dialog); - PrismUnityApplication.Current.Exit(); - } - public bool ExpertMode { - get { return _expertMode; } + get => _expertMode; set { if (!SetProperty(ref _expertMode, value)) @@ -269,7 +249,7 @@ namespace NextcloudApp.ViewModels public bool UseWindowsHello { - get { return _useWindowsHello; } + get => _useWindowsHello; set { if (!SetProperty(ref _useWindowsHello, value)) @@ -281,28 +261,30 @@ namespace NextcloudApp.ViewModels public async void UseWindowsHelloToggled() { - if (UseWindowsHello) + if (!UseWindowsHello) { - var available = await VerificationService.CheckAvailabilityAsync(); - - if (!available) - { - var dialog = new ContentDialog - { - Title = _resourceLoader.GetString(ResourceConstants.DialogTitle_GeneralNextCloudApp), - Content = new TextBlock - { - Text = _resourceLoader.GetString(ResourceConstants.WindowsHelloNotAvailable), - TextWrapping = TextWrapping.WrapWholeWords, - Margin = new Thickness(0, 20, 0, 0) - }, - PrimaryButtonText = _resourceLoader.GetString("OK") - }; - await _dialogService.ShowAsync(dialog); - - UseWindowsHello = false; - } + return; } + var available = await VerificationService.CheckAvailabilityAsync(); + + if (available) + { + return; + } + var dialog = new ContentDialog + { + Title = _resourceLoader.GetString(ResourceConstants.DialogTitle_GeneralNextCloudApp), + Content = new TextBlock + { + Text = _resourceLoader.GetString(ResourceConstants.WindowsHelloNotAvailable), + TextWrapping = TextWrapping.WrapWholeWords, + Margin = new Thickness(0, 20, 0, 0) + }, + PrimaryButtonText = _resourceLoader.GetString("OK") + }; + await _dialogService.ShowAsync(dialog); + + UseWindowsHello = false; } public string AppVersion diff --git a/NextcloudApp/Views/DirectoryListPage.xaml b/NextcloudApp/Views/DirectoryListPage.xaml index b694914..c815120 100644 --- a/NextcloudApp/Views/DirectoryListPage.xaml +++ b/NextcloudApp/Views/DirectoryListPage.xaml @@ -506,3 +506,4 @@ + diff --git a/NextcloudApp/Views/DirectoryListPage.xaml.cs b/NextcloudApp/Views/DirectoryListPage.xaml.cs index 1bdf747..4a64d44 100644 --- a/NextcloudApp/Views/DirectoryListPage.xaml.cs +++ b/NextcloudApp/Views/DirectoryListPage.xaml.cs @@ -1,8 +1,8 @@ -using Prism.Windows.Mvvm; +using NextcloudApp.Controls; namespace NextcloudApp.Views { - public sealed partial class DirectoryListPage : SessionStateAwarePage + public sealed partial class DirectoryListPage { public DirectoryListPage() { diff --git a/NextcloudApp/Views/SettingsPage.xaml.cs b/NextcloudApp/Views/SettingsPage.xaml.cs index 55cfc37..0f57aad 100644 --- a/NextcloudApp/Views/SettingsPage.xaml.cs +++ b/NextcloudApp/Views/SettingsPage.xaml.cs @@ -1,17 +1,10 @@ -using System; -using System.Collections.ObjectModel; -using System.Diagnostics; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; -using Prism.Windows.Mvvm; - -namespace NextcloudApp.Views -{ - public sealed partial class SettingsPage : SessionStateAwarePage - { - public SettingsPage() - { - InitializeComponent(); +namespace NextcloudApp.Views +{ + public sealed partial class SettingsPage + { + public SettingsPage() + { + InitializeComponent(); } - } -} + } +}