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 ;
2023-11-21 15:26:57 +01:00
using TINK.ViewModel.LegalInformation ;
2022-08-30 15:42:25 +02:00
using Xamarin.Forms ;
2021-05-13 20:03:07 +02:00
2023-11-21 15:26:57 +01:00
namespace TINK.ViewModel.WhatsNew.Gtc
2021-05-13 20:03:07 +02:00
{
2023-11-21 15:26:57 +01:00
public class GtcViewModel : INotifyPropertyChanged
2022-09-06 16:08:19 +02:00
{
/// <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>
2023-11-21 15:26:57 +01:00
public GtcViewModel (
2022-09-06 16:08:19 +02:00
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>
2023-11-21 15:26:57 +01:00
private HtmlWebViewSource gtcHtml ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Agb information text.</summary>
2023-11-21 15:26:57 +01:00
public HtmlWebViewSource GtcHtml
2022-09-06 16:08:19 +02:00
{
2023-11-21 15:26:57 +01:00
get = > gtcHtml ;
2022-09-06 16:08:19 +02:00
set
{
2023-11-21 15:26:57 +01:00
gtcHtml = value ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( GtcHtml ) ) ) ;
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> Called when page is shown. </summary>
public async Task OnAppearing ( )
{
2023-11-21 15:26:57 +01:00
GtcHtml = await LegalInformationPageViewModel . GetGtc ( 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
}