mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-21 04:26:29 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,84 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShareeBike.Model;
|
||||
using ShareeBike.Model.Connector;
|
||||
using ShareeBike.Model.Connector.Filter;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace ShareeBike.ViewModel.Map
|
||||
{
|
||||
/// <remarks> Old name: MapPageFilter. </remarks>
|
||||
public class CargoCitybikeToggleViewModel : ICargoCitybikeToggleViewModel
|
||||
{
|
||||
/// <summary> Constructs a map page filter view model object from values.</summary>
|
||||
/// <param name="currentFilter">Filters and options dictionary.</param>
|
||||
public CargoCitybikeToggleViewModel(IGroupFilterMapPage currentFilter)
|
||||
{
|
||||
FilterDictionary = currentFilter ?? new GroupFilterMapPage();
|
||||
}
|
||||
|
||||
/// <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 value whether ShareeBike is enabled or not. </summary>
|
||||
public bool IsCargoEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CARGOBIKE;
|
||||
|
||||
/// <summary> Gets color of the ShareeBike button. </summary>
|
||||
public Color CargoColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
|
||||
public Color NoCargoColor => CurrentFilter.GetBikeCategory() == FilterHelper.CARGOBIKE ? Color.FromRgb(210, 17, 20) : Color.White;
|
||||
/// <summary> Gets value whether Citybike is enabled or not. </summary>
|
||||
public bool IsCitybikeEnabled => !string.IsNullOrEmpty(CurrentFilter) && CurrentFilter.GetBikeCategory() != FilterHelper.CITYBIKE;
|
||||
|
||||
/// <summary> Gets color of the Citybike button. </summary>
|
||||
public Color CitybikeColor => CurrentFilter.GetBikeCategory() == FilterHelper.CITYBIKE ? Color.White : Color.FromRgba(0, 0, 0, 0);
|
||||
public Color NoCitybikeColor => 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)
|
||||
&& (IsCargoEnabled || IsCitybikeEnabled);
|
||||
|
||||
/// <summary>
|
||||
/// Toggles from bike group Cargo to Citybike or vice versa.
|
||||
/// Toggling means one of
|
||||
/// - ShareeBike => Citybike or
|
||||
/// - ShareeBike => Citybike.
|
||||
/// </summary>
|
||||
/// <param name="p_strCurrentFilterSet">Filter set to toggle.</param>
|
||||
/// <returns></returns>
|
||||
public CargoCitybikeToggleViewModel DoToggle()
|
||||
{
|
||||
var currentFilterSet = FilterDictionary.ToArray();
|
||||
|
||||
if (currentFilterSet.Length < 2)
|
||||
{
|
||||
// There is nothing to toggle because filter set contains only one element.
|
||||
return new CargoCitybikeToggleViewModel(FilterDictionary);
|
||||
}
|
||||
|
||||
var currentState = currentFilterSet[currentFilterSet.Length - 1].Value == FilterState.On
|
||||
? FilterState.On
|
||||
: FilterState.Off;
|
||||
|
||||
var toggledFilterSet = new Dictionary<string, FilterState>();
|
||||
|
||||
foreach (var filterElement in currentFilterSet)
|
||||
{
|
||||
toggledFilterSet.Add(filterElement.Key, currentState);
|
||||
currentState = filterElement.Value;
|
||||
}
|
||||
|
||||
return new CargoCitybikeToggleViewModel(new GroupFilterMapPage(toggledFilterSet));
|
||||
}
|
||||
}
|
||||
}
|
31
SharedBusinessLogic/ViewModel/Map/EmptyToggleViewModel.cs
Normal file
31
SharedBusinessLogic/ViewModel/Map/EmptyToggleViewModel.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using Xamarin.Forms;
|
||||
|
||||
namespace ShareeBike.ViewModel.Map
|
||||
{
|
||||
/// <summary> Holds an empty filter object.</summary>
|
||||
/// <remarks>Old name: EmptyMapPageFilter</remarks>
|
||||
public class EmptyToggleViewModel : ICargoCitybikeToggleViewModel
|
||||
{
|
||||
/// <summary> Holds the map page filter.</summary>
|
||||
public IGroupFilterMapPage FilterDictionary => new GroupFilterMapPage();
|
||||
|
||||
/// <summary> Active filter</summary>
|
||||
public string CurrentFitler => string.Empty;
|
||||
|
||||
public bool IsCargoEnabled => false;
|
||||
|
||||
public Color CargoColor => Color.Default;
|
||||
|
||||
public Color NoCargoColor => Color.Default;
|
||||
|
||||
public bool IsCitybikeEnabled => false;
|
||||
|
||||
public Color CitybikeColor => Color.Default;
|
||||
|
||||
public Color NoCitybikeColor => Color.Default;
|
||||
|
||||
public bool IsToggleVisible => false;
|
||||
|
||||
public string CurrentFilter => string.Empty;
|
||||
}
|
||||
}
|
67
SharedBusinessLogic/ViewModel/Map/GroupFilterMapPage.cs
Normal file
67
SharedBusinessLogic/ViewModel/Map/GroupFilterMapPage.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShareeBike.Model;
|
||||
using ShareeBike.Model.Connector.Filter;
|
||||
|
||||
namespace ShareeBike.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();
|
||||
}
|
||||
|
||||
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> Performs filtering on response-group. </summary>
|
||||
public IEnumerable<string> DoFilter(IEnumerable<string> filter = null) => Filter.DoFilter(filter);
|
||||
|
||||
private IDictionary<string, FilterState> FilterDictionary { get; }
|
||||
|
||||
public FilterState this[string key] { get => FilterDictionary[key]; set => FilterDictionary[key] = value; }
|
||||
|
||||
public ICollection<string> Keys => FilterDictionary.Keys;
|
||||
|
||||
public ICollection<FilterState> Values => FilterDictionary.Values;
|
||||
|
||||
public int Count => FilterDictionary.Count;
|
||||
|
||||
public bool IsReadOnly => true;
|
||||
|
||||
public void Add(string key, FilterState value) => throw new System.NotImplementedException();
|
||||
|
||||
public void Add(KeyValuePair<string, FilterState> item) => throw new System.NotImplementedException();
|
||||
|
||||
public void Clear() => throw new System.NotImplementedException();
|
||||
|
||||
public bool Contains(KeyValuePair<string, FilterState> item) => FilterDictionary.Contains(item);
|
||||
|
||||
public bool ContainsKey(string key) => FilterDictionary.ContainsKey(key);
|
||||
|
||||
public void CopyTo(KeyValuePair<string, FilterState>[] array, int arrayIndex) => FilterDictionary.CopyTo(array, arrayIndex);
|
||||
|
||||
public IEnumerator<KeyValuePair<string, FilterState>> GetEnumerator() => FilterDictionary.GetEnumerator();
|
||||
|
||||
public bool Remove(string key) => 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);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => FilterDictionary.GetEnumerator();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ShareeBike.Model;
|
||||
|
||||
namespace ShareeBike.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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using Xamarin.Forms;
|
||||
|
||||
namespace ShareeBike.ViewModel.Map
|
||||
{
|
||||
public interface ICargoCitybikeToggleViewModel
|
||||
{
|
||||
IGroupFilterMapPage FilterDictionary { get; }
|
||||
|
||||
string CurrentFilter { get; }
|
||||
|
||||
bool IsCargoEnabled { get; }
|
||||
|
||||
Color CargoColor { get; }
|
||||
|
||||
Color NoCargoColor { get; }
|
||||
|
||||
bool IsCitybikeEnabled { get; }
|
||||
|
||||
Color CitybikeColor { get; }
|
||||
|
||||
Color NoCitybikeColor { get; }
|
||||
|
||||
bool IsToggleVisible { get; }
|
||||
}
|
||||
}
|
15
SharedBusinessLogic/ViewModel/Map/IGroupFilterMapPage.cs
Normal file
15
SharedBusinessLogic/ViewModel/Map/IGroupFilterMapPage.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using ShareeBike.Model;
|
||||
|
||||
namespace ShareeBike.ViewModel.Map
|
||||
{
|
||||
/// <summary> Interface for filtering. </summary>
|
||||
/// <remarks> Holds a dictionary of filters which might or might not be applied 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();
|
||||
}
|
||||
}
|
1060
SharedBusinessLogic/ViewModel/Map/MapPageViewModel.cs
Normal file
1060
SharedBusinessLogic/ViewModel/Map/MapPageViewModel.cs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue