home page for App
This commit is contained in:
59
FlowerApp/Controls/AppContentPage.cs
Normal file
59
FlowerApp/Controls/AppContentPage.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace Blahblah.FlowerApp;
|
||||
|
||||
public class AppContentPage : ContentPage
|
||||
{
|
||||
protected static string L(string key, string defaultValue = "")
|
||||
{
|
||||
return LocalizationResource.GetText(key, defaultValue);
|
||||
}
|
||||
|
||||
protected static Task<T?> FetchAsync<T>(string url, CancellationToken cancellation = default)
|
||||
{
|
||||
return Extensions.FetchAsync<T>(url, cancellation);
|
||||
}
|
||||
|
||||
protected T GetValue<T>(BindableProperty property)
|
||||
{
|
||||
return (T)GetValue(property);
|
||||
}
|
||||
|
||||
protected Task AlertError(string error)
|
||||
{
|
||||
return Alert(LocalizationResource.GetText("error", "Error"), error);
|
||||
}
|
||||
|
||||
protected Task Alert(string title, string message, string? cancel = null)
|
||||
{
|
||||
cancel ??= LocalizationResource.GetText("ok", "Ok");
|
||||
|
||||
if (MainThread.IsMainThread)
|
||||
{
|
||||
return DisplayAlert(title, message, cancel);
|
||||
}
|
||||
var taskSource = new TaskCompletionSource();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await DisplayAlert(title, message, cancel);
|
||||
taskSource.TrySetResult();
|
||||
});
|
||||
return taskSource.Task;
|
||||
}
|
||||
|
||||
protected Task<bool> Confirm(string title, string question, string? accept = null, string? cancel = null)
|
||||
{
|
||||
accept ??= LocalizationResource.GetText("yes", "Yes");
|
||||
cancel ??= LocalizationResource.GetText("no", "No");
|
||||
|
||||
if (MainThread.IsMainThread)
|
||||
{
|
||||
return DisplayAlert(title, question, accept, cancel);
|
||||
}
|
||||
var taskSource = new TaskCompletionSource<bool>();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
var result = await DisplayAlert(title, question, accept, cancel);
|
||||
taskSource.TrySetResult(result);
|
||||
});
|
||||
return taskSource.Task;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user