private void SendRecentCommentsToFacade(IEnumerable<TraktCommentItem> comments)
{
// clear facade
GUIControl.ClearControl(GetID, Facade.GetID);
// protected profiles might also return null
if (comments == null || comments.Count() == 0)
{
GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.UserHasNoRecentShouts);
PreviousUser = CurrentUser;
CurrentUser = TraktSettings.Username;
GUIWindowManager.ShowPreviousWindow();
return;
}
int itemId = 0;
var commentImages = new List<GUITmdbImage>();
// Add each item added
foreach (var comment in comments)
{
// bad api data - at least one must not be null
if (comment.Movie == null && comment.Show == null && comment.List == null)
continue;
// add image for download
var images = GetTmdbImage(comment);
commentImages.Add(images);
var item = new GUICustomListItem(GetCommentItemTitle(comment), (int)TraktGUIWindows.RecentShouts);
// add user shout date as second label
item.Label2 = comment.Comment.CreatedAt.ToPrettyDateTime();
item.TVTag = comment;
item.Episode = comment.Episode;
item.Show = comment.Show;
item.Movie = comment.Movie;
item.Season = comment.Season;
item.List = comment.List;
item.Images = images;
item.ItemId = Int32.MaxValue - itemId;
item.IconImage = GUIImageHandler.GetDefaultPoster(false);
item.IconImageBig = GUIImageHandler.GetDefaultPoster();
item.ThumbnailImage = GUIImageHandler.GetDefaultPoster();
item.PinImage = "traktActivityShout.png";
item.OnItemSelected += OnCommentSelected;
Utils.SetDefaultIcons(item);
Facade.Add(item);
itemId++;
}
// set Facade Layout
Facade.SetCurrentLayout("List");
GUIControl.FocusControl(GetID, Facade.GetID);
if (PreviousSelectedIndex >= comments.Count())
Facade.SelectIndex(PreviousSelectedIndex - 1);
else
Facade.SelectIndex(PreviousSelectedIndex);
// set facade properties
GUIUtils.SetProperty("#itemcount", comments.Count().ToString());
GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", comments.Count().ToString(), comments.Count() > 1 ? Translation.Comment : Translation.Comments));
// Download images Async and set to facade
GUICustomListItem.GetImages(commentImages);
}