Make unit converters stil working when users opened 'Currency' in offline mode (#1022)

This commit is contained in:
Rudy Huyn 2020-02-25 16:34:18 -08:00 committed by GitHub
parent dab258f3f0
commit c0cb14a8e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 35 deletions

View file

@ -171,9 +171,6 @@ void UnitConverterViewModel::OnCategoryChanged(Object ^ parameter)
void UnitConverterViewModel::ResetCategory() void UnitConverterViewModel::ResetCategory()
{ {
UCM::Category currentCategory = CurrentCategory->GetModelCategory();
IsCurrencyCurrentCategory = currentCategory.id == NavCategory::Serialize(ViewMode::Currency);
m_isInputBlocked = false; m_isInputBlocked = false;
SetSelectedUnits(); SetSelectedUnits();

View file

@ -143,7 +143,6 @@ namespace CalculatorApp
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Category ^> ^, Categories); OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Category ^> ^, Categories);
OBSERVABLE_PROPERTY_RW(Category ^, CurrentCategory);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, Mode); OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, Mode);
OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Unit ^> ^, Units); OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Unit ^> ^, Units);
OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencySymbol1); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencySymbol1);
@ -164,7 +163,7 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen); OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen);
OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsCurrencyLoadingVisible); 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 ^, CurrencyRatioEquality);
OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyRatioEqualityAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyRatioEqualityAutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyTimestamp); OBSERVABLE_PROPERTY_RW(Platform::String ^, CurrencyTimestamp);
@ -172,6 +171,26 @@ namespace CalculatorApp
OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataLoadFailed); OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataLoadFailed);
OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataIsWeekOld); 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 property Windows::UI::Xaml::Visibility SupplementaryVisibility
{ {
Windows::UI::Xaml::Visibility get() Windows::UI::Xaml::Visibility get()
@ -321,7 +340,7 @@ namespace CalculatorApp
std::wstring m_lastAnnouncedFrom; std::wstring m_lastAnnouncedFrom;
std::wstring m_lastAnnouncedTo; std::wstring m_lastAnnouncedTo;
Platform::String ^ m_lastAnnouncedConversionResult; Platform::String ^ m_lastAnnouncedConversionResult;
Category ^ m_CurrentCategory;
bool m_isCurrencyDataLoaded; bool m_isCurrencyDataLoaded;
}; };

View file

@ -32,11 +32,13 @@
TextWrapping="NoWrap"/> TextWrapping="NoWrap"/>
</DataTemplate> </DataTemplate>
<DataTemplate x:Key="SelectedUnitTemplate" x:DataType="vm:Unit"> <!-- Native bindings can't be use with this template, it will launch an exception when ComboxBox.SelectedItem == null -->
<!-- if you switch between modes when no currencies are available for example) -->
<DataTemplate x:Key="SelectedUnitTemplate">
<TextBlock Style="{ThemeResource BodyTextBlockStyle}" <TextBlock Style="{ThemeResource BodyTextBlockStyle}"
FontWeight="SemiBold" FontWeight="SemiBold"
AutomationProperties.Name="{x:Bind AccessibleName}" AutomationProperties.Name="{Binding AccessibleName, Mode=OneTime, FallbackValue=''}"
Text="{x:Bind Name}" Text="{Binding Name, Mode=OneTime, FallbackValue=''}"
TextWrapping="NoWrap"/> TextWrapping="NoWrap"/>
</DataTemplate> </DataTemplate>
@ -440,9 +442,9 @@
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
<VisualStateGroup x:Name="CurrencyLoadingStates"> <VisualStateGroup x:Name="UnitLoadedStates">
<VisualStateGroup.Transitions> <VisualStateGroup.Transitions>
<VisualTransition From="CurrencyLoadingState" To="CurrencyLoadedState"> <VisualTransition From="UnitNotLoadedState" To="UnitLoadedState">
<Storyboard> <Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Units1" Storyboard.TargetProperty="Visibility"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Units1" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
@ -489,7 +491,7 @@
</Storyboard> </Storyboard>
</VisualTransition> </VisualTransition>
</VisualStateGroup.Transitions> </VisualStateGroup.Transitions>
<VisualState x:Name="CurrencyLoadingState"> <VisualState x:Name="UnitNotLoadedState">
<VisualState.Setters> <VisualState.Setters>
<Setter Target="CurrencyRatioEqualityBlock.Opacity" Value="0"/> <Setter Target="CurrencyRatioEqualityBlock.Opacity" Value="0"/>
<Setter Target="CurrencyTimestampTextBlock.Opacity" Value="0"/> <Setter Target="CurrencyTimestampTextBlock.Opacity" Value="0"/>
@ -500,17 +502,7 @@
<Setter Target="Value2Container.Visibility" Value="Collapsed"/> <Setter Target="Value2Container.Visibility" Value="Collapsed"/>
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
<VisualState x:Name="CurrencyLoadedState"> <VisualState x:Name="UnitLoadedState"/>
<VisualState.Setters>
<Setter Target="CurrencyRatioEqualityBlock.Opacity" Value="1"/>
<Setter Target="CurrencyTimestampTextBlock.Opacity" Value="1"/>
<Setter Target="CurrencyLoadingGrid.Visibility" Value="Collapsed"/>
<Setter Target="Units1.Visibility" Value="Visible"/>
<Setter Target="Value1Container.Visibility" Value="Visible"/>
<Setter Target="Units2.Visibility" Value="Visible"/>
<Setter Target="Value2Container.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup> </VisualStateGroup>
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
@ -576,12 +568,12 @@
DropDownClosed="UpdateDropDownState" DropDownClosed="UpdateDropDownState"
DropDownOpened="UpdateDropDownState" DropDownOpened="UpdateDropDownState"
FlowDirection="{x:Bind LayoutDirection}" FlowDirection="{x:Bind LayoutDirection}"
IsEnabled="{Binding IsDropDownEnabled}"
IsEnabledChanged="Units1_IsEnabledChanged" IsEnabledChanged="Units1_IsEnabledChanged"
ItemTemplate="{StaticResource UnitTemplate}" ItemTemplate="{StaticResource UnitTemplate}"
ItemsSource="{Binding Units, Converter={StaticResource AlwaysSelectedConverter}}" ItemsSource="{Binding Units, Converter={StaticResource AlwaysSelectedConverter}}"
SelectedItem="{Binding Unit1, Mode=TwoWay, Converter={StaticResource ValidSelectedItemConverter}}" SelectedItem="{Binding Unit1, Mode=TwoWay, Converter={StaticResource ValidSelectedItemConverter}}"
TabIndex="2"/> TabIndex="2"
IsEnabled="{Binding IsDropDownEnabled}"/>
<Grid x:Name="Value2Container" <Grid x:Name="Value2Container"
Grid.Row="3" Grid.Row="3"
@ -626,11 +618,11 @@
DropDownClosed="UpdateDropDownState" DropDownClosed="UpdateDropDownState"
DropDownOpened="UpdateDropDownState" DropDownOpened="UpdateDropDownState"
FlowDirection="{x:Bind LayoutDirection}" FlowDirection="{x:Bind LayoutDirection}"
IsEnabled="{Binding IsDropDownEnabled}"
ItemTemplate="{StaticResource UnitTemplate}" ItemTemplate="{StaticResource UnitTemplate}"
ItemsSource="{Binding Units, Converter={StaticResource AlwaysSelectedConverter}}" ItemsSource="{Binding Units, Converter={StaticResource AlwaysSelectedConverter}}"
SelectedItem="{Binding Unit2, Mode=TwoWay, Converter={StaticResource ValidSelectedItemConverter}}" SelectedItem="{Binding Unit2, Mode=TwoWay, Converter={StaticResource ValidSelectedItemConverter}}"
TabIndex="4"/> TabIndex="4"
IsEnabled="{Binding IsDropDownEnabled}"/>
<StackPanel x:Name="SupplementaryResultsPanelInGrid" <StackPanel x:Name="SupplementaryResultsPanelInGrid"
Grid.Row="5" Grid.Row="5"

View file

@ -81,7 +81,9 @@ void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChanged
{ {
SetCurrencyTimestampFontWeight(); SetCurrencyTimestampFontWeight();
} }
else if (propertyName == UnitConverterViewModel::IsCurrencyLoadingVisiblePropertyName) else if (
propertyName == UnitConverterViewModel::IsCurrencyLoadingVisiblePropertyName
|| propertyName == UnitConverterViewModel::IsCurrencyCurrentCategoryPropertyName)
{ {
OnIsDisplayVisibleChanged(); OnIsDisplayVisibleChanged();
} }
@ -318,18 +320,21 @@ void UnitConverter::Units1_IsEnabledChanged(Object ^ sender, DependencyPropertyC
void UnitConverter::OnIsDisplayVisibleChanged() void UnitConverter::OnIsDisplayVisibleChanged()
{ {
if (Model->IsCurrencyLoadingVisible) if (!Model->IsCurrencyCurrentCategory)
{ {
VisualStateManager::GoToState(this, L"CurrencyLoadingState", false); VisualStateManager::GoToState(this, UnitLoadedState->Name, false);
StartProgressRingWithDelay();
} }
else else
{ {
HideProgressRing(); if (Model->IsCurrencyLoadingVisible)
if (Model->IsCurrencyCurrentCategory && !Model->CurrencyTimestamp->IsEmpty())
{ {
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);
} }
} }
} }