2021-05-13 20:16:41 +02:00
using System.ComponentModel ;
using Xamarin.Forms ;
using TINK.Services.CopriApi.ServerUris ;
2021-06-26 20:57:55 +02:00
using System ;
2021-05-13 20:16:41 +02:00
namespace TINK.ViewModel.Contact
{
public class HelpContactViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged ;
2021-06-26 20:57:55 +02:00
/// <summary> Gets the platfrom specific prefix. </summary>
private Func < string , string > ResourceProvider { get ; set ; }
2021-05-13 20:16:41 +02:00
/// <summary> Holds value wether site caching is on or off.</summary>
bool IsSiteCachingOn { get ; }
/// <summary> Constructs view model.</summary>
/// <param name="isSiteCachingOn">Set of user permissions</param>
2021-06-26 20:57:55 +02:00
/// <param name="resourceProvider">Delegate to get an an embedded html ressource. Used as fallback if download from web page does not work and cache is empty.</param>
2021-05-13 20:16:41 +02:00
public HelpContactViewModel (
string hostName ,
2021-06-26 20:57:55 +02:00
bool isSiteCachingOn ,
Func < string , string > resourceProvider )
2021-05-13 20:16:41 +02:00
{
HostName = hostName ;
IsSiteCachingOn = isSiteCachingOn ;
2021-06-26 20:57:55 +02:00
ResourceProvider = resourceProvider
? ? throw new ArgumentException ( $"Can not instantiate {typeof(HelpContactViewModel)}-object. No ressource provider availalbe." ) ;
2021-05-13 20:16:41 +02:00
}
/// <summary> Holds the name of the host.</summary>
private string HostName { get ; }
/// <summary> Called when page is shown. </summary>
public async void OnAppearing ( )
{
RentBikeText = new HtmlWebViewSource
{
Html = HostName . GetIsCopri ( )
2021-06-26 20:57:55 +02:00
? ResourceProvider ( "HtmlResouces.V02.InfoRentBike.html" )
: await ViewModelHelper . GetSource ( $"https://{HostName}/{CopriHelper.SHAREE_SILTEFOLDERNAME}/tariff_info_1.html" , IsSiteCachingOn )
2021-05-13 20:16:41 +02:00
} ;
TypesOfBikesText = new HtmlWebViewSource
{
Html = HostName . GetIsCopri ( )
2021-06-26 20:57:55 +02:00
? ResourceProvider ( "HtmlResouces.V02.InfoTypesOfBikes.html" )
2021-05-13 20:16:41 +02:00
: await ViewModelHelper . GetSource ( $"https://{HostName}/{CopriHelper.SHAREE_SILTEFOLDERNAME}/bike_info.html" , IsSiteCachingOn )
} ;
}
private HtmlWebViewSource rentBikeText ;
private HtmlWebViewSource typesOfBikesText ;
public HtmlWebViewSource RentBikeText
{
get = > rentBikeText ;
set
{
rentBikeText = value ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( RentBikeText ) ) ) ;
}
}
public HtmlWebViewSource TypesOfBikesText
{
get = > typesOfBikesText ;
set
{
typesOfBikesText = value ;
PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( TypesOfBikesText ) ) ) ;
}
}
}
}