diff --git a/FoliCon/Modules/IGDBClass.cs b/FoliCon/Modules/IGDBClass.cs index 7c4a1785..0bf4443c 100644 --- a/FoliCon/Modules/IGDBClass.cs +++ b/FoliCon/Modules/IGDBClass.cs @@ -54,7 +54,7 @@ public async Task SearchGameByIdAsync(string id) { Contract.Assert(_serviceClient != null); var r = await _serviceClient.QueryAsync(IGDBClient.Endpoints.Games, - $"fields name,first_release_date,total_rating,summary,cover.*; where id = {id}"); + $"fields name,first_release_date,total_rating,summary,cover.*; where id = {id};"); var response = new ResultResponse { MediaType = MediaTypes.Game, diff --git a/FoliCon/ViewModels/ProSearchResultViewModel.cs b/FoliCon/ViewModels/ProSearchResultViewModel.cs index 5557ee28..cb884238 100644 --- a/FoliCon/ViewModels/ProSearchResultViewModel.cs +++ b/FoliCon/ViewModels/ProSearchResultViewModel.cs @@ -10,6 +10,7 @@ using System.Collections.ObjectModel; using System.Data; using System.Globalization; +using System.Linq; using System.Threading.Tasks; using FoliCon.Properties.Langs; @@ -99,10 +100,10 @@ private async Task Search(string query, int offset = 0) var lastIndex = Index; if (searchResult.Results?.Length > 0) { - TotalPosters = searchResult.Results.Length + offset; + TotalPosters = searchResult.Results.Count( result => result.IsDownloadable) + offset; foreach (var item in searchResult.Results.GetEnumeratorWithIndex()) { - Index = item.Index + lastIndex; + Index += lastIndex; if (!item.Value.IsDownloadable) continue; using (var bm = await Util.GetBitmapFromUrlAsync(item.Value.Thumbs[0].Src)) @@ -114,6 +115,8 @@ private async Task Search(string query, int offset = 0) { return; } + + Index++; } if (searchResult.HasMore) { diff --git a/FoliCon/ViewModels/SearchResultViewModel.cs b/FoliCon/ViewModels/SearchResultViewModel.cs index 76de1c98..ff510372 100644 --- a/FoliCon/ViewModels/SearchResultViewModel.cs +++ b/FoliCon/ViewModels/SearchResultViewModel.cs @@ -35,22 +35,76 @@ public class SearchResultViewModel : BindableBase, IDialogAware private Tmdb _tmdbObject; private IgdbClass _igdbObject; private string customRating; + #endregion Variables #region Properties - public string Title { get => _title; set => SetProperty(ref _title, value); } - public string SearchTitle { get => _searchTitle; set => SetProperty(ref _searchTitle, value); } - public string BusyContent { get => _busyContent; set => SetProperty(ref _busyContent, value); } - public bool IsBusy { get => _isBusy; set => SetProperty(ref _isBusy, value); } - public string CustomRating { get => customRating; set => SetProperty(ref customRating, value); } - public ListViewData ResultListViewData { get => _resultListViewData; set => SetProperty(ref _resultListViewData, value); } + public string Title + { + get => _title; + set => SetProperty(ref _title, value); + } + + public string SearchTitle + { + get => _searchTitle; + set => SetProperty(ref _searchTitle, value); + } - public string SearchAgainTitle { get => _searchAgainTitle; set => SetProperty(ref _searchAgainTitle, value); } - public List FileList { get => _fileList; set => SetProperty(ref _fileList, value); } - public ResultResponse SearchResult { get => _searchResult; set => SetProperty(ref _searchResult, value); } - public string SearchMode { get => _searchMode; set => SetProperty(ref _searchMode, value); } - public bool IsSearchFocused { get => _isSearchFocused; set => SetProperty(ref _isSearchFocused, value); } + public string BusyContent + { + get => _busyContent; + set => SetProperty(ref _busyContent, value); + } + + public bool IsBusy + { + get => _isBusy; + set => SetProperty(ref _isBusy, value); + } + + public string CustomRating + { + get => customRating; + set => SetProperty(ref customRating, value); + } + + public ListViewData ResultListViewData + { + get => _resultListViewData; + set => SetProperty(ref _resultListViewData, value); + } + + public string SearchAgainTitle + { + get => _searchAgainTitle; + set => SetProperty(ref _searchAgainTitle, value); + } + + public List FileList + { + get => _fileList; + set => SetProperty(ref _fileList, value); + } + + public ResultResponse SearchResult + { + get => _searchResult; + set => SetProperty(ref _searchResult, value); + } + + public string SearchMode + { + get => _searchMode; + set => SetProperty(ref _searchMode, value); + } + + public bool IsSearchFocused + { + get => _isSearchFocused; + set => SetProperty(ref _isSearchFocused, value); + } #endregion Properties @@ -72,12 +126,15 @@ public SearchResultViewModel(IDialogService dialogService) ResultListViewData = new ListViewData { Data = null, SelectedItem = null }; PickCommand = new DelegateCommand(PickMethod); SortResultCommand = new DelegateCommand(SortResult); - SkipAllCommand = new DelegateCommand(delegate { GlobalVariables.SkipAll = true; CloseDialog("false"); }); + SkipAllCommand = new DelegateCommand(delegate + { + GlobalVariables.SkipAll = true; + CloseDialog("false"); + }); } private void SortResult() { - } protected virtual void CloseDialog(string parameter) @@ -135,16 +192,21 @@ private async void StartSearch(bool useBusy) { IsBusy = false; } + LoadData(titleToSearch); } private void LoadData(string searchTitle) { if (SearchResult != null - && (_isPickedById ? SearchResult.Result != null ? 1 : null : SearchMode == "Game" ? SearchResult.Result.Length : SearchResult.Result.TotalResults) != null - && (_isPickedById ? SearchResult.Result != null ? 1 : 0 : SearchMode == "Game" ? SearchResult?.Result?.Length : SearchResult?.Result?.TotalResults) != 0) + && (_isPickedById ? SearchResult.Result != null ? 1 : + null : + SearchMode == "Game" ? SearchResult.Result.Length : SearchResult.Result.TotalResults) != null + && (_isPickedById ? SearchResult.Result != null ? 1 : + 0 : + SearchMode == "Game" ? SearchResult?.Result?.Length : SearchResult?.Result?.TotalResults) != 0) { - ResultListViewData.Data = Util.FetchAndAddDetailsToListView(SearchResult, searchTitle,_isPickedById); + ResultListViewData.Data = Util.FetchAndAddDetailsToListView(SearchResult, searchTitle, _isPickedById); if (ResultListViewData.Data.Count != 0) ResultListViewData.SelectedItem = ResultListViewData.Data[0]; } @@ -152,6 +214,7 @@ private void LoadData(string searchTitle) { IsSearchFocused = true; } + FileList = Util.GetFileNamesFromFolder(_fullFolderPath); } @@ -167,20 +230,34 @@ private void PickMethod() { if (ResultListViewData.SelectedItem == null) return; var pickedIndex = ResultListViewData.Data.IndexOf(ResultListViewData.SelectedItem); - var rating=""; + var rating = ""; if (CustomRating is not null && customRating != "_._") { rating = CustomRating.Replace('_', '0'); } + try { - if (SearchMode == MediaTypes.Game) + if (_isPickedById) { - _igdbObject.ResultPicked(SearchResult.Result[pickedIndex], _fullFolderPath,rating); + if (SearchResult.MediaType == MediaTypes.Game) + { + _igdbObject.ResultPicked(SearchResult.Result[pickedIndex], _fullFolderPath, rating); + } + else + { + _tmdbObject.ResultPicked(SearchResult.Result.Results[pickedIndex], SearchResult.MediaType, + _fullFolderPath, rating); + } + } + else if (SearchMode == MediaTypes.Game) + { + _igdbObject.ResultPicked(SearchResult.Result[pickedIndex], _fullFolderPath, rating); } else { - _tmdbObject.ResultPicked(SearchResult.Result.Results[pickedIndex], SearchResult.MediaType, _fullFolderPath, rating); + _tmdbObject.ResultPicked(SearchResult.Result.Results[pickedIndex], SearchResult.MediaType, + _fullFolderPath, rating); } } catch (Exception ex) @@ -190,6 +267,7 @@ private void PickMethod() MessageBox.Show(CustomMessageBox.Warning(LangProvider.GetLang("NoPosterFound"), SearchTitle)); } } + CloseDialog("true"); } @@ -203,9 +281,15 @@ private void MouseDoubleClick() var pickedIndex = ResultListViewData.Data.IndexOf(ResultListViewData.SelectedItem); try { - if (SearchMode != MediaTypes.Game) + if (_isPickedById) + { + _dialogService.ShowPosterPicker(_tmdbObject, SearchResult, pickedIndex, ResultListViewData.Data, + _isPickedById, r => { }); + } + else if (SearchMode != MediaTypes.Game) { - _dialogService.ShowPosterPicker(_tmdbObject, SearchResult, pickedIndex, ResultListViewData.Data,_isPickedById, r => { }); + _dialogService.ShowPosterPicker(_tmdbObject, SearchResult, pickedIndex, ResultListViewData.Data, + _isPickedById, r => { }); } } catch (Exception ex)