private bool SetVideosToFacade(List<VideoInfo> videos, VideosMode mode, bool append = false) { // Check for received data if (videos == null || videos.Count == 0) { GUIDialogNotify dlg_error = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlg_error != null) { dlg_error.Reset(); dlg_error.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlg_error.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg_error.SetText(Translation.Instance.NoVideoFound); dlg_error.DoModal(GUIWindowManager.ActiveWindow); } return false; } int indextoSelect = -1; if (append) { currentFilter.Clear(); indextoSelect = currentVideoList.Count + 1; currentVideoList.AddRange(videos); } else { currentVideoList = videos; } GUIControl.ClearControl(GetID, GUI_facadeView.GetID); currentFacadeItems.Clear(); // add the first item that will go to the previous menu OnlineVideosGuiListItem backItem = new OnlineVideosGuiListItem(".."); backItem.ItemId = 0; backItem.IsFolder = true; backItem.OnItemSelected += OnItemSelected; MediaPortal.Util.Utils.SetDefaultIcons(backItem); GUI_facadeView.Add(backItem); currentFacadeItems.Add(backItem); // add the items Dictionary<string, bool> imageHash = new Dictionary<string, bool>(); currentFilter.StartMatching(); foreach (VideoInfo videoInfo in currentVideoList) { videoInfo.CleanDescriptionAndTitle(); if (!currentFilter.Matches(videoInfo.Title) || FilterOut(videoInfo.Title) || FilterOut(videoInfo.Description)) continue; if (!string.IsNullOrEmpty(videosVKfilter) && !videoInfo.Title.ToLower().Contains(videosVKfilter.ToLower())) continue; OnlineVideosGuiListItem listItem = new OnlineVideosGuiListItem(videoInfo); listItem.ItemId = GUI_facadeView.Count; listItem.OnItemSelected += OnItemSelected; GUI_facadeView.Add(listItem); currentFacadeItems.Add(listItem); if (listItem.Item == selectedVideo) GUI_facadeView.SelectedListItemIndex = GUI_facadeView.Count - 1; if (!string.IsNullOrEmpty(videoInfo.Thumb)) imageHash[videoInfo.Thumb] = true; } // fall back to list view if there are no items with thumbs or more than one item and all have the same thumb suggestedView = null; if ((GUI_facadeView.Count > 1 && imageHash.Count == 0) || (GUI_facadeView.Count > 2 && imageHash.Count == 1)) suggestedView = GUIFacadeControl.Layout.List; if (SelectedSite.HasNextPage) { OnlineVideosGuiListItem nextPageItem = new OnlineVideosGuiListItem(Translation.Instance.NextPage); nextPageItem.ItemId = GUI_facadeView.Count; nextPageItem.IsFolder = true; nextPageItem.IconImage = "OnlineVideos\\NextPage.png"; nextPageItem.IconImageBig = "OnlineVideos\\NextPage.png"; nextPageItem.ThumbnailImage = "OnlineVideos\\NextPage.png"; nextPageItem.OnItemSelected += OnItemSelected; GUI_facadeView.Add(nextPageItem); currentFacadeItems.Add(nextPageItem); } if (indextoSelect > -1 && indextoSelect < GUI_facadeView.Count) GUI_facadeView.SelectedListItemIndex = indextoSelect; if (imageHash.Count > 0) ImageDownloader.GetImages<VideoInfo>(currentVideoList); string filterstring = currentFilter.ToString(); if (!string.IsNullOrEmpty(filterstring) && !string.IsNullOrEmpty(videosVKfilter)) filterstring += " & "; filterstring += videosVKfilter; GUIPropertyManager.SetProperty("#OnlineVideos.filter", filterstring); currentVideosDisplayMode = mode; CurrentState = State.videos; if (PluginConfiguration.Instance.StoreLayoutPerCategory) suggestedView = FavoritesDatabase.Instance.GetPreferredLayout(SelectedSite.Settings.Name, selectedCategory) ?? suggestedView; UpdateViewState(); return true; }
private void SetSearchResultItemsToFacade(List<SearchResultItem> resultList, VideosMode mode = VideosMode.Search, string categoryName = "") { if (resultList != null && resultList.Count > 0) { if (resultList[0] is VideoInfo) { SetVideosToFacade(resultList.ConvertAll(i => i as VideoInfo), mode); // if only 1 result found and the current site has a details view for this video - open it right away if (SelectedSite is IChoice && resultList.Count == 1 && (resultList[0] as VideoInfo).HasDetails) { // actually select this item, so fanart can be shown in this and the coming screen! (fanart handler inspects the #selecteditem proeprty of teh facade) GUI_facadeView.SelectedListItemIndex = 1; selectedVideo = (GUI_facadeView[1] as OnlineVideosGuiListItem).Item as VideoInfo; DisplayDetails(); } } else { Category searchCategory = CrossDomain.OnlineVideosAppDomain.Domain.CreateInstanceAndUnwrap(typeof(Category).Assembly.FullName, typeof(Category).FullName) as Category; searchCategory.Name = categoryName; searchCategory.HasSubCategories = true; searchCategory.SubCategoriesDiscovered = true; searchCategory.SubCategories = resultList.ConvertAll(i => { (i as Category).ParentCategory = searchCategory; return i as Category; }); SetCategoriesToFacade(searchCategory, searchCategory.SubCategories, true); } } else { GUIDialogNotify dlg_error = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlg_error != null) { dlg_error.Reset(); dlg_error.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlg_error.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName); dlg_error.SetText(Translation.Instance.NoVideoFound); dlg_error.DoModal(GUIWindowManager.ActiveWindow); } } }