using TINK.View;
using System.Windows.Input;
using Xamarin.Forms;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using TINK.ViewModel.Info;
using TINK.Model.User.Account;
namespace TINK.ViewModel.WhatsNew.Agb
{
public class AgbViewModel : INotifyPropertyChanged
{
/// Fired whenever a property changed.
public event PropertyChangedEventHandler PropertyChanged;
/// Holds the name of the host.
private string HostName { get; }
/// Holds value wether site caching is on or off.
bool IsSiteCachingOn { get; }
/// Constructs AGB view model
/// Holds value wether site caching is on or off.
/// Delegate to get an an embedded html ressource. Used as fallback if download from web page does not work and cache is empty.
/// View service to close page.
public AgbViewModel(
string hostName,
bool isSiteCachingOn,
Func resourceProvider,
IViewService p_oViewService)
{
HostName = hostName;
IsSiteCachingOn = isSiteCachingOn;
ViewService = p_oViewService
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available.");
ResourceProvider = resourceProvider
?? throw new ArgumentException($"Can not instantiate {typeof(WhatsNewViewModel)}-object. No ressource provider availalbe.");
}
/// Gets the platfrom specific prefix.
private Func ResourceProvider { get; set; }
/// Agb information text.
private HtmlWebViewSource infoAgb;
/// Agb information text.
public HtmlWebViewSource InfoAgb
{
get => infoAgb;
set
{
infoAgb = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InfoAgb)));
}
}
/// Called when page is shown.
public async Task OnAppearing()
{
InfoAgb = await InfoViewModel.GetAgb(HostName, IsSiteCachingOn, ResourceProvider);
}
/// User clicks OK button.
public ICommand OnOk
{
get
{
return new Command(async () => await ViewService.PopModalAsync());
}
}
/// Reference to view service object.
private IViewService ViewService;
}
}