Skip to content

Commit

Permalink
Fixed count in professional mode, now only shows count of downloadabl…
Browse files Browse the repository at this point in the history
…e media.

fixed poster picker not opening for IDPicked media, when media is not game, but search mode was game.
  • Loading branch information
DineshSolanki committed Aug 6, 2021
1 parent bc9cc88 commit 7ce21b1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 25 deletions.
2 changes: 1 addition & 1 deletion FoliCon/Modules/IGDBClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<ResultResponse> SearchGameByIdAsync(string id)
{
Contract.Assert(_serviceClient != null);
var r = await _serviceClient.QueryAsync<Game>(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,
Expand Down
7 changes: 5 additions & 2 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -114,6 +115,8 @@ private async Task Search(string query, int offset = 0)
{
return;
}

Index++;
}
if (searchResult.HasMore)
{
Expand Down
128 changes: 106 additions & 22 deletions FoliCon/ViewModels/SearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> 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

Expand All @@ -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)
Expand Down Expand Up @@ -135,23 +192,29 @@ 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];
}
else
{
IsSearchFocused = true;
}

FileList = Util.GetFileNamesFromFolder(_fullFolderPath);
}

Expand All @@ -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)
Expand All @@ -190,6 +267,7 @@ private void PickMethod()
MessageBox.Show(CustomMessageBox.Warning(LangProvider.GetLang("NoPosterFound"), SearchTitle));
}
}

CloseDialog("true");
}

Expand All @@ -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)
Expand Down

0 comments on commit 7ce21b1

Please sign in to comment.