2022-10-26 20:53:18 +02:00
|
|
|
using System.Collections.Generic;
|
2021-05-13 20:03:07 +02:00
|
|
|
using System.Collections.ObjectModel;
|
2022-10-26 20:53:18 +02:00
|
|
|
using System.ComponentModel;
|
2021-05-13 20:03:07 +02:00
|
|
|
using System.Linq;
|
|
|
|
using TINK.Model;
|
|
|
|
using TINK.Model.Connector;
|
2021-12-08 20:03:50 +01:00
|
|
|
using TINK.MultilingualResources;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
namespace TINK.ViewModel.Settings
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Holds the filters to display..</summary>
|
|
|
|
/// <remarks> Former name: FilterCollectionMutable.</remarks>
|
2022-10-26 20:53:18 +02:00
|
|
|
public class SettingsBikeFilterViewModel : ObservableCollection<FilterItemMutable>, INotifyPropertyChanged
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
2022-10-26 20:53:18 +02:00
|
|
|
public new event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Constructs a filter collection object.</summary>
|
|
|
|
/// <param name="filterSettings">All available filters.</param>
|
|
|
|
/// <param name="filterGroupUser">Filters which apply to logged in user.</param>
|
|
|
|
public SettingsBikeFilterViewModel(
|
|
|
|
IGroupFilterSettings filterSettings,
|
|
|
|
IEnumerable<string> filterGroupUser)
|
|
|
|
{
|
|
|
|
foreach (var filter in filterSettings)
|
|
|
|
{
|
|
|
|
if (filter.Key == FilterHelper.CARGOBIKE)
|
|
|
|
{
|
2022-10-26 20:53:18 +02:00
|
|
|
var cargo = new FilterItemMutable(
|
2022-09-06 16:08:19 +02:00
|
|
|
filter.Key,
|
|
|
|
filter.Value,
|
|
|
|
(filterGroupUser != null && filterGroupUser.Count() > 0) ? filterGroupUser.Contains(filter.Key) : true,
|
2022-10-26 20:53:18 +02:00
|
|
|
AppResources.MarkingCargoBike);
|
|
|
|
Add(cargo);
|
|
|
|
|
|
|
|
cargo.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev);
|
2022-09-06 16:08:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (filter.Key == FilterHelper.CITYBIKE)
|
|
|
|
{
|
2022-10-26 20:53:18 +02:00
|
|
|
var city = new FilterItemMutable(
|
2022-09-06 16:08:19 +02:00
|
|
|
filter.Key,
|
|
|
|
filter.Value,
|
|
|
|
(filterGroupUser != null && filterGroupUser.Count() > 0) ? filterGroupUser.Contains(filter.Key) : true,
|
2022-10-26 20:53:18 +02:00
|
|
|
AppResources.MarkingCityBike);
|
|
|
|
Add(city);
|
|
|
|
city.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev);
|
2022-09-06 16:08:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-10-26 20:53:18 +02:00
|
|
|
var item = new FilterItemMutable(
|
2022-09-06 16:08:19 +02:00
|
|
|
filter.Key,
|
|
|
|
filter.Value,
|
|
|
|
filterGroupUser != null ? filterGroupUser.Contains(filter.Key) : true,
|
2022-10-26 20:53:18 +02:00
|
|
|
filter.Key);
|
|
|
|
Add(item);
|
|
|
|
item.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Get filter collection which might have been modified for serialization purposes.</summary>
|
|
|
|
public Dictionary<string, FilterState> FilterCollection
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var dictionary = new Dictionary<string, FilterState>();
|
|
|
|
foreach (var entry in this)
|
|
|
|
{
|
|
|
|
dictionary.Add(entry.Key, entry.State);
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
return dictionary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
}
|