Version 3.0.342

This commit is contained in:
Oliver Hauff 2022-10-03 17:55:10 +02:00
parent d852ccef4c
commit 2cde196f16
54 changed files with 998 additions and 498 deletions

View file

@ -1,4 +1,4 @@
using Serilog;
using Serilog;
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
@ -355,32 +355,6 @@ namespace TINK.ViewModel.Bikes.Bike
/// <summary> Gets the value of property <see cref="StateColor"/> when PropertyChanged was fired. </summary>
public Color LastStateColor { get; set; }
/// <summary> Command object to bind login page redirect link to view model.</summary>
public System.Windows.Input.ICommand ShowAgbTappedCommand
=> new Xamarin.Forms.Command(() => ShowAgbPageAsync());
/// <summary> Opens login page. </summary>
public void ShowAgbPageAsync()
{
try
{
var url = GetUrlFirstOrDefault(TariffDescription.OperatorAgb);
if (string.IsNullOrEmpty(url))
{
// No url contained in string.
return;
}
OpenUrlInBrowser(url);
}
catch (Exception p_oException)
{
Log.Error("An unexpected error occurred opening broser. {@Exception}", p_oException);
return;
}
}
/// <summary> Gets first url from text.</summary>
/// <param name="htmlSource">url to extract text from.</param>
/// <returns>Gets first url or an empty string if on url is contained in text.</returns>

View file

@ -36,7 +36,7 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
IUser activeUser) : base(
selectedBike,
AppResources.ActionReturn, // Copri button text "Miete beenden"
false, // Do no more allow to return bike.
true, // Show button to enabled returning of bike.
isConnectedDelegate,
connectorFactory,
geolocation,

View file

@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Linq;
using TINK.Model.Bikes.BikeInfoNS;
@ -9,8 +9,6 @@ namespace TINK.ViewModel.Bikes.Bike
/// </summary>
public class TariffDescriptionViewModel
{
private const string AGBKEY = "AGB";
public TariffDescriptionViewModel(RentalDescription tariff)
{
Name = tariff?.Name ?? string.Empty;
@ -20,13 +18,8 @@ namespace TINK.ViewModel.Bikes.Bike
: new ObservableCollection<RentalDescription.TariffElement>();
InfoEntries = tariff != null && tariff?.InfoEntries != null
? new ObservableCollection<string>(tariff.InfoEntries.OrderBy(x => x.Key).Where(x => x.Value.Key != AGBKEY).Select(x => x.Value.Value))
? new ObservableCollection<string>(tariff.InfoEntries.OrderBy(x => x.Key).Select(x => x.Value.Value))
: new ObservableCollection<string>();
OperatorAgb = tariff?.InfoEntries != null
&& tariff.InfoEntries.Select(x => x.Value.Key).Contains(AGBKEY)
? tariff?.InfoEntries.FirstOrDefault(x => x.Value.Key == AGBKEY).Value.Value
: string.Empty;
}
/// <summary>
@ -44,9 +37,6 @@ namespace TINK.ViewModel.Bikes.Bike
/// </summary>
public ObservableCollection<string> InfoEntries { get; private set; }
/// <summary> Info about operator agb as HTML (i.g. text and hyperlink). </summary>
public string OperatorAgb { get; set; }
public RentalDescription.TariffElement TarifEntry1 => TariffEntries.Count > 0 ? TariffEntries[0] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry2 => TariffEntries.Count > 1 ? TariffEntries[1] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry3 => TariffEntries.Count > 2 ? TariffEntries[2] : new RentalDescription.TariffElement();

View file

@ -1,5 +1,12 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Serilog;
using TINK.Model;
using TINK.Model.Bikes;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi;
using TINK.ViewModel.Info;
using Xamarin.Forms;
namespace TINK.ViewModel.Contact
@ -12,24 +19,67 @@ namespace TINK.ViewModel.Contact
/// <summary> Holds value wether site caching is on or off.</summary>
bool IsSiteCachingOn { get; }
private string FeesResourcePath { get; }
/// <summary>
/// Relative path to fees resources of empty if value was not yet querried from backend.
/// </summary>
private string FeesResourcePath { get; set; }
private string BikesResourcePath { get; }
/// <summary>
/// Relative path to bike info resources of empty if value was not yet querried from backend.
/// </summary>
private string BikesResourcePath { get; set; }
private bool _IsIdle = false;
/// <summary>
/// Is true if no action is pending, false otherwise.
/// </summary>
public bool IsIdle
{
get => _IsIdle;
private set
{
if (_IsIdle == value)
{
// Nothing to do.
return;
}
_IsIdle = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsIdle)));
return;
}
}
/// <summary>
/// Object to querry resources urls object from backend if required.
/// This object is used to update resources path values <see cref="FeesResourcePath"/>, and <see cref="BikesResourcePath"/> from.
/// </summary>
private Func<IQuery> QueryProvider { get; }
/// <summary>
/// Action to update shared resources urls object exposed by main model.
/// </summary>
private Action<IResourceUrls> UpdateUrlsAction { get; }
/// <summary> Constructs view model.</summary>
/// <param name="isSiteCachingOn">Set of user permissions</param>
/// <param name="resourceProvider">Delegate to get an an embedded html ressource. Used as fallback if download from web page does not work and cache is empty.</param>
/// <param name="query">Object to querry resources path values if required.</param>
public FeesAndBikesPageViewModel(
string hostName,
string feesResourcePath,
string bikesResourcePath,
bool isSiteCachingOn)
bool isSiteCachingOn,
Func<IQuery> queryProvider,
Action<IResourceUrls> updateUrlsAction)
{
HostName = hostName;
FeesResourcePath = feesResourcePath;
BikesResourcePath = bikesResourcePath;
IsSiteCachingOn = isSiteCachingOn;
QueryProvider = queryProvider;
UpdateUrlsAction = updateUrlsAction;
}
/// <summary> Holds the name of the host.</summary>
@ -38,10 +88,38 @@ namespace TINK.ViewModel.Contact
/// <summary> Called when page is shown. </summary>
public async void OnAppearing()
{
// Get resource urls object from backend.
async Task<IResourceUrls> GetUrls()
{
Result<BikeCollection> bikes;
try
{
bikes = await QueryProvider().GetBikesAsync();
}
catch (Exception ex)
{
Log.ForContext<FeesAndBikesPageViewModel>().Error($"Getting resource urls from COPRI failed. {ex.Message}");
return new ResourceUrls();
}
return bikes?.GeneralData?.ResourceUrls ?? new ResourceUrls();
}
// Set state to busy.
IsIdle = false;
if (string.IsNullOrEmpty(FeesResourcePath))
{
var urls = await GetUrls();
FeesResourcePath = urls.FeesResourcePath;
BikesResourcePath = urls.BikesResourcePath;
UpdateUrlsAction(urls); // Update main model to prevent duplicate queries.
}
RentBikeText = new HtmlWebViewSource
{
Html = !string.IsNullOrEmpty(FeesResourcePath)
? await ViewModelHelper.GetSource($"https://{HostName}/{FeesResourcePath}" /* "site/tariff_info_1.html" */, IsSiteCachingOn)
? await ViewModelHelper.GetSource($"https://{HostName}/{FeesResourcePath}", IsSiteCachingOn)
: await Task.FromResult(ViewModelHelper.FromBody("No fees resource available. Resource path is null or empty."))
};
@ -51,6 +129,9 @@ namespace TINK.ViewModel.Contact
? await ViewModelHelper.GetSource($"https://{HostName}/{BikesResourcePath}" /*"site/bike_info.html"*/, IsSiteCachingOn)
: await Task.FromResult(ViewModelHelper.FromBody("No bikes instruction resource available. Resource path is null or empty."))
};
// Set state to idle.
IsIdle = true;
}
private HtmlWebViewSource rentBikeText;

View file

@ -1,10 +1,14 @@
using System;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Serilog;
using TINK.Model.Bikes;
using TINK.Model;
using TINK.Model.Device;
using TINK.Model.Services.CopriApi;
using Xamarin.Essentials;
using Xamarin.Forms;
using TINK.Model.Connector;
namespace TINK.ViewModel.Info
{
@ -20,39 +24,80 @@ namespace TINK.ViewModel.Info
/// <summary> Holds value wether site caching is on or off.</summary>
bool IsSiteCachingOn { get; }
private string AgbResourcePath { get; }
private string PrivacyResourcePath { get; }
private string ImpressResourcePath { get; }
/// <summary>
/// Relative path to agb resources of empty if value was not yet querried from backend.
/// </summary>
private string AgbResourcePath { get; set; }
/// <summary>
/// Holds the current ui two letter ISO language name.
/// Relative path to privacy resources of empty if value was not yet querried from backend.
/// </summary>
private string UiIsoLanguageName { get; }
private string PrivacyResourcePath { get; set; }
/// <summary>
/// Relative path to impress resources of empty if value was not yet querried from backend.
/// </summary>
private string ImpressResourcePath { get; set; }
private bool _IsIdle = false;
/// <summary>
/// Is true if no action is pending, false otherwise.
/// </summary>
public bool IsIdle
{
get => _IsIdle;
private set
{
if (_IsIdle == value)
{
// Nothing to do.
return;
}
_IsIdle = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsIdle)));
return;
}
}
/// <summary>
/// Object to querry resources urls object from backend if required.
/// This object is used to update resources path values <see cref="AgbResourcePath"/>, <see cref="PrivacyResourcePath"/> and <see cref="ImpressResourcePath"/> from.
/// </summary>
private Func<IQuery> QueryProvider { get; }
/// <summary>
/// Action to update shared resources urls object exposed by main model.
/// </summary>
private Action<IResourceUrls> UpdateUrlsAction { get; }
/// <summary> Constructs Info view model</summary>
/// <param name="hostName">Name of the host to get html resources from.</param>
/// <param name="isSiteCachingOn">Holds value wether site caching is on or off.</param>
/// <param name="agbResourcePath"> Agb resouce path received from backend.</param>
/// <param name="privacyResourcePath"> Privacy resouce path received from backend.</param>
/// <param name="impressResourcePath"> Impress resouce path received from backend.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="resourceProvider">Delegate to get an an embedded html ressource. Used as fallback if download from web page does not work and cache is empty.</param>
/// <param name="queryProvider">Object to querry resources urls object from backend if required.</param>
/// <param name="updateUrlsAction">Action to update shared resources urls object</param>
public InfoPageViewModel(
string hostName,
string agbResourcePath,
string privacyResourcePath,
string impressResourcePath,
bool isSiteCachingOn,
string uiIsoLangugageName,
Func<string, string> resourceProvider)
Func<string, string> resourceProvider,
Func<IQuery> queryProvider,
Action<IResourceUrls> updateUrlsAction)
{
HostName = hostName;
AgbResourcePath = agbResourcePath;
PrivacyResourcePath = privacyResourcePath;
ImpressResourcePath = impressResourcePath;
IsSiteCachingOn = isSiteCachingOn;
UiIsoLanguageName = uiIsoLangugageName;
QueryProvider = queryProvider;
UpdateUrlsAction = updateUrlsAction;
InfoAgb = new HtmlWebViewSource { Html = "<html>Loading...</html>" };
@ -63,6 +108,37 @@ namespace TINK.ViewModel.Info
/// <summary> Called when page is shown. </summary>
public async void OnAppearing()
{
// Get resource urls object from backend.
async Task<IResourceUrls> GetUrls()
{
Result<BikeCollection> bikes;
try
{
bikes = await QueryProvider().GetBikesAsync();
}
catch (Exception ex)
{
Log.ForContext<InfoPageViewModel>().Error($"Getting resource urls from COPRI failed. {ex.Message}");
return new ResourceUrls();
}
IResourceUrls resourceUrls = bikes?.GeneralData?.ResourceUrls ?? new ResourceUrls();
return resourceUrls;
}
// Set state to busy.
IsIdle = false;
// Check if urls to show info from are already known.
if (string.IsNullOrEmpty(PrivacyResourcePath))
{
var urls = await GetUrls();
PrivacyResourcePath = urls.PrivacyResourcePath;
ImpressResourcePath = urls.ImpressResourcePath;
AgbResourcePath = urls.AgbResourcePath;
UpdateUrlsAction(urls); // Update main model to prevent duplicate queries.
}
// Gets privacy info from server.
async Task<HtmlWebViewSource> GetInfoPrivacy()
{
@ -113,11 +189,14 @@ namespace TINK.ViewModel.Info
};
}
InfoAgb = await GetAgb(HostName, AgbResourcePath, IsSiteCachingOn, UiIsoLanguageName);
InfoAgb = await GetAgb(HostName, AgbResourcePath, IsSiteCachingOn);
InfoPrivacy = await GetInfoPrivacy();
InfoImpressum = await GetImpressum();
// Set state to idle.
IsIdle = true;
}
/// <summary> Gets the AGBs</summary>
@ -126,8 +205,7 @@ namespace TINK.ViewModel.Info
public static async Task<HtmlWebViewSource> GetAgb(
string hostName,
string agbResourcePath,
bool isSiteCachingOn,
string uiIsoLangugageName)
bool isSiteCachingOn)
{
string GetUriText()
=> $"https://{hostName}/{agbResourcePath}";

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
@ -228,27 +228,6 @@ namespace TINK.ViewModel
return l_oError;
}
/// <summary> User tabbed a URI. </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="eventArgs">Event arguments</param>
public static void OnNavigating(object sender, WebNavigatingEventArgs eventArgs)
{
if (!eventArgs.Url.ToUpper().StartsWith("HTTP"))
{
// An internal link was detected.
// Stay inside WebView
eventArgs.Cancel = false;
return;
}
// Do not navigate outside the document.
eventArgs.Cancel = true;
DependencyService.Get<IExternalBrowserService>().OpenUrl(eventArgs.Url);
}
/// <summary> Gets the user group if a user friendly name.</summary>
/// <param name="user"></param>
/// <returns></returns>

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Input;
@ -19,11 +19,6 @@ namespace TINK.ViewModel.WhatsNew.Agb
/// <summary> Holds value wether site caching is on or off.</summary>
bool IsSiteCachingOn { get; }
/// <summary>
/// Holds the current ui two letter ISO language name.
/// </summary>
private string UiIsoLanguageName { get; }
/// <summary> Constructs AGB view model</summary>
/// <param name="isSiteCachingOn">Holds value wether site caching is on or off.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
@ -32,13 +27,11 @@ namespace TINK.ViewModel.WhatsNew.Agb
public AgbViewModel(
string hostName,
bool isSiteCachingOn,
string uiIsoLangugageName,
Func<string, string> resourceProvider,
IViewService viewService)
{
HostName = hostName;
IsSiteCachingOn = isSiteCachingOn;
UiIsoLanguageName = uiIsoLangugageName;
ViewService = viewService
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available.");
@ -67,7 +60,7 @@ namespace TINK.ViewModel.WhatsNew.Agb
/// <summary> Called when page is shown. </summary>
public async Task OnAppearing()
{
InfoAgb = await InfoPageViewModel.GetAgb(HostName, "agbResourcePath", IsSiteCachingOn, UiIsoLanguageName);
InfoAgb = await InfoPageViewModel.GetAgb(HostName, "agbResourcePath", IsSiteCachingOn);
}
/// <summary> User clicks OK button.</summary>