sharee.bike-App/TINKLib/ViewModel/FeesAndBikes/FeesAndBikesPageViewModel.cs

81 lines
2.9 KiB
C#
Raw Normal View History

2021-05-13 20:16:41 +02:00
using System.ComponentModel;
using Xamarin.Forms;
2022-01-22 18:28:01 +01:00
using System.Threading.Tasks;
2021-06-26 20:57:55 +02:00
2021-05-13 20:16:41 +02:00
namespace TINK.ViewModel.Contact
{
2022-01-22 18:28:01 +01:00
public class FeesAndBikesPageViewModel : INotifyPropertyChanged
2021-05-13 20:16:41 +02:00
{
public event PropertyChangedEventHandler PropertyChanged;
2021-06-26 20:57:55 +02:00
2021-05-13 20:16:41 +02:00
/// <summary> Holds value wether site caching is on or off.</summary>
bool IsSiteCachingOn { get; }
2022-01-22 18:28:01 +01:00
private string FeesResourcePath { get; }
private string BikesResourcePath { get; }
2021-05-13 20:16:41 +02:00
/// <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>
2022-01-22 18:28:01 +01:00
public FeesAndBikesPageViewModel(
2021-05-13 20:16:41 +02:00
string hostName,
2022-01-22 18:28:01 +01:00
string feesResourcePath,
string bikesResourcePath,
bool isSiteCachingOn)
2021-05-13 20:16:41 +02:00
{
HostName = hostName;
2022-01-22 18:28:01 +01:00
FeesResourcePath = feesResourcePath;
BikesResourcePath = bikesResourcePath;
2021-05-13 20:16:41 +02:00
IsSiteCachingOn = isSiteCachingOn;
}
/// <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
{
2022-01-22 18:28:01 +01:00
Html = !string.IsNullOrEmpty(FeesResourcePath)
? await ViewModelHelper.GetSource($"https://{HostName}/{FeesResourcePath}" /* "site/tariff_info_1.html" */, IsSiteCachingOn)
: await Task.FromResult(ViewModelHelper.FromBody("No fees resource available. Resource path is null or empty."))
2021-05-13 20:16:41 +02:00
};
TypesOfBikesText = new HtmlWebViewSource
{
2022-01-22 18:28:01 +01:00
Html = !string.IsNullOrEmpty(BikesResourcePath)
? await ViewModelHelper.GetSource($"https://{HostName}/{BikesResourcePath}" /*"site/bike_info.html"*/, IsSiteCachingOn)
: await Task.FromResult(ViewModelHelper.FromBody("No bikes instruction resource available. Resource path is null or empty."))
2021-05-13 20:16:41 +02:00
};
}
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)));
}
}
}
}