using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using TINK.Model; using TINK.Model.Connector; using TINK.MultilingualResources; namespace TINK.ViewModel.Settings { /// Holds the filters to display.. /// Former name: FilterCollectionMutable. public class SettingsBikeFilterViewModel : ObservableCollection, INotifyPropertyChanged { public new event PropertyChangedEventHandler PropertyChanged; /// Constructs a filter collection object. /// All available filters. /// Filters which apply to logged in user. public SettingsBikeFilterViewModel( IGroupFilterSettings filterSettings, IEnumerable filterGroupUser) { foreach (var filter in filterSettings) { if (filter.Key == FilterHelper.CARGOBIKE) { var cargo = new FilterItemMutable( filter.Key, filter.Value, (filterGroupUser != null && filterGroupUser.Count() > 0) ? filterGroupUser.Contains(filter.Key) : true, AppResources.MarkingCargoBike); Add(cargo); cargo.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev); continue; } if (filter.Key == FilterHelper.CITYBIKE) { var city = new FilterItemMutable( filter.Key, filter.Value, (filterGroupUser != null && filterGroupUser.Count() > 0) ? filterGroupUser.Contains(filter.Key) : true, AppResources.MarkingCityBike); Add(city); city.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev); continue; } var item = new FilterItemMutable( filter.Key, filter.Value, filterGroupUser != null ? filterGroupUser.Contains(filter.Key) : true, filter.Key); Add(item); item.PropertyChanged += (sender, ev) => PropertyChanged?.Invoke(sender, ev); } } /// Get filter collection which might have been modified for serialization purposes. public Dictionary FilterCollection { get { var dictionary = new Dictionary(); foreach (var entry in this) { dictionary.Add(entry.Key, entry.State); } return dictionary; } } } }