mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Don't call Reset/Clear when users refresh currency rates v2
This commit is contained in:
parent
4b6b8fa8fa
commit
ec534e43e9
4 changed files with 35 additions and 12 deletions
|
@ -63,6 +63,7 @@ UnitConverter::UnitConverter(_In_ const shared_ptr<IConverterDataLoader>& dataLo
|
|||
unquoteConversions[L"{sc}"] = L';';
|
||||
unquoteConversions[L"{lb}"] = LEFTESCAPECHAR;
|
||||
unquoteConversions[L"{rb}"] = RIGHTESCAPECHAR;
|
||||
ClearValues();
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
@ -836,7 +837,6 @@ void UnitConverter::Reset()
|
|||
{
|
||||
m_categories = m_dataLoader->LoadOrderedCategories();
|
||||
|
||||
ClearValues();
|
||||
m_switchedActive = false;
|
||||
|
||||
if (m_categories.empty())
|
||||
|
@ -881,7 +881,6 @@ void UnitConverter::Reset()
|
|||
}
|
||||
|
||||
InitializeSelectedUnits();
|
||||
Calculate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -972,11 +971,20 @@ bool UnitConverter::AnyUnitIsEmpty()
|
|||
/// </summary>
|
||||
void UnitConverter::Calculate()
|
||||
{
|
||||
unordered_map<Unit, ConversionData, UnitHash> conversionTable = m_ratioMap[m_fromType];
|
||||
double returnValue = stod(m_currentDisplay);
|
||||
if (AnyUnitIsEmpty() || (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0))
|
||||
if (AnyUnitIsEmpty())
|
||||
{
|
||||
m_returnDisplay = m_currentDisplay;
|
||||
m_returnHasDecimal = m_currentHasDecimal;
|
||||
TrimString(m_returnDisplay);
|
||||
return;
|
||||
}
|
||||
|
||||
unordered_map<Unit, ConversionData, UnitHash> conversionTable = m_ratioMap[m_fromType];
|
||||
double returnValue = stod(m_currentDisplay);
|
||||
if (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0)
|
||||
{
|
||||
m_returnDisplay = m_currentDisplay;
|
||||
m_returnHasDecimal = m_currentHasDecimal;
|
||||
TrimString(m_returnDisplay);
|
||||
}
|
||||
else
|
||||
|
@ -1015,9 +1023,8 @@ void UnitConverter::Calculate()
|
|||
m_returnDisplay = returnString;
|
||||
TrimString(m_returnDisplay);
|
||||
}
|
||||
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
||||
}
|
||||
|
||||
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1078,3 +1085,10 @@ void UnitConverter::UpdateViewModel()
|
|||
m_vmCallback->DisplayCallback(m_currentDisplay, m_returnDisplay);
|
||||
m_vmCallback->SuggestedValueCallback(CalculateSuggested());
|
||||
}
|
||||
|
||||
void UnitConverter::ResetCategoriesAndRatio()
|
||||
{
|
||||
Reset();
|
||||
Calculate();
|
||||
UpdateViewModel();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
@ -195,6 +195,7 @@ namespace UnitConversionManager
|
|||
virtual void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) = 0;
|
||||
virtual void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) = 0;
|
||||
virtual concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() = 0;
|
||||
virtual void ResetCategoriesAndRatio() = 0;
|
||||
};
|
||||
|
||||
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
||||
|
@ -220,6 +221,7 @@ namespace UnitConversionManager
|
|||
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
||||
// IUnitConverter
|
||||
|
||||
void ResetCategoriesAndRatio();
|
||||
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
||||
static std::wstring Quote(const std::wstring& s);
|
||||
static std::wstring Unquote(const std::wstring& s);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
|
@ -175,12 +175,16 @@ void UnitConverterViewModel::PopulateData()
|
|||
}
|
||||
|
||||
void UnitConverterViewModel::OnCategoryChanged(Object^ parameter)
|
||||
{
|
||||
m_model->SendCommand(UCM::Command::Clear);
|
||||
ResetCategory();
|
||||
}
|
||||
|
||||
void UnitConverterViewModel::ResetCategory()
|
||||
{
|
||||
UCM::Category currentCategory = CurrentCategory->GetModelCategory();
|
||||
IsCurrencyCurrentCategory = currentCategory.id == NavCategory::Serialize(ViewMode::Currency);
|
||||
|
||||
m_model->SendCommand(UCM::Command::Clear);
|
||||
|
||||
m_isInputBlocked = false;
|
||||
SetSelectedUnits();
|
||||
|
||||
|
@ -716,7 +720,8 @@ void UnitConverterViewModel::OnCurrencyDataLoadFinished(bool didLoad)
|
|||
{
|
||||
m_isCurrencyDataLoaded = true;
|
||||
CurrencyDataLoadFailed = !didLoad;
|
||||
ResetView();
|
||||
m_model->ResetCategoriesAndRatio();
|
||||
ResetCategory();
|
||||
|
||||
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
|
||||
String^ announcement = AppResourceProvider::GetInstance().GetResourceString(key);
|
||||
|
|
|
@ -242,6 +242,7 @@ namespace CalculatorApp
|
|||
void UpdateValue2AutomationName();
|
||||
Platform::String^ Serialize();
|
||||
void Deserialize(Platform::String^ state);
|
||||
void ResetCategoriesAndRatio();
|
||||
|
||||
// Saving And Restoring User Preferences of Category and Associated-Units across Sessions.
|
||||
void SaveUserPreferences();
|
||||
|
@ -282,6 +283,7 @@ namespace CalculatorApp
|
|||
void RefreshSupplementaryResults();
|
||||
void UpdateInputBlocked(_In_ const std::wstring& currencyInput);
|
||||
bool UnitsAreValid();
|
||||
void ResetCategory();
|
||||
|
||||
void OnButtonPressed(Platform::Object^ parameter);
|
||||
Platform::String^ ConvertToLocalizedString(const std::wstring& stringToLocalize, bool allowPartialStrings);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue