From 7beb4aea2c76d94161decd701fca075b2bd37f39 Mon Sep 17 00:00:00 2001 From: Eric Tian Date: Fri, 5 Mar 2021 20:53:14 -0800 Subject: [PATCH] Clean up #3 --- src/Calculator/App.xaml.cpp | 2 ++ src/Calculator/SettingsPage.xaml.cpp | 31 +++++++++++++++++++++------- src/Calculator/SettingsPage.xaml.h | 1 - 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index d7ef2824..dfcf61dd 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -71,7 +71,9 @@ App::App() this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); + // Reset restartApp and currentTheme Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"restartApp", nullptr); + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"currentTheme", nullptr); auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting"); auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings(); diff --git a/src/Calculator/SettingsPage.xaml.cpp b/src/Calculator/SettingsPage.xaml.cpp index 1eb83384..57c12cdb 100644 --- a/src/Calculator/SettingsPage.xaml.cpp +++ b/src/Calculator/SettingsPage.xaml.cpp @@ -30,8 +30,10 @@ SettingsPage::SettingsPage() auto resourceLoader = AppResourceProvider::GetInstance(); auto themevalue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting"); auto restartValue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"restartApp"); + auto currentThemeValue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"CurrentTheme"); String ^ colorSetting = safe_cast(themevalue); String ^ restartApp = safe_cast(restartValue); + String ^ currentTheme = safe_cast(currentThemeValue); InitializeComponent(); @@ -45,23 +47,35 @@ SettingsPage::SettingsPage() if (colorSetting == L"Light") { SettingsLightTheme->IsChecked = true; - m_currentTheme = "Light"; + if (currentTheme == nullptr) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"CurrentTheme", L"Light"); + } } else if (colorSetting == L"Dark") { SettingsDarkTheme->IsChecked = true; - m_currentTheme = "Dark"; + if (currentTheme == nullptr) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"CurrentTheme", L"Dark"); + } } else if (colorSetting == L"System") { SettingsSystemTheme->IsChecked = true; - m_currentTheme = "System"; + if (currentTheme == nullptr) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"CurrentTheme", L"System"); + } } } else { SettingsSystemTheme->IsChecked = true; - m_currentTheme = "System"; + if (currentTheme == nullptr) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"CurrentTheme", L"System"); + } } if (restartValue != nullptr) @@ -98,7 +112,7 @@ void SettingsPage::SetDefaultFocus() void SettingsPage::InitializeContributeTextBlock() { auto resourceLoader = AppResourceProvider::GetInstance(); - std::wstring contributeHyperlinkText = resourceLoader->GetResourceString(L"SettingsContribute")->Data(); + std::wstring contributeHyperlinkText = resourceLoader->GetResourceString("SettingsContribute")->Data(); // The resource string has '%HL%' wrapped around 'GitHub' // Break the string and assign pieces appropriately. @@ -139,7 +153,7 @@ void SettingsPage::BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml: void SettingsPage::SetVersionString() { PackageVersion version = Package::Current->Id->Version; - String ^ appName = AppResourceProvider::GetInstance()->GetResourceString(L"AppName"); + String ^ appName = AppResourceProvider::GetInstance()->GetResourceString("AppName"); SettingsVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision; } @@ -170,10 +184,13 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed void SettingsPage::ThemeChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) { auto resourceLoader = AppResourceProvider::GetInstance(); + auto currentThemeValue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"CurrentTheme"); RadioButton ^ radioButton = safe_cast(sender); String ^ tag = radioButton->Tag->ToString(); + String ^ currentTheme = safe_cast(currentThemeValue); - if (m_currentTheme == tag) + // Only display the restart app notice if the theme selected is not the current theme. + if (currentTheme == tag) { SettingsRestartApp->Visibility = ::Visibility::Collapsed; } diff --git a/src/Calculator/SettingsPage.xaml.h b/src/Calculator/SettingsPage.xaml.h index 8ed7594a..1639f250 100644 --- a/src/Calculator/SettingsPage.xaml.h +++ b/src/Calculator/SettingsPage.xaml.h @@ -19,7 +19,6 @@ namespace CalculatorApp virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e) override; private: - Platform::String ^ m_currentTheme; void SetDefaultFocus(); void InitializeContributeTextBlock(); void BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);