sharee.bike-App/TINKLib/ViewModel/WhatsNew/Gtc/GtcViewModel.cs
2023-11-21 15:26:57 +01:00

78 lines
2.4 KiB
C#

using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Input;
using TINK.View;
using TINK.ViewModel.LegalInformation;
using Xamarin.Forms;
namespace TINK.ViewModel.WhatsNew.Gtc
{
public class GtcViewModel : INotifyPropertyChanged
{
/// <summary> Fired whenever a property changed.</summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary> Holds the name of the host.</summary>
private string HostName { get; }
/// <summary> Holds value whether site caching is on or off.</summary>
bool IsSiteCachingOn { get; }
/// <summary> Constructs AGB view model</summary>
/// <param name="isSiteCachingOn">Holds value whether site caching is on or off.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="resourceProvider">Delegate to get embedded html resource. Used as fallback if download from web page does not work and cache is empty.</param>
/// <param name="viewService">View service to close page.</param>
public GtcViewModel(
string hostName,
bool isSiteCachingOn,
Func<string, string> resourceProvider,
IViewService viewService)
{
HostName = hostName;
IsSiteCachingOn = isSiteCachingOn;
ViewService = viewService
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available.");
ResourceProvider = resourceProvider
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No resource provider centered.");
}
/// <summary> Gets the platfrom specific prefix. </summary>
private Func<string, string> ResourceProvider { get; set; }
/// <summary> Agb information text.</summary>
private HtmlWebViewSource gtcHtml;
/// <summary> Agb information text.</summary>
public HtmlWebViewSource GtcHtml
{
get => gtcHtml;
set
{
gtcHtml = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(GtcHtml)));
}
}
/// <summary> Called when page is shown. </summary>
public async Task OnAppearing()
{
GtcHtml = await LegalInformationPageViewModel.GetGtc(HostName, "agbResourcePath", IsSiteCachingOn);
}
/// <summary> User clicks OK button.</summary>
public ICommand OnOk
{
get
{
return new Command(async () => await ViewService.PopModalAsync());
}
}
/// <summary> Reference to view service object.</summary>
private IViewService ViewService;
}
}