sharee.bike-App/LastenradBayern/ShareeBike/View/WhatsNew/WhatsNewPage.xaml.cs
2024-04-09 12:53:23 +02:00

101 lines
3.4 KiB
C#

using System;
using System.Threading.Tasks;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using ShareeBike.Model.Device;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace ShareeBike.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()));
}
/// <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);
#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();
});
}
}
}