private void SendSearchResultsToFacade(IEnumerable<TraktSearchResult> searchResults)
{
// clear facade
GUIControl.ClearControl(GetID, Facade.GetID);
if (searchResults == null || searchResults.Count() == 0)
{
GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
return;
}
// jump directly to results
if (!TraktSettings.ShowSearchResultsBreakdown && SearchTypes.Count == 1)
{
// set the selected search type as we have not clicked on a facade item
SelectedSearchType = (SearchType)GetSearchTypesID();
SendSearchResultsToWindow(SearchResults);
// clear the search term so when we return (press back) we don't go in a loop.
SearchTerm = null;
return;
}
int itemId = 0;
// Add each search type to the list
foreach (var type in SearchTypes)
{
GUIListItem item = new GUIListItem(GetSearchListName(type));
item.Label2 = GetSearchResultCount(searchResults, type).ToString();
item.ItemId = Int32.MaxValue - itemId;
item.TVTag = type;
item.IconImage = "defaultFolder.png";
item.IconImageBig = "defaultFolderBig.png";
item.ThumbnailImage = "defaultFolderBig.png";
item.OnItemSelected += OnItemSelected;
Utils.SetDefaultIcons(item);
Facade.Add(item);
itemId++;
}
// Set Facade Layout
Facade.SetCurrentLayout("List");
GUIControl.FocusControl(GetID, Facade.GetID);
if (PreviousSelectedIndex >= SearchTypes.Count)
Facade.SelectIndex(PreviousSelectedIndex - 1);
else
Facade.SelectIndex(PreviousSelectedIndex);
// set facade properties
GUIUtils.SetProperty("#itemcount", SearchTypes.Count().ToString());
GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", SearchTypes.Count.ToString(), Translation.SearchTypes));
}