sharee.bike-App/TINKLib/ViewModel/Settings/FilterItemMutable.cs
2021-05-13 20:03:07 +02:00

63 lines
2.1 KiB
C#

using TINK.Model;
namespace TINK.ViewModel.Settings
{
/// <summary>Holds filter item incluting full state (avaialble, activated, name, ...). </summary>
public class FilterItemMutable
{
/// <summary> Switch value</summary>
private bool m_bIsActivatedSwitch;
/// <summary> Constructs a filter object. </summary>
/// <param name="p_strKey">Key of the filter state.</param>
/// <param name="p_oFilterState">State of filter, on or off.</param>
/// <param name="p_bIsEnabled">If filter does not apply because user does not belong to group (TINK, Konrad, ...) filter is deactivated.</param>
/// <param name="p_strLabelText">Text of the switch describing the filter.</param>
public FilterItemMutable(
string p_strKey,
FilterState p_oFilterState,
bool p_bIsEnabled,
string p_strLabelText)
{
Text = p_strLabelText;
IsEnabled = p_bIsEnabled;
State = p_oFilterState;
Key = p_strKey;
m_bIsActivatedSwitch = p_bIsEnabled && p_oFilterState == FilterState.On;
}
/// <summary> Text describing the filter. </summary>
public string Text { get; }
/// <summary> True if switch can be toggeled.</summary>
public bool IsEnabled { get; }
/// <summary> True if switch is on.</summary>
public bool IsActivated
{
get
{
return m_bIsActivatedSwitch;
}
set
{
m_bIsActivatedSwitch = value;
if (!IsEnabled)
{
// Nothing to do if filter does not apply to user account.
return;
}
State = m_bIsActivatedSwitch ? FilterState.On : FilterState.Off;
}
}
/// <summary> Key of the filter.</summary>
public string Key { get; }
/// <summary> State of the filter.</summary>
public FilterState State { get; private set; }
}
}