version up
This commit is contained in:
@@ -1,59 +1,82 @@
|
||||
namespace Blahblah.FlowerApp;
|
||||
using Blahblah.FlowerApp.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class AppContentPage : ContentPage
|
||||
namespace Blahblah.FlowerApp;
|
||||
|
||||
public class AppContentPage : ContentPage, ILoggerContent
|
||||
{
|
||||
protected static string L(string key, string defaultValue = "")
|
||||
{
|
||||
return LocalizationResource.GetText(key, defaultValue);
|
||||
}
|
||||
public ILogger Logger { get; init; } = null!;
|
||||
|
||||
protected static Task<T?> FetchAsync<T>(string url, CancellationToken cancellation = default)
|
||||
{
|
||||
return Extensions.FetchAsync<T>(url, cancellation);
|
||||
}
|
||||
public FlowerDatabase Database { get; init; } = null!;
|
||||
|
||||
protected T GetValue<T>(BindableProperty property)
|
||||
{
|
||||
return (T)GetValue(property);
|
||||
}
|
||||
|
||||
protected Task AlertError(string error)
|
||||
bool hasLoading = true;
|
||||
ContentView? loading;
|
||||
|
||||
#if __IOS__
|
||||
private async Task DoLoading(bool flag)
|
||||
#else
|
||||
private Task DoLoading(bool flag)
|
||||
#endif
|
||||
{
|
||||
return Alert(LocalizationResource.GetText("error", "Error"), error);
|
||||
if (loading == null && hasLoading)
|
||||
{
|
||||
try
|
||||
{
|
||||
loading = (ContentView)FindByName("loading");
|
||||
}
|
||||
catch
|
||||
{
|
||||
hasLoading = false;
|
||||
}
|
||||
}
|
||||
if (loading != null)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
#if __IOS__
|
||||
loading.IsVisible = true;
|
||||
await loading.FadeTo(1, easing: Easing.CubicOut);
|
||||
#else
|
||||
loading.Opacity = 1;
|
||||
loading.IsVisible = true;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if __IOS__
|
||||
await loading.FadeTo(0, easing: Easing.CubicIn);
|
||||
loading.IsVisible = false;
|
||||
#else
|
||||
loading.IsVisible = false;
|
||||
loading.Opacity = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if __ANDROID__
|
||||
return Task.CompletedTask;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected Task Alert(string title, string message, string? cancel = null)
|
||||
protected Task Loading(bool flag)
|
||||
{
|
||||
cancel ??= LocalizationResource.GetText("ok", "Ok");
|
||||
IsBusy = flag;
|
||||
|
||||
if (MainThread.IsMainThread)
|
||||
{
|
||||
return DisplayAlert(title, message, cancel);
|
||||
return DoLoading(flag);
|
||||
}
|
||||
var taskSource = new TaskCompletionSource();
|
||||
|
||||
var source = new TaskCompletionSource();
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await DisplayAlert(title, message, cancel);
|
||||
taskSource.TrySetResult();
|
||||
await DoLoading(flag);
|
||||
source.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;
|
||||
return source.Task;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user