83 lines
1.8 KiB
C#
83 lines
1.8 KiB
C#
using Blahblah.FlowerApp.Data;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Blahblah.FlowerApp;
|
|
|
|
public class AppContentPage : ContentPage, ILoggerContent
|
|
{
|
|
public ILogger Logger { get; init; } = null!;
|
|
|
|
public FlowerDatabase Database { get; init; } = null!;
|
|
|
|
protected T GetValue<T>(BindableProperty property)
|
|
{
|
|
return (T)GetValue(property);
|
|
}
|
|
|
|
bool hasLoading = true;
|
|
ContentView? loading;
|
|
|
|
#if __IOS__
|
|
private async Task DoLoading(bool flag)
|
|
#else
|
|
private Task DoLoading(bool flag)
|
|
#endif
|
|
{
|
|
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 Loading(bool flag)
|
|
{
|
|
IsBusy = flag;
|
|
|
|
if (MainThread.IsMainThread)
|
|
{
|
|
return DoLoading(flag);
|
|
}
|
|
|
|
var source = new TaskCompletionSource();
|
|
MainThread.BeginInvokeOnMainThread(async () =>
|
|
{
|
|
await DoLoading(flag);
|
|
source.TrySetResult();
|
|
});
|
|
return source.Task;
|
|
}
|
|
}
|