Implemented search results window for AppID search
This commit is contained in:
parent
418e4fa86c
commit
99b9c52b40
@ -75,13 +75,23 @@ namespace GoldbergGUI.Core.Services
|
|||||||
{
|
{
|
||||||
var listOfAppsByName = _cache.Search(x => x.Name)
|
var listOfAppsByName = _cache.Search(x => x.Name)
|
||||||
.SetCulture(StringComparison.OrdinalIgnoreCase)
|
.SetCulture(StringComparison.OrdinalIgnoreCase)
|
||||||
.ContainingAll(name.Split(' ')).ToHashSet();
|
.ContainingAll(name.Split(' '));
|
||||||
|
return listOfAppsByName;
|
||||||
|
/*var filteredList = new HashSet<SteamApp>();
|
||||||
foreach (var steamApp in listOfAppsByName)
|
foreach (var steamApp in listOfAppsByName)
|
||||||
{
|
{
|
||||||
var sa = Task.Run(async () => await AppDetails.GetAsync(steamApp.AppId).ConfigureAwait(false)).Result;
|
try
|
||||||
if (sa.Type != AppType.Game) listOfAppsByName.Remove(steamApp);
|
{
|
||||||
|
var task = AppDetails.GetAsync(steamApp.AppId);
|
||||||
|
var details = await task.ConfigureAwait(false);
|
||||||
|
if (details?.Type != null && details.Type == AppType.Game) filteredList.Add(steamApp);
|
||||||
}
|
}
|
||||||
return listOfAppsByName;
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Debug($"{e.GetType()}: {steamApp}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredList;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public SteamApp GetAppByName(string name)
|
public SteamApp GetAppByName(string name)
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using MvvmCross.Commands;
|
using MvvmCross.Commands;
|
||||||
using MvvmCross.Logging;
|
using MvvmCross.Logging;
|
||||||
|
using MvvmCross.Navigation;
|
||||||
using MvvmCross.ViewModels;
|
using MvvmCross.ViewModels;
|
||||||
|
|
||||||
namespace GoldbergGUI.Core.ViewModels
|
namespace GoldbergGUI.Core.ViewModels
|
||||||
@ -15,6 +16,7 @@
|
|||||||
// ReSharper disable once ClassNeverInstantiated.Global
|
// ReSharper disable once ClassNeverInstantiated.Global
|
||||||
public class MainViewModel : MvxViewModel
|
public class MainViewModel : MvxViewModel
|
||||||
{
|
{
|
||||||
|
private readonly IMvxNavigationService _navigationService;
|
||||||
private string _dllPath;
|
private string _dllPath;
|
||||||
private string _gameName;
|
private string _gameName;
|
||||||
|
|
||||||
@ -34,11 +36,13 @@
|
|||||||
private bool _mainWindowEnabled;
|
private bool _mainWindowEnabled;
|
||||||
private bool _goldbergApplied;
|
private bool _goldbergApplied;
|
||||||
|
|
||||||
public MainViewModel(ISteamService steam, IGoldbergService goldberg, IMvxLog log)
|
public MainViewModel(ISteamService steam, IGoldbergService goldberg, IMvxLogProvider logProvider,
|
||||||
|
IMvxNavigationService navigationService)
|
||||||
{
|
{
|
||||||
_steam = steam;
|
_steam = steam;
|
||||||
_goldberg = goldberg;
|
_goldberg = goldberg;
|
||||||
_log = log;
|
_log = logProvider.GetLogFor(typeof(MainViewModel));
|
||||||
|
_navigationService = navigationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Prepare()
|
public override void Prepare()
|
||||||
@ -212,15 +216,16 @@
|
|||||||
await ReadConfig().ConfigureAwait(false);
|
await ReadConfig().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMvxCommand FindIdCommand => new MvxCommand(FindId);
|
public IMvxCommand FindIdCommand => new MvxAsyncCommand(FindId);
|
||||||
|
|
||||||
private void FindId()
|
private async Task FindId()
|
||||||
{
|
{
|
||||||
if (GameName.Contains("Game name..."))
|
if (GameName.Contains("Game name..."))
|
||||||
{
|
{
|
||||||
_log.Error("No game name entered!");
|
_log.Error("No game name entered!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
MainWindowEnabled = false;
|
||||||
var appByName = _steam.GetAppByName(_gameName);
|
var appByName = _steam.GetAppByName(_gameName);
|
||||||
if (appByName != null)
|
if (appByName != null)
|
||||||
{
|
{
|
||||||
@ -229,8 +234,26 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_log.Warn("Steam app could not be found!");
|
var list = _steam.GetListOfAppsByName(GameName);
|
||||||
|
var steamApps = list as SteamApp[] ?? list.ToArray();
|
||||||
|
if (steamApps.Length == 1)
|
||||||
|
{
|
||||||
|
GameName = steamApps[0].Name;
|
||||||
|
AppId = steamApps[0].AppId;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var navigateTask = _navigationService
|
||||||
|
.Navigate<SearchResultViewModel, IEnumerable<SteamApp>, SteamApp>(steamApps);
|
||||||
|
var navigateResult = await navigateTask.ConfigureAwait(false);
|
||||||
|
if (navigateResult != null)
|
||||||
|
{
|
||||||
|
GameName = navigateResult.Name;
|
||||||
|
AppId = navigateResult.AppId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MainWindowEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public IMvxCommand GetNameByIdCommand => new MvxAsyncCommand(GetNameById);
|
//public IMvxCommand GetNameByIdCommand => new MvxAsyncCommand(GetNameById);
|
||||||
|
74
GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs
Normal file
74
GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using GoldbergGUI.Core.Models;
|
||||||
|
using MvvmCross.Commands;
|
||||||
|
using MvvmCross.Logging;
|
||||||
|
using MvvmCross.Navigation;
|
||||||
|
using MvvmCross.ViewModels;
|
||||||
|
|
||||||
|
namespace GoldbergGUI.Core.ViewModels
|
||||||
|
{
|
||||||
|
public class SearchResultViewModel : MvxNavigationViewModel<IEnumerable<SteamApp>>, IMvxViewModel<IEnumerable<SteamApp>, SteamApp>
|
||||||
|
{
|
||||||
|
private readonly IMvxNavigationService _navigationService;
|
||||||
|
private readonly IMvxLog _log;
|
||||||
|
private IEnumerable<SteamApp> _apps;
|
||||||
|
|
||||||
|
public SearchResultViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService) :
|
||||||
|
base(logProvider, navigationService)
|
||||||
|
{
|
||||||
|
_log = logProvider.GetLogFor(typeof(SearchResultViewModel));
|
||||||
|
_navigationService = navigationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Prepare(IEnumerable<SteamApp> parameter)
|
||||||
|
{
|
||||||
|
Apps = parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<SteamApp> Apps
|
||||||
|
{
|
||||||
|
get => _apps;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_apps = value;
|
||||||
|
RaisePropertyChanged(() => Apps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SteamApp Selected
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMvxCommand SaveCommand => new MvxAsyncCommand(Save);
|
||||||
|
|
||||||
|
public IMvxCommand CloseCommand => new MvxAsyncCommand(Close);
|
||||||
|
|
||||||
|
public TaskCompletionSource<object> CloseCompletionSource { get; set; }
|
||||||
|
|
||||||
|
public override void ViewDestroy(bool viewFinishing = true)
|
||||||
|
{
|
||||||
|
if (viewFinishing && CloseCompletionSource != null && !CloseCompletionSource.Task.IsCompleted &&
|
||||||
|
!CloseCompletionSource.Task.IsFaulted)
|
||||||
|
CloseCompletionSource?.TrySetCanceled();
|
||||||
|
|
||||||
|
base.ViewDestroy(viewFinishing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Save()
|
||||||
|
{
|
||||||
|
if (Selected != null)
|
||||||
|
{
|
||||||
|
_log.Info($"Successfully got app {Selected}");
|
||||||
|
await _navigationService.Close(this, Selected).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Close()
|
||||||
|
{
|
||||||
|
await _navigationService.Close(this).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
GoldbergGUI.WPF/Views/SearchResultView.xaml
Normal file
33
GoldbergGUI.WPF/Views/SearchResultView.xaml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<views:MvxWindow x:Class="GoldbergGUI.WPF.Views.SearchResultView"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"
|
||||||
|
xmlns:viewModels="clr-namespace:GoldbergGUI.Core.ViewModels;assembly=GoldbergGUI.Core"
|
||||||
|
d:DataContext="{d:DesignInstance Type=viewModels:SearchResultViewModel}"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Auto-CreamAPI 2: Search Results" Width="420" Height="540" MinWidth="420" MinHeight="540">
|
||||||
|
<Grid Margin="10,10,10,10">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Content="Select a game..." HorizontalAlignment="Left" Margin="0,0,0,10" VerticalAlignment="Top" />
|
||||||
|
<DataGrid Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single"
|
||||||
|
ItemsSource="{Binding Apps}" SelectedItem="{Binding Selected}">
|
||||||
|
<DataGrid.InputBindings>
|
||||||
|
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding SaveCommand}" />
|
||||||
|
</DataGrid.InputBindings>
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="AppID" Binding="{Binding AppId}" />
|
||||||
|
<DataGridTextColumn Header="Game Name" Binding="{Binding Name}" />
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
<Button Content="OK" Command="{Binding SaveCommand}" HorizontalAlignment="Right" Margin="0,10,70,0"
|
||||||
|
Grid.Row="2" VerticalAlignment="Top" Width="60" />
|
||||||
|
<Button Content="Cancel" Command="{Binding CloseCommand}" HorizontalAlignment="Right" Margin="0,10,0,0"
|
||||||
|
Grid.Row="2" VerticalAlignment="Top" Width="60" />
|
||||||
|
</Grid>
|
||||||
|
</views:MvxWindow>
|
14
GoldbergGUI.WPF/Views/SearchResultView.xaml.cs
Normal file
14
GoldbergGUI.WPF/Views/SearchResultView.xaml.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using MvvmCross.Platforms.Wpf.Presenters.Attributes;
|
||||||
|
using MvvmCross.Platforms.Wpf.Views;
|
||||||
|
|
||||||
|
namespace GoldbergGUI.WPF.Views
|
||||||
|
{
|
||||||
|
[MvxWindowPresentation(Identifier = nameof(SearchResultView), Modal = false)]
|
||||||
|
public partial class SearchResultView
|
||||||
|
{
|
||||||
|
public SearchResultView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user