sharee.bike-App/LastenradBayern/TINK/View/WhatsNew/WhatsNewPage.xaml.cs

102 lines
3.3 KiB
C#
Raw Normal View History

2023-08-31 12:31:38 +02:00
using System;
2021-11-07 19:42:59 +01:00
using System.Threading.Tasks;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
2021-11-07 19:42:59 +01:00
using TINK.Model.Device;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace TINK.View.WhatsNew
{
2022-09-06 16:08:19 +02:00
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class WhatsNewPage : ContentPage, IViewService
{
/// <summary> Holds a reference on the view model. </summary>
private ViewModel.WhatsNew.WhatsNewViewModel WhatsNewViewModel;
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary> Constructs whats new page.</summary>
/// <param name="showMasterDetail">Action to invoke master detail page.</param>
public WhatsNewPage(Action showMasterDetail)
{
InitializeComponent();
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
WhatsNewViewModel = new ViewModel.WhatsNew.WhatsNewViewModel(
DependencyService.Get<IAppInfo>().Version,
App.ModelRoot.WhatsNew.WhatsNewText,
App.ModelRoot.WhatsNew.IsShowAgbRequired,
showMasterDetail,
this);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
BindingContext = WhatsNewViewModel;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <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);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <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);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public Task PopModalAsync()
{
throw new NotImplementedException(); ;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <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();
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
public async Task PushModalAsync(ViewTypes p_oTypeOfPage)
{
await Navigation.PushModalAsync((Page)Activator.CreateInstance(p_oTypeOfPage.GetViewType()));
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <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);
2021-11-07 19:42:59 +01:00
#if USCSHARP9
public Task<IViewService.IUserFeedback> DisplayUserFeedbackPopup() => throw new NotSupportedException();
#else
2023-09-22 11:38:42 +02:00
public async Task<IUserFeedback> DisplayUserFeedbackPopup(IBatteryMutable battery = null) => throw new NotSupportedException();
2021-11-07 19:42:59 +01:00
#endif
2022-09-06 16:08:19 +02:00
/// <summary>
/// Invoked when pages is closed/ hidden.
/// /// </summary>
protected override void OnDisappearing()
{
base.OnDisappearing();
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
if (WhatsNewViewModel == null)
{
// View model might be null.
return;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
WhatsNewViewModel?.OnDisappearing(() =>
{
App.ModelRoot.WhatsNew.WasShownInCurrentSession = true;
App.ModelRoot.Save();
});
}
}
2023-08-31 12:31:38 +02:00
}