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