From c0cb14a8e866566c9f5cd98cae050f8adc08ba89 Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Tue, 25 Feb 2020 16:34:18 -0800 Subject: [PATCH] Make unit converters stil working when users opened 'Currency' in offline mode (#1022) --- src/CalcViewModel/UnitConverterViewModel.cpp | 3 -- src/CalcViewModel/UnitConverterViewModel.h | 25 ++++++++++++-- src/Calculator/Views/UnitConverter.xaml | 34 ++++++++------------ src/Calculator/Views/UnitConverter.xaml.cpp | 21 +++++++----- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp index ff77cd77..3b46d9ab 100644 --- a/src/CalcViewModel/UnitConverterViewModel.cpp +++ b/src/CalcViewModel/UnitConverterViewModel.cpp @@ -171,9 +171,6 @@ void UnitConverterViewModel::OnCategoryChanged(Object ^ parameter) void UnitConverterViewModel::ResetCategory() { - UCM::Category currentCategory = CurrentCategory->GetModelCategory(); - IsCurrencyCurrentCategory = currentCategory.id == NavCategory::Serialize(ViewMode::Currency); - m_isInputBlocked = false; SetSelectedUnits(); diff --git a/src/CalcViewModel/UnitConverterViewModel.h b/src/CalcViewModel/UnitConverterViewModel.h index 5891f037..1f95a47a 100644 --- a/src/CalcViewModel/UnitConverterViewModel.h +++ b/src/CalcViewModel/UnitConverterViewModel.h @@ -143,7 +143,6 @@ namespace CalculatorApp OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector ^, Categories); - OBSERVABLE_PROPERTY_RW(Category ^, CurrentCategory); OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, Mode); OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector ^, Units); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencySymbol1); @@ -164,7 +163,7 @@ namespace CalculatorApp OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen); OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsCurrencyLoadingVisible); - OBSERVABLE_PROPERTY_RW(bool, IsCurrencyCurrentCategory); + OBSERVABLE_NAMED_PROPERTY_R(bool, IsCurrencyCurrentCategory); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyRatioEquality); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyRatioEqualityAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyTimestamp); @@ -172,6 +171,26 @@ namespace CalculatorApp OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataLoadFailed); OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataIsWeekOld); + public: + property Category ^ CurrentCategory + { + Category ^ get() { return m_CurrentCategory; } + void set(Category ^ value) + { + if (m_CurrentCategory == value) + { + return; + } + m_CurrentCategory = value; + if (value != nullptr) + { + auto currentCategory = value->GetModelCategory(); + IsCurrencyCurrentCategory = currentCategory.id == CalculatorApp::Common::NavCategory::Serialize(CalculatorApp::Common::ViewMode::Currency); + } + OnPropertyChanged("CurrentCategory"); + } + } + property Windows::UI::Xaml::Visibility SupplementaryVisibility { Windows::UI::Xaml::Visibility get() @@ -321,7 +340,7 @@ namespace CalculatorApp std::wstring m_lastAnnouncedFrom; std::wstring m_lastAnnouncedTo; Platform::String ^ m_lastAnnouncedConversionResult; - + Category ^ m_CurrentCategory; bool m_isCurrencyDataLoaded; }; diff --git a/src/Calculator/Views/UnitConverter.xaml b/src/Calculator/Views/UnitConverter.xaml index 21c64034..60fd7248 100644 --- a/src/Calculator/Views/UnitConverter.xaml +++ b/src/Calculator/Views/UnitConverter.xaml @@ -32,11 +32,13 @@ TextWrapping="NoWrap"/> - + + + @@ -440,9 +442,9 @@ - + - + @@ -489,7 +491,7 @@ - + @@ -500,17 +502,7 @@ - - - - - - - - - - - + @@ -576,12 +568,12 @@ DropDownClosed="UpdateDropDownState" DropDownOpened="UpdateDropDownState" FlowDirection="{x:Bind LayoutDirection}" - IsEnabled="{Binding IsDropDownEnabled}" IsEnabledChanged="Units1_IsEnabledChanged" ItemTemplate="{StaticResource UnitTemplate}" ItemsSource="{Binding Units, Converter={StaticResource AlwaysSelectedConverter}}" SelectedItem="{Binding Unit1, Mode=TwoWay, Converter={StaticResource ValidSelectedItemConverter}}" - TabIndex="2"/> + TabIndex="2" + IsEnabled="{Binding IsDropDownEnabled}"/> + TabIndex="4" + IsEnabled="{Binding IsDropDownEnabled}"/> IsCurrencyLoadingVisible) + if (!Model->IsCurrencyCurrentCategory) { - VisualStateManager::GoToState(this, L"CurrencyLoadingState", false); - StartProgressRingWithDelay(); + VisualStateManager::GoToState(this, UnitLoadedState->Name, false); } else { - HideProgressRing(); - - if (Model->IsCurrencyCurrentCategory && !Model->CurrencyTimestamp->IsEmpty()) + if (Model->IsCurrencyLoadingVisible) { - VisualStateManager::GoToState(this, L"CurrencyLoadedState", true); + VisualStateManager::GoToState(this, UnitNotLoadedState->Name, false); + StartProgressRingWithDelay(); + } + else + { + HideProgressRing(); + VisualStateManager::GoToState(this, !Model->CurrencyTimestamp->IsEmpty() ? UnitLoadedState->Name : UnitNotLoadedState->Name, true); } } }