private void SendBoxOfficeToFacade(IEnumerable<TraktMovieBoxOffice> boxOffice)
{
// clear facade
GUIControl.ClearControl(GetID, Facade.GetID);
if (boxOffice == null)
{
GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
GUIWindowManager.ShowPreviousWindow();
return;
}
if (boxOffice.Count() == 0)
{
GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoBoxOffice);
GUIWindowManager.ShowPreviousWindow();
return;
}
int itemId = 0;
var movieImages = new List<GUITmdbImage>();
// Add each movie
foreach (var box in boxOffice.Where(b => !string.IsNullOrEmpty(b.Movie.Title)))
{
var item = new GUIMovieListItem(box.Movie.Title, (int)TraktGUIWindows.BoxOffice);
// add image for download
var image = new GUITmdbImage { MovieImages = new TmdbMovieImages { Id = box.Movie.Ids.Tmdb } };
movieImages.Add(image);
item.Label2 = box.Movie.Year == null ? "----" : box.Movie.Year.ToString();
item.TVTag = box;
item.Movie = box.Movie;
item.Images = image;
item.IsPlayed = box.Movie.IsWatched();
item.ItemId = Int32.MaxValue - itemId;
// movie in collection doesnt nessararily mean
// that the movie is locally available on this computer
// as 'keep library clean' might not be enabled
//item.IsRemote = !movie.InCollection;
item.IconImage = GUIImageHandler.GetDefaultPoster(false);
item.IconImageBig = GUIImageHandler.GetDefaultPoster();
item.ThumbnailImage = GUIImageHandler.GetDefaultPoster();
item.OnItemSelected += OnMovieSelected;
Utils.SetDefaultIcons(item);
Facade.Add(item);
itemId++;
}
// Set Facade Layout
Facade.SetCurrentLayout(Enum.GetName(typeof(Layout), CurrentLayout));
GUIControl.FocusControl(GetID, Facade.GetID);
Facade.SelectIndex(PreviousSelectedIndex);
// set facade properties
GUIUtils.SetProperty("#itemcount", boxOffice.Count().ToString());
GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", boxOffice.Count().ToString(), boxOffice.Count() > 1 ? Translation.Movies : Translation.Movie));
int totalRevenue = boxOffice.Sum(b => b.Revenue);
GUIUtils.SetProperty("#Trakt.BoxOffice.Total.Revenue", string.Format("{0:C0}", totalRevenue));
GUIUtils.SetProperty("#Trakt.BoxOffice.Total.Revenue.Raw", totalRevenue.ToString());
// Download movie images Async and set to facade
GUIMovieListItem.GetImages(movieImages);
}