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,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue