Inheritance: MediaPortal.UI.Presentation.DataObjects.ListItem
        public void ChangeModelContext(MediaPortal.UI.Presentation.Workflow.NavigationContext oldContext, MediaPortal.UI.Presentation.Workflow.NavigationContext newContext, bool push)
        {
			// reload a site when going away from configuring it and settings were changed
			if (oldContext.WorkflowState.StateId == Guids.WorkflowStateSiteSettings && FocusedSite.UserSettingsChanged)
			{
				FocusedSite.RecreateSite();
				// save Site Settings
				(OnlineVideoSettings.Instance.UserStore as Configuration.UserSiteSettingsStore).SaveAll();
			}

            // going to sites view
            if (newContext.WorkflowState.StateId == Guids.WorkflowStateSites)
            {
                SelectedCategory = null;
                CategoriesList = null;
            }
            // going from categories to categories view
			else if (newContext.WorkflowState.Name == Guids.WorkflowStateCategoriesName && oldContext.WorkflowState.Name == Guids.WorkflowStateCategoriesName)
            {
                // going up in hierarchy
                if (oldContext.Predecessor == newContext)
                {
                    CategoriesList = new ItemsList();
                    if (SelectedCategory.Category.ParentCategory != null)
                    {
                        SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c)));
                        ImageDownloader.GetImages<Category>(SelectedCategory.Category.ParentCategory.SubCategories);
						SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory);
                    }
                    else
                    {
                        foreach (Category c in SelectedSite.Site.Settings.Categories) CategoriesList.Add(new CategoryViewModel(c));
                        ImageDownloader.GetImages<Category>(SelectedSite.Site.Settings.Categories);
						SelectedCategory = null;
                    }
                }
            }
            // going from videos to categories view
			else if (newContext.WorkflowState.Name == Guids.WorkflowStateCategoriesName && oldContext.WorkflowState.StateId == Guids.WorkflowStateVideos)
            {
                VideosList = null;
                CategoriesList = new ItemsList();

                if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null)
                {
					SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c)));
                    ImageDownloader.GetImages<Category>(SelectedCategory.Category.ParentCategory.SubCategories);
                }
                else
                {
                    foreach (Category c in SelectedSite.Site.Settings.Categories) CategoriesList.Add(new CategoryViewModel(c));
                    ImageDownloader.GetImages<Category>(SelectedSite.Site.Settings.Categories);
                }

				if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null)
					SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory);
				else
					SelectedCategory = null;
            }
            // going from details to videos view
            else if (newContext.WorkflowState.StateId == Guids.WorkflowStateVideos && oldContext.WorkflowState.StateId == Guids.WorkflowStateDetails)
            {
                DetailsVideosList = null;
            }
        }
		internal void ShowSearchResults(List<SearchResultItem> result, string title)
		{
			// pop all states up to the site state from the current navigation stack
			IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
			while (!(workflowManager.NavigationContextStack.Peek().WorkflowState.Name == Guids.WorkflowStateCategoriesName &&
				workflowManager.NavigationContextStack.Peek().WorkflowState.DisplayLabel == SelectedSite.Name))
			{
				workflowManager.NavigationContextStack.Pop();
			}
			// create a "fake" Category as Parent for a results items
			var searchCategory = new CategoryViewModel(
				new Category()
				{
					Name = title,
					HasSubCategories = result[0] is Category,
					SubCategoriesDiscovered = true
				});
			// display results
			if (result[0] is VideoInfo)
			{
				ShowVideos(searchCategory, result.ConvertAll(i => i as VideoInfo));
			}
			else
			{
				searchCategory.Category.SubCategories = result.ConvertAll(i => { (i as Category).ParentCategory = searchCategory.Category; return i as Category; });
				SelectedCategory = searchCategory;
				ShowCategories(searchCategory.Category.SubCategories, searchCategory.Name);
			}
		}
        void ShowVideos(CategoryViewModel category, List<VideoInfo> videos)
        {
            SelectedCategory = category;
            VideosList = new ItemsList();
			videos.ForEach(r => { r.CleanDescriptionAndTitle(); VideosList.Add(new VideoViewModel(r, SelectedCategory != null ? SelectedCategory.Category : null, SelectedSite.Name, SelectedSite.Site.Settings.UtilName, false)); });

            if (SelectedSite.Site.HasNextPage) VideosList.Add(new VideoViewModel(Translation.Instance.NextPage, "NextPage.png"));

            ImageDownloader.GetImages<VideoInfo>(videos);
            IWorkflowManager workflowManager = ServiceRegistration.Get<IWorkflowManager>();
            workflowManager.NavigatePushAsync(Guids.WorkflowStateVideos, new NavigationContextConfig() { NavigationContextDisplayLabel = SelectedCategory.Name });
        }
		public void SelectCategory(CategoryViewModel categoryModel)
        {
			if (BackgroundTask.Instance.IsExecuting) return;
			if (categoryModel.Category is NextPageCategory)
            {
                // discover and append next page categories
                BackgroundTask.Instance.Start<bool>(
					() =>
					{
						SelectedSite.Site.DiscoverNextPageCategories(categoryModel.Category as NextPageCategory);
						return true;
                    },
					(success, result) =>
					{
						if (success)
						{
							int selectNr = CategoriesList.Count - 1;
							CategoriesList.Clear();
							IList<Category> catList = categoryModel.Category.ParentCategory == null ? (IList<Category>)SelectedSite.Site.Settings.Categories : categoryModel.Category.ParentCategory.SubCategories;
							foreach (Category c in catList) CategoriesList.Add(new CategoryViewModel(c) { Selected = CategoriesList.Count == selectNr });
							ImageDownloader.GetImages<Category>(catList);
							CategoriesList.FireChange();
						}
					},
                    Translation.Instance.GettingNextPageVideos);
            }
            else
            {
				if (categoryModel.Category.HasSubCategories)
                {
					if (!categoryModel.Category.SubCategoriesDiscovered)
                    {
						// discover and show subcategories
                        BackgroundTask.Instance.Start<bool>(
							() =>
							{
								SelectedSite.Site.DiscoverSubCategories(categoryModel.Category);
								return true;
                            },
                            (success, result) =>
							{
								if (success)
								{
									SelectedCategory = categoryModel;
									ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
								}
                            },
                            Translation.Instance.GettingDynamicCategories);
                    }
                    else
                    {
						SelectedCategory = categoryModel;
						ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
                    }
                }
                else
                {
					// discover and show videos of this category
                    BackgroundTask.Instance.Start<List<VideoInfo>>(
						() =>
						{
							return SelectedSite.Site.GetVideos(categoryModel.Category);
                        },
                        (success, videos) =>
						{
							if (success)
							{
								ShowVideos(categoryModel, videos);
							}
                        },
                        Translation.Instance.GettingCategoryVideos);
                }
            }
        }
        public void ChangeModelContext(NavigationContext oldContext, NavigationContext newContext, bool push)
        {
            // reload a site when going away from configuring it and settings were changed
            if (oldContext.WorkflowState.StateId == Guids.WorkflowStateSiteSettings && FocusedSite.UserSettingsChanged)
            {
                FocusedSite.RecreateSite();
                // save Site Settings
                (OnlineVideoSettings.Instance.UserStore as Configuration.UserSiteSettingsStore).SaveAll();
            }

            // going to sites view
            if (newContext.WorkflowState.StateId == Guids.WorkflowStateSites)
            {
                SelectedCategory = null;
                CategoriesList   = null;
            }
            // going from categories to categories view
            else if (newContext.WorkflowState.StateId == Guids.WorkflowStateCategories && oldContext.WorkflowState.StateId == Guids.WorkflowStateCategories)
            {
                // going up in hierarchy
                if (oldContext.Predecessor == newContext)
                {
                    CategoriesList = new ItemsList();
                    if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null)
                    {
                        SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c)));
                        ImageDownloader.GetImages <Category>(SelectedCategory.Category.ParentCategory.SubCategories);
                        SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory);
                    }
                    else
                    {
                        foreach (Category c in SelectedSite.Site.Settings.Categories)
                        {
                            CategoriesList.Add(new CategoryViewModel(c));
                        }
                        ImageDownloader.GetImages <Category>(SelectedSite.Site.Settings.Categories);
                        SelectedCategory = null;
                    }
                }
            }
            // going from videos to categories view
            else if (newContext.WorkflowState.StateId == Guids.WorkflowStateCategories && oldContext.WorkflowState.StateId == Guids.WorkflowStateVideos)
            {
                VideosList     = null;
                CategoriesList = new ItemsList();

                if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null)
                {
                    SelectedCategory.Category.ParentCategory.SubCategories.ForEach(c => CategoriesList.Add(new CategoryViewModel(c)));
                    ImageDownloader.GetImages <Category>(SelectedCategory.Category.ParentCategory.SubCategories);
                }
                else
                {
                    foreach (Category c in SelectedSite.Site.Settings.Categories)
                    {
                        CategoriesList.Add(new CategoryViewModel(c));
                    }
                    ImageDownloader.GetImages <Category>(SelectedSite.Site.Settings.Categories);
                }

                if (SelectedCategory != null && SelectedCategory.Category.ParentCategory != null)
                {
                    SelectedCategory = new CategoryViewModel(SelectedCategory.Category.ParentCategory);
                }
                else
                {
                    SelectedCategory = null;
                }
            }
            // going from details to videos view
            else if (newContext.WorkflowState.StateId == Guids.WorkflowStateVideos && oldContext.WorkflowState.StateId == Guids.WorkflowStateDetails)
            {
                DetailsVideosList = null;
            }
        }
 public void SelectCategory(CategoryViewModel categoryModel)
 {
     if (BackgroundTask.Instance.IsExecuting)
     {
         return;
     }
     if (categoryModel.Category is NextPageCategory)
     {
         // discover and append next page categories
         BackgroundTask.Instance.Start <bool>(
             () =>
         {
             SelectedSite.Site.DiscoverNextPageCategories(categoryModel.Category as NextPageCategory);
             return(true);
         },
             (success, result) =>
         {
             if (success)
             {
                 int selectNr = CategoriesList.Count - 1;
                 CategoriesList.Clear();
                 IList <Category> catList = categoryModel.Category.ParentCategory == null ? (IList <Category>)SelectedSite.Site.Settings.Categories : categoryModel.Category.ParentCategory.SubCategories;
                 foreach (Category c in catList)
                 {
                     CategoriesList.Add(new CategoryViewModel(c)
                     {
                         Selected = CategoriesList.Count == selectNr
                     });
                 }
                 ImageDownloader.GetImages <Category>(catList);
                 CategoriesList.FireChange();
             }
         },
             Translation.Instance.GettingNextPageVideos);
     }
     else
     {
         if (categoryModel.Category.HasSubCategories)
         {
             if (!categoryModel.Category.SubCategoriesDiscovered)
             {
                 // discover and show subcategories
                 BackgroundTask.Instance.Start <bool>(
                     () =>
                 {
                     SelectedSite.Site.DiscoverSubCategories(categoryModel.Category);
                     return(true);
                 },
                     (success, result) =>
                 {
                     if (success)
                     {
                         SelectedCategory = categoryModel;
                         ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
                     }
                 },
                     Translation.Instance.GettingDynamicCategories);
             }
             else
             {
                 SelectedCategory = categoryModel;
                 ShowCategories(categoryModel.Category.SubCategories, categoryModel.Name);
             }
         }
         else
         {
             // discover and show videos of this category
             BackgroundTask.Instance.Start <List <VideoInfo> >(
                 () =>
             {
                 return(SelectedSite.Site.GetVideos(categoryModel.Category));
             },
                 (success, videos) =>
             {
                 if (success)
                 {
                     ShowVideos(categoryModel, videos);
                 }
             },
                 Translation.Instance.GettingCategoryVideos);
         }
     }
 }