Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -2,30 +2,30 @@
namespace TINK.ViewModel.Map
{
/// <summary> Holds an empty filter object.</summary>
/// <remarks>Old name: EmptyMapPageFilter</remarks>
public class EmptyToggleViewModel : ITinkKonradToggleViewModel
{
/// <summary> Holds the map page filter.</summary>
public IGroupFilterMapPage FilterDictionary => new GroupFilterMapPage();
/// <summary> Holds an empty filter object.</summary>
/// <remarks>Old name: EmptyMapPageFilter</remarks>
public class EmptyToggleViewModel : ITinkKonradToggleViewModel
{
/// <summary> Holds the map page filter.</summary>
public IGroupFilterMapPage FilterDictionary => new GroupFilterMapPage();
/// <summary> Active filter</summary>
public string CurrentFitler => string.Empty;
/// <summary> Active filter</summary>
public string CurrentFitler => string.Empty;
public bool IsTinkEnabled => false;
public bool IsTinkEnabled => false;
public Color TinkColor => Color.Default;
public Color TinkColor => Color.Default;
public Color NoTinkColor => Color.Default;
public Color NoTinkColor => Color.Default;
public bool IsKonradEnabled => false;
public bool IsKonradEnabled => false;
public Color KonradColor => Color.Default;
public Color KonradColor => Color.Default;
public Color NoKonradColor => Color.Default;
public Color NoKonradColor => Color.Default;
public bool IsToggleVisible => false;
public bool IsToggleVisible => false;
public string CurrentFilter => string.Empty;
}
public string CurrentFilter => string.Empty;
}
}

View file

@ -6,62 +6,62 @@ using TINK.Model.Connector.Filter;
namespace TINK.ViewModel.Map
{
public class GroupFilterMapPage : IGroupFilterMapPage
{
public GroupFilterMapPage(IDictionary<string, FilterState> filterDictionary = null)
{
FilterDictionary = filterDictionary ?? new Dictionary<string, FilterState>();
Filter = filterDictionary != null
? (IGroupFilter)new IntersectGroupFilter(FilterDictionary.Where(x => x.Value == FilterState.On).Select(x => x.Key))
: new NullGroupFilter();
}
public class GroupFilterMapPage : IGroupFilterMapPage
{
public GroupFilterMapPage(IDictionary<string, FilterState> filterDictionary = null)
{
FilterDictionary = filterDictionary ?? new Dictionary<string, FilterState>();
Filter = filterDictionary != null
? (IGroupFilter)new IntersectGroupFilter(FilterDictionary.Where(x => x.Value == FilterState.On).Select(x => x.Key))
: new NullGroupFilter();
}
private IGroupFilter Filter { get; }
private IGroupFilter Filter { get; }
/// <summary> Gets the active filters.</summary>
/// <param name="filterCollection">Filter collection to get group from.</param>
/// <returns>List of active filters.</returns>
/// <todo>Rename to ToFilterList</todo>
public IList<string> GetGroup()
{
return this.Where(x => x.Value == FilterState.On).Select(x => x.Key).ToList();
}
/// <summary> Gets the active filters.</summary>
/// <param name="filterCollection">Filter collection to get group from.</param>
/// <returns>List of active filters.</returns>
/// <todo>Rename to ToFilterList</todo>
public IList<string> GetGroup()
{
return this.Where(x => x.Value == FilterState.On).Select(x => x.Key).ToList();
}
/// <summary> Performs filtering on response-group. </summary>
public IEnumerable<string> DoFilter(IEnumerable<string> filter = null) => Filter.DoFilter(filter);
/// <summary> Performs filtering on response-group. </summary>
public IEnumerable<string> DoFilter(IEnumerable<string> filter = null) => Filter.DoFilter(filter);
private IDictionary<string, FilterState> FilterDictionary { get; }
private IDictionary<string, FilterState> FilterDictionary { get; }
public FilterState this[string key] { get => FilterDictionary[key]; set => FilterDictionary[key] = value; }
public FilterState this[string key] { get => FilterDictionary[key]; set => FilterDictionary[key] = value; }
public ICollection<string> Keys => FilterDictionary.Keys;
public ICollection<string> Keys => FilterDictionary.Keys;
public ICollection<FilterState> Values => FilterDictionary.Values;
public ICollection<FilterState> Values => FilterDictionary.Values;
public int Count => FilterDictionary.Count;
public int Count => FilterDictionary.Count;
public bool IsReadOnly => true;
public bool IsReadOnly => true;
public void Add(string key, FilterState value) => throw new System.NotImplementedException();
public void Add(string key, FilterState value) => throw new System.NotImplementedException();
public void Add(KeyValuePair<string, FilterState> item) => throw new System.NotImplementedException();
public void Add(KeyValuePair<string, FilterState> item) => throw new System.NotImplementedException();
public void Clear() => throw new System.NotImplementedException();
public void Clear() => throw new System.NotImplementedException();
public bool Contains(KeyValuePair<string, FilterState> item) => FilterDictionary.Contains(item);
public bool Contains(KeyValuePair<string, FilterState> item) => FilterDictionary.Contains(item);
public bool ContainsKey(string key) => FilterDictionary.ContainsKey(key);
public bool ContainsKey(string key) => FilterDictionary.ContainsKey(key);
public void CopyTo(KeyValuePair<string, FilterState>[] array, int arrayIndex) => FilterDictionary.CopyTo(array, arrayIndex);
public void CopyTo(KeyValuePair<string, FilterState>[] array, int arrayIndex) => FilterDictionary.CopyTo(array, arrayIndex);
public IEnumerator<KeyValuePair<string, FilterState>> GetEnumerator() => FilterDictionary.GetEnumerator();
public IEnumerator<KeyValuePair<string, FilterState>> GetEnumerator() => FilterDictionary.GetEnumerator();
public bool Remove(string key) => throw new System.NotImplementedException();
public bool Remove(string key) => throw new System.NotImplementedException();
public bool Remove(KeyValuePair<string, FilterState> item) => throw new System.NotImplementedException();
public bool Remove(KeyValuePair<string, FilterState> item) => throw new System.NotImplementedException();
public bool TryGetValue(string key, out FilterState value) => FilterDictionary.TryGetValue(key, out value);
public bool TryGetValue(string key, out FilterState value) => FilterDictionary.TryGetValue(key, out value);
IEnumerator IEnumerable.GetEnumerator() => FilterDictionary.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => FilterDictionary.GetEnumerator();
}
}

View file

@ -4,71 +4,71 @@ using TINK.Model;
namespace TINK.ViewModel.Map
{
/// <summary> Helper functionality. </summary>
/// <remarks> Former name: MapPageFilterFactory</remarks>
public static class GroupFilterMapPageHelper
{
/// <summary> Verifies that filters available are always consistent with filter configuration from settings page/ user group. </summary>
/// <param name="mapPageFilterDictionary">Last filter from map page. Might have to be updated.</param>
/// <param name="settingsAndUserFilter">Filter from settings page/ user group.</param>
public static IGroupFilterMapPage CreateUpdated(
this IGroupFilterMapPage mapPageFilterDictionary,
IEnumerable<string> settingsAndUserFilter)
{
if (settingsAndUserFilter == null)
{
// All filters are null filters no update has to be performed.
return mapPageFilterDictionary;
}
/// <summary> Helper functionality. </summary>
/// <remarks> Former name: MapPageFilterFactory</remarks>
public static class GroupFilterMapPageHelper
{
/// <summary> Verifies that filters available are always consistent with filter configuration from settings page/ user group. </summary>
/// <param name="mapPageFilterDictionary">Last filter from map page. Might have to be updated.</param>
/// <param name="settingsAndUserFilter">Filter from settings page/ user group.</param>
public static IGroupFilterMapPage CreateUpdated(
this IGroupFilterMapPage mapPageFilterDictionary,
IEnumerable<string> settingsAndUserFilter)
{
if (settingsAndUserFilter == null)
{
// All filters are null filters no update has to be performed.
return mapPageFilterDictionary;
}
if (mapPageFilterDictionary == null || mapPageFilterDictionary.Count <= 0)
{
return new GroupFilterMapPage();
}
if (mapPageFilterDictionary == null || mapPageFilterDictionary.Count <= 0)
{
return new GroupFilterMapPage();
}
// Filter dictionary by enumeration.
var updatedMapPageFilterDictionary = new Dictionary<string, FilterState>(mapPageFilterDictionary).Where(x => settingsAndUserFilter.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value);
// Filter dictionary by enumeration.
var updatedMapPageFilterDictionary = new Dictionary<string, FilterState>(mapPageFilterDictionary).Where(x => settingsAndUserFilter.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value);
// Get key of activated filter if there is still one.
var activatedFilter = updatedMapPageFilterDictionary.FirstOrDefault(x => x.Value == FilterState.On).Key
?? string.Empty;
// Get key of activated filter if there is still one.
var activatedFilter = updatedMapPageFilterDictionary.FirstOrDefault(x => x.Value == FilterState.On).Key
?? string.Empty;
// Add entries which have become available.
var filterState = FilterState.On; // Set first filter added to on.
var filtersToAdd = settingsAndUserFilter.Except(updatedMapPageFilterDictionary.Select(x => x.Key));
foreach (var l_oEntry in filtersToAdd)
{
updatedMapPageFilterDictionary.Add(l_oEntry, filterState);
filterState = FilterState.Off;
}
// Add entries which have become available.
var filterState = FilterState.On; // Set first filter added to on.
var filtersToAdd = settingsAndUserFilter.Except(updatedMapPageFilterDictionary.Select(x => x.Key));
foreach (var l_oEntry in filtersToAdd)
{
updatedMapPageFilterDictionary.Add(l_oEntry, filterState);
filterState = FilterState.Off;
}
if (updatedMapPageFilterDictionary.Count <= 0)
{
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
if (updatedMapPageFilterDictionary.Count <= 0)
{
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
// Ensure that there is at least one element on.
if (updatedMapPageFilterDictionary.Where(x => x.Value == FilterState.On).Count() == 0)
{
// No element is active. Set one element active.
updatedMapPageFilterDictionary[updatedMapPageFilterDictionary.ToArray()[0].Key] = FilterState.On;
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
// Ensure that there is at least one element on.
if (updatedMapPageFilterDictionary.Where(x => x.Value == FilterState.On).Count() == 0)
{
// No element is active. Set one element active.
updatedMapPageFilterDictionary[updatedMapPageFilterDictionary.ToArray()[0].Key] = FilterState.On;
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
// Ensure that there is only one selected element.
if (updatedMapPageFilterDictionary.Where(x => x.Value == FilterState.On).Count() > 1)
{
// More than one element is active. Set element inactive.
if (updatedMapPageFilterDictionary.ContainsKey(activatedFilter))
{
// Turn filter off.
updatedMapPageFilterDictionary[activatedFilter] = FilterState.Off;
}
// Ensure that there is only one selected element.
if (updatedMapPageFilterDictionary.Where(x => x.Value == FilterState.On).Count() > 1)
{
// More than one element is active. Set element inactive.
if (updatedMapPageFilterDictionary.ContainsKey(activatedFilter))
{
// Turn filter off.
updatedMapPageFilterDictionary[activatedFilter] = FilterState.Off;
}
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
}
return new GroupFilterMapPage(updatedMapPageFilterDictionary);
}
}
}

View file

@ -3,13 +3,13 @@ using TINK.Model;
namespace TINK.ViewModel.Map
{
/// <summary> Interface for filtering. </summary>
/// <remarks> Holds a dictionary of filters which might or might not be appield depending on filter state.</remarks>
public interface IGroupFilterMapPage : IDictionary<string /* Filter*/, FilterState /* on or off*/>
{
/// <summary> Performs filtering on response-group. </summary>
IEnumerable<string> DoFilter(IEnumerable<string> filter = null);
/// <summary> Interface for filtering. </summary>
/// <remarks> Holds a dictionary of filters which might or might not be appield depending on filter state.</remarks>
public interface IGroupFilterMapPage : IDictionary<string /* Filter*/, FilterState /* on or off*/>
{
/// <summary> Performs filtering on response-group. </summary>
IEnumerable<string> DoFilter(IEnumerable<string> filter = null);
IList<string> GetGroup();
}
IList<string> GetGroup();
}
}

View file

@ -2,24 +2,24 @@
namespace TINK.ViewModel.Map
{
public interface ITinkKonradToggleViewModel
{
IGroupFilterMapPage FilterDictionary { get; }
public interface ITinkKonradToggleViewModel
{
IGroupFilterMapPage FilterDictionary { get; }
string CurrentFilter { get; }
string CurrentFilter { get; }
bool IsTinkEnabled { get; }
bool IsTinkEnabled { get; }
Color TinkColor { get; }
Color TinkColor { get; }
Color NoTinkColor { get; }
Color NoTinkColor { get; }
bool IsKonradEnabled { get; }
bool IsKonradEnabled { get; }
Color KonradColor { get; }
Color KonradColor { get; }
Color NoKonradColor { get; }
Color NoKonradColor { get; }
bool IsToggleVisible { get; }
}
bool IsToggleVisible { get; }
}
}

File diff suppressed because it is too large Load diff

View file

@ -7,78 +7,78 @@ using Xamarin.Forms;
namespace TINK.ViewModel.Map
{
/// <remarks> Old name: MapPageFilter. </remarks>
public class TinkKonradToggleViewModel : ITinkKonradToggleViewModel
{
/// <summary> Constructs a map page filter view model object from values.</summary>
/// <param name="currentFilter">Filters and options dictionary.</param>
public TinkKonradToggleViewModel(IGroupFilterMapPage currentFilter)
{
FilterDictionary = currentFilter ?? new GroupFilterMapPage();
}
/// <remarks> Old name: MapPageFilter. </remarks>
public class TinkKonradToggleViewModel : ITinkKonradToggleViewModel
{
/// <summary> Constructs a map page filter view model object from values.</summary>
/// <param name="currentFilter">Filters and options dictionary.</param>
public TinkKonradToggleViewModel(IGroupFilterMapPage currentFilter)
{
FilterDictionary = currentFilter ?? new GroupFilterMapPage();
}
/// <summary> Gets the filter values.</summary>
public IGroupFilterMapPage FilterDictionary { get; }
/// <summary> Gets the filter values.</summary>
public IGroupFilterMapPage FilterDictionary { get; }
/// <summary> Gets the activated filter.</summary>
public string CurrentFilter
{
get
{
return FilterDictionary.FirstOrDefault(x => x.Value == FilterState.On).Key ?? string.Empty;
}
}
/// <summary> Gets the activated filter.</summary>
public string CurrentFilter
{
get
{
return FilterDictionary.FirstOrDefault(x => x.Value == FilterState.On).Key ?? string.Empty;
}
}
/// <summary> Gets value whether TINK is enabled or not. </summary>
public bool IsTinkEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CARGOBIKE;
/// <summary> Gets value whether TINK is enabled or not. </summary>
public bool IsTinkEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CARGOBIKE;
/// <summary> Gets color of the TINK button. </summary>
public Color TinkColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
public Color NoTinkColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.FromRgb(210, 17, 20) : Color.White;
/// <summary> Gets value whether Konrad is enabled or not. </summary>
public bool IsKonradEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CITYBIKE;
/// <summary> Gets color of the TINK button. </summary>
public Color TinkColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
public Color NoTinkColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.FromRgb(210, 17, 20) : Color.White;
/// <summary> Gets value whether Konrad is enabled or not. </summary>
public bool IsKonradEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CITYBIKE;
/// <summary> Gets color of the Konrad button. </summary>
public Color KonradColor => CurrentFilter.GetBikeCategory() == FilterHelper.CITYBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
public Color NoKonradColor => CurrentFilter.GetBikeCategory() == FilterHelper.CITYBIKE ? Color.FromRgb(210, 17, 20) : Color.White;
/// <summary> Gets color of the Konrad button. </summary>
public Color KonradColor => CurrentFilter.GetBikeCategory() == FilterHelper.CITYBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
public Color NoKonradColor => CurrentFilter.GetBikeCategory() == FilterHelper.CITYBIKE ? Color.FromRgb(210, 17, 20) : Color.White;
/// <summary> Gets whether toggle functionality is visible or not. </summary>
public bool IsToggleVisible =>
FilterDictionary.Select(x => x.Key).ContainsGroupId(FilterHelper.CITYBIKE)
&& FilterDictionary.Select(x => x.Key).ContainsGroupId(FilterHelper.CARGOBIKE)
&& (IsTinkEnabled || IsKonradEnabled);
/// <summary> Gets whether toggle functionality is visible or not. </summary>
public bool IsToggleVisible =>
FilterDictionary.Select(x => x.Key).ContainsGroupId(FilterHelper.CITYBIKE)
&& FilterDictionary.Select(x => x.Key).ContainsGroupId(FilterHelper.CARGOBIKE)
&& (IsTinkEnabled || IsKonradEnabled);
/// <summary>
/// Toggles from bike group TINK to Konrad or vice versa.
/// Toggling means one of
/// - TINK => Konrad or
/// - TINK => Konrad.
/// </summary>
/// <param name="p_strCurrentFilterSet">Filter set to toggle.</param>
/// <returns></returns>
public TinkKonradToggleViewModel DoToggle()
{
var currentFilterSet = FilterDictionary.ToArray();
/// <summary>
/// Toggles from bike group TINK to Konrad or vice versa.
/// Toggling means one of
/// - TINK => Konrad or
/// - TINK => Konrad.
/// </summary>
/// <param name="p_strCurrentFilterSet">Filter set to toggle.</param>
/// <returns></returns>
public TinkKonradToggleViewModel DoToggle()
{
var currentFilterSet = FilterDictionary.ToArray();
if (currentFilterSet.Length < 2)
{
// There is nothing to toggle because filter set contains only one element.
return new TinkKonradToggleViewModel(FilterDictionary);
}
if (currentFilterSet.Length < 2)
{
// There is nothing to toggle because filter set contains only one element.
return new TinkKonradToggleViewModel(FilterDictionary);
}
var currentState = currentFilterSet[currentFilterSet.Length - 1].Value == FilterState.On
? FilterState.On
: FilterState.Off;
var currentState = currentFilterSet[currentFilterSet.Length - 1].Value == FilterState.On
? FilterState.On
: FilterState.Off;
var toggledFilterSet = new Dictionary<string, FilterState>();
var toggledFilterSet = new Dictionary<string, FilterState>();
foreach (var filterElement in currentFilterSet)
{
toggledFilterSet.Add(filterElement.Key, currentState);
currentState = filterElement.Value;
}
foreach (var filterElement in currentFilterSet)
{
toggledFilterSet.Add(filterElement.Key, currentState);
currentState = filterElement.Value;
}
return new TinkKonradToggleViewModel(new GroupFilterMapPage(toggledFilterSet));
}
}
return new TinkKonradToggleViewModel(new GroupFilterMapPage(toggledFilterSet));
}
}
}