protected async Task DisplayCategoryAsync(object categoryToShow) { CategoryAction.Clear(); // displaying main category if (categoryToShow == null) { Debug.Write("Displaing categoryToShow is null"); int AllViews = 0; SetButton(1, Category.TitleForNull, true); SetButton(2, String.Empty, false); SetButton(3, String.Empty, false); var categoryList = await _rzeszowiakRepository.GetMasterCategoryListAsync(); foreach (var item in categoryList) { AllViews += item.Views; } CategoryAction.Add(new CatDisplay { Title = Category.TitleForNull, Views = AllViews, Image = LastSelectedCategory == null ? CatSelectImage.selected : CatSelectImage.none, CategoryObj = null, }); foreach (var category in categoryList) { CategoryAction.Add( new CatDisplay { Title = category.Title, Views = category.Views, Image = CatSelectImage.arrowDeeper, CategoryObj = category, }); } } // display category if (categoryToShow != null && categoryToShow.GetType() == typeof(MasterCategory)) { Debug.Write("Displaing categoryToShow is MasterCategory"); var master = categoryToShow as MasterCategory; SetButton(1, Category.TitleForNull, true, CatSelectImage.arrowUp, master); SetButton(2, master.Title, true, CatSelectImage.none, master); SetButton(3, String.Empty, false); var categoryList = await _rzeszowiakRepository.GetCategoryListAsync(); foreach (var category in categoryList) { if (master == category.Master) { var catDisplay = new CatDisplay { Title = category.Title, Views = category.Views, Image = (LastSelectedCategory == category) && (category.SelectedChildCategory == null) && ((category.ChildCategory?.Count ?? 0) == 0) ? CatSelectImage.selected : ((category.ChildCategory?.Count ?? 0) > 0 ? CatSelectImage.arrowDeeper : CatSelectImage.none), CategoryObj = category, }; CategoryAction.Add(catDisplay); if (catDisplay.Image == CatSelectImage.selected) { lastSelect = catDisplay; lastImageState = (category.ChildCategory?.Count ?? 0) > 0 ? CatSelectImage.arrowDeeper : CatSelectImage.none; } } } } //display childCategory if (categoryToShow != null && categoryToShow?.GetType() == typeof(Category)) { Debug.Write("Displaing categoryToShow is Category"); var category = categoryToShow as Category; SetButton(1, Category.TitleForNull, true, CatSelectImage.arrowUp, category.Master); SetButton(2, category.Master.Title, true, CatSelectImage.arrowUp, category.Master); SetButton(3, category.Title, true, CatSelectImage.none, category); var catDisplay = new CatDisplay { Title = $"Wszystkie w {category.Title}", Views = category.Views, Image = ((LastSelectedCategory) == category) && (LastSelectedCategory?.SelectedChildCategory == null) ? CatSelectImage.selected : CatSelectImage.none, CategoryObj = category, }; CategoryAction.Add(catDisplay); if (catDisplay.Image == CatSelectImage.selected) { lastSelect = catDisplay; lastImageState = CatSelectImage.none; } foreach (var child in category.ChildCategory) { Debug.Write("End Displaing categoryToShow is MasterCategory"); catDisplay = new CatDisplay { Title = child.Title, Views = child.Views, Image = (LastSelectedCategory == category && LastSelectedCategory?.SelectedChildCategory == child) ? CatSelectImage.selected : CatSelectImage.none, CategoryObj = child, }; CategoryAction.Add(catDisplay); if (catDisplay.Image == CatSelectImage.selected) { lastSelect = catDisplay; lastImageState = CatSelectImage.none; } } } }