sharee.bike-App/TINKLib/ViewModel/Settings/FilterItemMutable.cs
2022-10-26 20:53:18 +02:00

74 lines
1.9 KiB
C#

using System.ComponentModel;
using TINK.Model;
namespace TINK.ViewModel.Settings
{
/// <summary>Holds filter item incluting full state (avaialble, activated, name, ...). </summary>
public class FilterItemMutable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
/// <summary> Switch value</summary>
private bool m_bIsActivatedSwitch;
/// <summary> Constructs a filter object. </summary>
/// <param name="key">Key of the filter state.</param>
/// <param name="filterState">State of filter, on or off.</param>
/// <param name="isEnabled">If filter does not apply because user does not belong to group (TINK, Konrad, ...) filter is deactivated.</param>
/// <param name="labelText">Text of the switch describing the filter.</param>
public FilterItemMutable(
string key,
FilterState filterState,
bool isEnabled,
string labelText)
{
Text = labelText;
IsEnabled = isEnabled;
State = filterState;
Key = key;
m_bIsActivatedSwitch = isEnabled && filterState == 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
{
if (m_bIsActivatedSwitch == value)
{
// Nothing to do.
return;
}
m_bIsActivatedSwitch = value;
if (!IsEnabled)
{
// Nothing to do if filter does not apply to user account.
return;
}
State = m_bIsActivatedSwitch ? FilterState.On : FilterState.Off;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsActivated)));
}
}
/// <summary> Key of the filter.</summary>
public string Key { get; }
/// <summary> State of the filter.</summary>
public FilterState State { get; private set; }
}
}