2022-10-03 17:55:10 +02:00
using System ;
2021-05-13 20:03:07 +02:00
using System.ComponentModel ;
using System.Threading.Tasks ;
2022-08-30 15:42:25 +02:00
using System.Windows.Input ;
using TINK.View ;
2021-05-13 20:03:07 +02:00
using TINK.ViewModel.Info ;
2022-08-30 15:42:25 +02:00
using Xamarin.Forms ;
2021-05-13 20:03:07 +02:00
namespace TINK.ViewModel.WhatsNew.Agb
{
2022-09-06 16:08:19 +02:00
public class AgbViewModel : INotifyPropertyChanged
{
/// <summary> Fired whenever a property changed.</summary>
public event PropertyChangedEventHandler PropertyChanged ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the name of the host.</summary>
private string HostName { get ; }
2021-05-13 20:03:07 +02:00
2023-05-09 08:47:52 +02:00
/// <summary> Holds value whether site caching is on or off.</summary>
2022-09-06 16:08:19 +02:00
bool IsSiteCachingOn { get ; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Constructs AGB view model</summary>
2023-05-09 08:47:52 +02:00
/// <param name="isSiteCachingOn">Holds value whether site caching is on or off.</param>
2022-09-06 16:08:19 +02:00
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
2023-05-09 08:47:52 +02:00
/// <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>
2022-09-06 16:08:19 +02:00
/// <param name="viewService">View service to close page.</param>
public AgbViewModel (
string hostName ,
bool isSiteCachingOn ,
Func < string , string > resourceProvider ,
IViewService viewService )
{
HostName = hostName ;
IsSiteCachingOn = isSiteCachingOn ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
ViewService = viewService
? ? throw new ArgumentException ( $"Can not instantiate {typeof(WhatsNewViewModel)}-object. No view available." ) ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
ResourceProvider = resourceProvider
2023-05-09 08:47:52 +02:00
? ? throw new ArgumentException ( $"Can not instantiate {typeof(WhatsNewViewModel)}-object. No resource provider centered." ) ;
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the platfrom specific prefix. </summary>
private Func < string , string > ResourceProvider { get ; set ; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Agb information text.</summary>
private HtmlWebViewSource infoAgb ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Agb information text.</summary>
public HtmlWebViewSource InfoAgb
{
get = > infoAgb ;
set
{
infoAgb = value ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( InfoAgb ) ) ) ;
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Called when page is shown. </summary>
public async Task OnAppearing ( )
{
2022-10-03 17:55:10 +02:00
InfoAgb = await InfoPageViewModel . GetAgb ( HostName , "agbResourcePath" , IsSiteCachingOn ) ;
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> User clicks OK button.</summary>
public ICommand OnOk
{
get
{
return new Command ( async ( ) = > await ViewService . PopModalAsync ( ) ) ;
}
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Reference to view service object.</summary>
private IViewService ViewService ;
}
2021-05-13 20:03:07 +02:00
}