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
{
/// Fired whenever a property changed.
public event PropertyChangedEventHandler PropertyChanged;
/// Holds the name of the host.
private string HostName { get; }
/// Holds value whether site caching is on or off.
bool IsSiteCachingOn { get; }
/// Constructs AGB view model
/// Holds value whether site caching is on or off.
/// Two letter ISO language name.
/// Delegate to get embedded html resource. Used as fallback if download from web page does not work and cache is empty.
/// View service to close page.
public GtcViewModel(
string hostName,
bool isSiteCachingOn,
Func 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.");
}
/// Gets the platfrom specific prefix.
private Func ResourceProvider { get; set; }
/// Agb information text.
private HtmlWebViewSource gtcHtml;
/// Agb information text.
public HtmlWebViewSource GtcHtml
{
get => gtcHtml;
set
{
gtcHtml = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(GtcHtml)));
}
}
/// Called when page is shown.
public async Task OnAppearing()
{
GtcHtml = await LegalInformationPageViewModel.GetGtc(HostName, "agbResourcePath", IsSiteCachingOn);
}
/// User clicks OK button.
public ICommand OnOk
{
get
{
return new Command(async () => await ViewService.PopModalAsync());
}
}
/// Reference to view service object.
private IViewService ViewService;
}
}