|
@@ -1,4 +1,7 @@
|
|
|
-using Avalonia.Controls;
|
|
|
+using Avalonia;
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Controls.ApplicationLifetimes;
|
|
|
+using DynamicData.Binding;
|
|
|
using ReactiveUI;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -10,93 +13,39 @@ using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
|
+using VeloeAvaloniaKemonoPartyApp.Views;
|
|
|
|
|
|
namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
{
|
|
|
public class MainViewModel : ViewModelBase
|
|
|
{
|
|
|
- private CancellationTokenSource? _cancellationTokenSource;
|
|
|
+
|
|
|
+ private ViewModelBase _contentViewModel;
|
|
|
|
|
|
public MainViewModel()
|
|
|
{
|
|
|
- /*
|
|
|
- BuyMusicCommand = ReactiveCommand.Create(() =>
|
|
|
- {
|
|
|
- return SelectedAlbum;
|
|
|
- });*/
|
|
|
+ ActualMainViewModel = new CreatorsViewModel();
|
|
|
+ _contentViewModel = ActualMainViewModel;
|
|
|
|
|
|
- this.WhenAnyValue(x => x.SearchText)
|
|
|
- .Throttle(TimeSpan.FromMilliseconds(400))
|
|
|
- .ObserveOn(RxApp.MainThreadScheduler)
|
|
|
- .Subscribe(DoSearch!);
|
|
|
+ ActualMainViewModel.WhenAnyValue(x => x.SelectedAlbum).Subscribe(AddItem!);
|
|
|
}
|
|
|
|
|
|
- private string _searchText = string.Empty;
|
|
|
- private bool _isBusy = false;
|
|
|
+ public CreatorsViewModel ActualMainViewModel { get; }
|
|
|
|
|
|
- public string SearchText
|
|
|
+ public ViewModelBase ContentViewModel
|
|
|
{
|
|
|
- get => _searchText;
|
|
|
- set => this.RaiseAndSetIfChanged(ref _searchText, value);
|
|
|
+ get => _contentViewModel;
|
|
|
+ private set => this.RaiseAndSetIfChanged(ref _contentViewModel, value);
|
|
|
}
|
|
|
|
|
|
- public bool IsBusy
|
|
|
+ public void AddItem(CreatorViewModel creatorViewModel)
|
|
|
{
|
|
|
- get => _isBusy;
|
|
|
- set => this.RaiseAndSetIfChanged(ref _isBusy, value);
|
|
|
- }
|
|
|
-
|
|
|
- private CreatorViewModel _selectedAlbum;
|
|
|
+ if (creatorViewModel == null) return;
|
|
|
|
|
|
- public ObservableCollection<CreatorViewModel> SearchResults { get; } = new();
|
|
|
+ Debug.WriteLine("Call new view");
|
|
|
|
|
|
- public CreatorViewModel? SelectedAlbum
|
|
|
- {
|
|
|
- get => _selectedAlbum;
|
|
|
- set => this.RaiseAndSetIfChanged(ref _selectedAlbum, value);
|
|
|
+ ContentViewModel = new CreatorPostsViewModel(creatorViewModel.Creator);
|
|
|
}
|
|
|
|
|
|
- private async void DoSearch(string s)
|
|
|
- {
|
|
|
- _cancellationTokenSource?.Cancel();
|
|
|
- _cancellationTokenSource = new CancellationTokenSource();
|
|
|
- var cancellationToken = _cancellationTokenSource.Token;
|
|
|
-
|
|
|
- IsBusy = true;
|
|
|
- SearchResults.Clear();
|
|
|
-
|
|
|
- if (!string.IsNullOrWhiteSpace(s))
|
|
|
- {
|
|
|
- var creators = await Creator.SearchAsync(s);
|
|
|
-
|
|
|
- foreach (var creator in creators)
|
|
|
- {
|
|
|
- var vm = new CreatorViewModel(creator);
|
|
|
- SearchResults.Add(vm);
|
|
|
- }
|
|
|
-
|
|
|
- if (!cancellationToken.IsCancellationRequested)
|
|
|
- {
|
|
|
- LoadAvatars(cancellationToken);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- IsBusy = false;
|
|
|
- }
|
|
|
-
|
|
|
- private async void LoadAvatars(CancellationToken cancellationToken)
|
|
|
- {
|
|
|
- foreach (var creator in SearchResults.ToList())
|
|
|
- {
|
|
|
- await creator.LoadAvatar();
|
|
|
-
|
|
|
- if (cancellationToken.IsCancellationRequested)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|