wabbajack/Wabbajack.App/Screens/PlaySelectViewModel.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2021-10-22 04:28:52 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Controls;
using Wabbajack.App.Models;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
namespace Wabbajack.App.Screens;
public class PlaySelectViewModel : ViewModelBase, IActivatableViewModel
{
private readonly InstallationStateManager _manager;
2021-11-08 13:32:51 +00:00
private readonly ImageCache _imageCache;
2021-10-22 04:28:52 +00:00
2021-11-08 13:32:51 +00:00
public PlaySelectViewModel(InstallationStateManager manager, ImageCache imageCache)
2021-10-22 04:28:52 +00:00
{
2021-11-08 13:32:51 +00:00
_imageCache = imageCache;
2021-10-22 04:28:52 +00:00
_manager = manager;
Activator = new ViewModelActivator();
2021-10-23 16:51:17 +00:00
2021-10-22 04:28:52 +00:00
this.WhenActivated(disposables =>
{
LoadAndSetItems().FireAndForget();
Disposable.Empty.DisposeWith(disposables);
});
}
2021-10-23 16:51:17 +00:00
[Reactive] public IEnumerable<InstalledListViewModel> Items { get; set; }
2021-10-22 04:28:52 +00:00
public async Task LoadAndSetItems()
{
var items = await _manager.GetAll();
2021-11-08 13:32:51 +00:00
Items = items.Settings.Select(a => new InstalledListViewModel(a, _imageCache)).ToArray();
2021-10-22 04:28:52 +00:00
}
}