using System.ComponentModel;
using TINK.Model;
namespace TINK.ViewModel.Settings
{
/// Holds filter item including full state (available, activated, name, ...).
public class FilterItemMutable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
/// Switch value
private bool m_bIsActivatedSwitch;
/// Constructs a filter object.
/// Key of the filter state.
/// State of filter, on or off.
/// If filter does not apply because user does not belong to group (TINK, Konrad, ...) filter is deactivated.
/// Text of the switch describing the filter.
public FilterItemMutable(
string key,
FilterState filterState,
bool isEnabled,
string labelText)
{
Text = labelText;
IsEnabled = isEnabled;
State = filterState;
Key = key;
m_bIsActivatedSwitch = isEnabled && filterState == FilterState.On;
}
/// Text describing the filter.
public string Text { get; }
/// True if switch can be toggled.
public bool IsEnabled { get; }
/// True if switch is on.
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)));
}
}
/// Key of the filter.
public string Key { get; }
/// State of the filter.
public FilterState State { get; private set; }
}
}