Keep input when users refresh currency rates (#369)
Fixes #260 Description of the changes: prevent UnitConverterViewModel to reset values when users click on update rates. recompute UnitConverter's caches (m_ratioMap and m_categoryToUnits) once rates are updated (but check first if the user did/didn't change the category) How changes were validated: Manually tested with fake currency rates (HTTP responses modified on the fly via FiddlerCore) Verified that it works no matter the selected field (From or To) Verified that the currencies selected are kept after a refresh
This commit is contained in:
committed by
Daniel Belcher
parent
775771d62a
commit
ad25feda6b
@@ -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,8 @@ 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 Calculate() = 0;
|
||||
virtual void ResetCategoriesAndRatios() = 0;
|
||||
};
|
||||
|
||||
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
||||
@@ -218,6 +220,8 @@ namespace UnitConversionManager
|
||||
void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) override;
|
||||
void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) override;
|
||||
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
||||
void Calculate() override;
|
||||
void ResetCategoriesAndRatios() override;
|
||||
// IUnitConverter
|
||||
|
||||
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
||||
@@ -228,9 +232,7 @@ namespace UnitConversionManager
|
||||
bool CheckLoad();
|
||||
double Convert(double value, ConversionData conversionData);
|
||||
std::vector<std::tuple<std::wstring, Unit>> CalculateSuggested();
|
||||
void Reset();
|
||||
void ClearValues();
|
||||
void Calculate();
|
||||
void TrimString(std::wstring& input);
|
||||
void InitializeSelectedUnits();
|
||||
std::wstring RoundSignificant(double num, int numSignificant);
|
||||
|
||||
Reference in New Issue
Block a user