2020-12-28 09:27:37 -05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using auto_creamapi.Models;
|
|
|
|
using auto_creamapi.Utils;
|
2023-12-23 16:55:26 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-12-28 09:27:37 -05:00
|
|
|
using MvvmCross.Commands;
|
|
|
|
using MvvmCross.Logging;
|
|
|
|
using MvvmCross.Navigation;
|
|
|
|
using MvvmCross.ViewModels;
|
|
|
|
|
|
|
|
namespace auto_creamapi.ViewModels
|
|
|
|
{
|
|
|
|
public class SearchResultViewModel : MvxNavigationViewModel<IEnumerable<SteamApp>>,
|
|
|
|
IMvxViewModel<IEnumerable<SteamApp>, SteamApp>
|
|
|
|
{
|
|
|
|
private readonly IMvxNavigationService _navigationService;
|
2023-12-23 16:55:26 -05:00
|
|
|
private readonly ILogger<SearchResultViewModel> _logger;
|
2020-12-28 09:27:37 -05:00
|
|
|
private IEnumerable<SteamApp> _steamApps;
|
|
|
|
|
|
|
|
/*public override async Task Initialize()
|
|
|
|
{
|
|
|
|
await base.Initialize();
|
|
|
|
}*/
|
2023-12-23 16:55:26 -05:00
|
|
|
public SearchResultViewModel(ILoggerFactory loggerFactory, IMvxNavigationService navigationService) : base(
|
|
|
|
loggerFactory, navigationService)
|
2020-12-28 09:27:37 -05:00
|
|
|
{
|
|
|
|
_navigationService = navigationService;
|
2023-12-23 16:55:26 -05:00
|
|
|
_logger = loggerFactory.CreateLogger<SearchResultViewModel>();
|
2020-12-28 09:27:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<SteamApp> Apps
|
|
|
|
{
|
|
|
|
get => _steamApps;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_steamApps = value;
|
|
|
|
RaisePropertyChanged(() => Apps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public SteamApp Selected
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
//RaisePropertyChanged(Selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IMvxCommand SaveCommand => new MvxAsyncCommand(Save);
|
|
|
|
|
|
|
|
public IMvxCommand CloseCommand => new MvxCommand(Close);
|
|
|
|
|
|
|
|
public override void Prepare(IEnumerable<SteamApp> parameter)
|
|
|
|
{
|
|
|
|
Apps = parameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TaskCompletionSource<object> CloseCompletionSource { get; set; }
|
|
|
|
|
|
|
|
public override void ViewDestroy(bool viewFinishing = true)
|
|
|
|
{
|
2023-12-23 16:55:26 -05:00
|
|
|
if (viewFinishing && CloseCompletionSource?.Task.IsCompleted == false &&
|
2020-12-28 09:27:37 -05:00
|
|
|
!CloseCompletionSource.Task.IsFaulted)
|
2023-12-23 16:55:26 -05:00
|
|
|
{
|
2020-12-28 09:27:37 -05:00
|
|
|
CloseCompletionSource?.TrySetCanceled();
|
2023-12-23 16:55:26 -05:00
|
|
|
}
|
2020-12-28 09:27:37 -05:00
|
|
|
|
|
|
|
base.ViewDestroy(viewFinishing);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task Save()
|
|
|
|
{
|
|
|
|
if (Selected != null)
|
|
|
|
{
|
2023-12-23 16:55:26 -05:00
|
|
|
_logger.LogInformation("Successfully got app {Selected}", Selected);
|
2021-01-13 07:04:35 -05:00
|
|
|
await _navigationService.Close(this, Selected).ConfigureAwait(false);
|
2020-12-28 09:27:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Close()
|
|
|
|
{
|
|
|
|
//throw new System.NotImplementedException();
|
|
|
|
_navigationService.Close(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|