sharee.bike-App/LastenradBayern/TINK/View/WhatsNew/WhatsNewPage.xaml.cs
2023-09-22 11:38:42 +02:00

106 lines
3.5 KiB
C#

using System;
using System.Threading.Tasks;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using TINK.Model.Device;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace TINK.View.WhatsNew
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class WhatsNewPage : ContentPage, IViewService
{
/// <summary> Holds a reference on the view model. </summary>
private ViewModel.WhatsNew.WhatsNewViewModel WhatsNewViewModel;
/// <summary> Constructs whats new page.</summary>
/// <param name="showMasterDetail">Action to invoke master detail page.</param>
public WhatsNewPage(Action showMasterDetail)
{
InitializeComponent();
WhatsNewViewModel = new ViewModel.WhatsNew.WhatsNewViewModel(
DependencyService.Get<IAppInfo>().Version,
App.ModelRoot.WhatsNew.WhatsNewText,
App.ModelRoot.WhatsNew.IsShowAgbRequired,
showMasterDetail,
this);
BindingContext = WhatsNewViewModel;
}
/// <summary> Displays alert message.</summary>
/// <param name="title">Title of message.</param>
/// <param name="message">Message to display.</param>
/// <param name="details">Detailed error description.</param>
/// <param name="cancel">Type of buttons.</param>
public async Task DisplayAdvancedAlert(
string title,
string message,
string details,
string cancel)
=> await App.Current.MainPage.DisplayAlert(title, $"{message}\r\nDetails:\r\n{details}", cancel);
/// <summary> Displays detailed alert message.</summary>
/// <param name="title">Title of message.</param>
/// <param name="message">Message to display.</param>
/// <param name="details">Detailed error description.</param>
/// <param name="accept">Text of accept button.</param>
/// <param name="cancel">Text of cancel button.</param>
/// <returns>True if user pressed accept.</returns>
public async Task<bool> DisplayAdvancedAlert(string title, string message, string details, string accept, string cancel)
=> await App.Current.MainPage.DisplayAlert(title, !string.IsNullOrEmpty(details) ? $"{message}\r\nDetails:\r\n{details}" : $"{message}", accept, cancel);
public Task PopModalAsync()
{
throw new NotImplementedException(); ;
}
/// <summary> Pushes a page onto the stack. </summary>
/// <param name="p_oTypeOfPage">Page to display.</param>
public Task PushAsync(ViewTypes p_oTypeOfPage)
{
throw new NotImplementedException();
}
public async Task PushModalAsync(ViewTypes p_oTypeOfPage)
{
await Navigation.PushModalAsync((Page)Activator.CreateInstance(p_oTypeOfPage.GetViewType()));
}
#if USEFLYOUT
public void ShowPage(ViewTypes p_oType, string p_strTitle = null)
=> throw new NotImplementedException();
#else
/// <summary> Shows a page.</summary>
/// <param name="route">Route of the page to show.</param>
public async Task ShowPage(string route) => await Shell.Current.GoToAsync(route);
#endif
#if USCSHARP9
public Task<IViewService.IUserFeedback> DisplayUserFeedbackPopup() => throw new NotSupportedException();
#else
public async Task<IUserFeedback> DisplayUserFeedbackPopup(IBatteryMutable battery = null) => throw new NotSupportedException();
#endif
/// <summary>
/// Invoked when pages is closed/ hidden.
/// /// </summary>
protected override void OnDisappearing()
{
base.OnDisappearing();
if (WhatsNewViewModel == null)
{
// View model might be null.
return;
}
WhatsNewViewModel?.OnDisappearing(() =>
{
App.ModelRoot.WhatsNew.WasShownInCurrentSession = true;
App.ModelRoot.Save();
});
}
}
}