mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Version 3.0.342
This commit is contained in:
parent
d852ccef4c
commit
2cde196f16
54 changed files with 998 additions and 498 deletions
|
@ -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}";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue