using System; using System.ComponentModel; using System.Threading.Tasks; using System.Windows.Input; using TINK.View; using TINK.ViewModel.Info; using Xamarin.Forms; 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. /// Two letter ISO language name. /// 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 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 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 InfoPageViewModel.GetAgb(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; } }