|
@@ -1,16 +1,13 @@
|
|
|
-using Avalonia.Controls.ApplicationLifetimes;
|
|
|
-using Avalonia.Input;
|
|
|
-using Avalonia.Interactivity;
|
|
|
+using Avalonia.Input;
|
|
|
+using Avalonia.Notification;
|
|
|
using Avalonia.Threading;
|
|
|
using DynamicData.Binding;
|
|
|
using HanumanInstitute.MvvmDialogs;
|
|
|
using ReactiveUI;
|
|
|
using System;
|
|
|
-using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Reactive.Linq;
|
|
|
-using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
@@ -39,10 +36,29 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
this.WhenPropertyChanged(x => x.SelectedAlbum).Subscribe(async x =>
|
|
|
{
|
|
|
if (x.Value is null) return;
|
|
|
- var vm = _dialogService.CreateViewModel<CreatorPostsViewModel>();
|
|
|
- vm.Creator = x.Value.Creator;
|
|
|
- Dispatcher.UIThread.Post(() => { SelectedAlbum = null; });
|
|
|
- await _dialogService.ShowDialogAsync(this, vm);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var vm = _dialogService.CreateViewModel<CreatorPostsViewModel>();
|
|
|
+ vm.Creator = x.Value.Creator;
|
|
|
+
|
|
|
+ await _dialogService.ShowDialogAsync(this, vm);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Manager
|
|
|
+ .CreateMessage()
|
|
|
+ .Accent("#1751C3")
|
|
|
+ .Animates(true)
|
|
|
+ .Background("#333")
|
|
|
+ .HasBadge("Error")
|
|
|
+ .HasMessage(ex.Message)
|
|
|
+ .Dismiss().WithDelay(TimeSpan.FromSeconds(5))
|
|
|
+ .Queue();
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ Dispatcher.UIThread.Post(() => { SelectedAlbum = null; });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -61,6 +77,8 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
set => this.RaiseAndSetIfChanged(ref _isBusy, value);
|
|
|
}
|
|
|
|
|
|
+ public INotificationMessageManager Manager { get; } = new NotificationMessageManager();
|
|
|
+
|
|
|
private CreatorViewModel _selectedAlbum;
|
|
|
|
|
|
public ObservableCollection<CreatorViewModel> SearchResults { get; } = new();
|
|
@@ -82,26 +100,41 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(s))
|
|
|
{
|
|
|
- var creators = await Creator.SearchAsync(s,false);
|
|
|
-
|
|
|
- foreach (var creator in creators)
|
|
|
+ try
|
|
|
{
|
|
|
- var vm = new CreatorViewModel(creator);
|
|
|
- SearchResults.Add(vm);
|
|
|
+ var creators = await Creator.SearchAsync(s, false);
|
|
|
+
|
|
|
+ foreach (var creator in creators)
|
|
|
+ {
|
|
|
+ var vm = new CreatorViewModel(creator);
|
|
|
+ SearchResults.Add(vm);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cancellationToken.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ LoadAvatars(cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (!cancellationToken.IsCancellationRequested)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- LoadAvatars(cancellationToken);
|
|
|
+ Manager
|
|
|
+ .CreateMessage()
|
|
|
+ .Accent("#1751C3")
|
|
|
+ .Animates(true)
|
|
|
+ .Background("#333")
|
|
|
+ .HasBadge("Error")
|
|
|
+ .HasMessage(ex.Message)
|
|
|
+ .Dismiss().WithDelay(TimeSpan.FromSeconds(5))
|
|
|
+ .Queue();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
IsBusy = false;
|
|
|
}
|
|
|
|
|
|
- public async Task ReloadCreatorsSource(object? sender, PullGestureEventArgs e)
|
|
|
+ public async Task ReloadCreatorsSource(object? sender, PullGestureEndedEventArgs e)
|
|
|
{
|
|
|
- if (IsBusy) return;
|
|
|
+ if (IsBusy || e.PullDirection != PullDirection.TopToBottom) return;
|
|
|
|
|
|
_cancellationTokenSource?.Cancel();
|
|
|
_cancellationTokenSource = new CancellationTokenSource();
|
|
@@ -112,17 +145,32 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(SearchText))
|
|
|
{
|
|
|
- var creators = await Creator.SearchAsync(SearchText,true);
|
|
|
-
|
|
|
- foreach (var creator in creators)
|
|
|
+ try
|
|
|
{
|
|
|
- var vm = new CreatorViewModel(creator);
|
|
|
- SearchResults.Add(vm);
|
|
|
+ var creators = await Creator.SearchAsync(SearchText, true);
|
|
|
+
|
|
|
+ foreach (var creator in creators)
|
|
|
+ {
|
|
|
+ var vm = new CreatorViewModel(creator);
|
|
|
+ SearchResults.Add(vm);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cancellationToken.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ LoadAvatars(cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (!cancellationToken.IsCancellationRequested)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- LoadAvatars(cancellationToken);
|
|
|
+ Manager
|
|
|
+ .CreateMessage()
|
|
|
+ .Accent("#1751C3")
|
|
|
+ .Animates(true)
|
|
|
+ .Background("#333")
|
|
|
+ .HasBadge("Error")
|
|
|
+ .HasMessage(ex.Message)
|
|
|
+ .Dismiss().WithDelay(TimeSpan.FromSeconds(5))
|
|
|
+ .Queue();
|
|
|
}
|
|
|
}
|
|
|
|