protected async Task Select(CatDisplay catDisplay, Category selCategory, ChildCategory childCategory = null) { Debug.Write("Select " + catDisplay?.Title ?? "null"); if (selCategory == null) { Debug.Write("Category is null"); } if (lastSelect != null) { lastSelect.Image = lastImageState; } lastSelect = catDisplay; lastImageState = catDisplay?.Image ?? CatSelectImage.none; LastSelectedCategory = selCategory; if (selCategory != null) { LastSelectedCategory.SelectedChildCategory = childCategory; } catDisplay.Image = CatSelectImage.selected; var navigationParams = new NavigationParameters(); navigationParams.Add("SelectedCategory", selCategory); await _navigationService.GoBackAsync(navigationParams); }
protected async void ItemTapedAsync(CatDisplay catTapped) { Debug.Write("ItemTapedAsync"); if (catTapped == null) { Debug.Write("ItemTapedAsync catTapped == null"); return; } // clicked on Wszystkie kategorie if (catTapped.CategoryObj == null) { Debug.Write("Tapped all category"); await Select(catTapped, null); return; } if (catTapped.CategoryObj.GetType() == typeof(MasterCategory)) { Debug.Write("Tapped CategoryObj is MasterCategory"); var master = catTapped.CategoryObj as MasterCategory; await DisplayCategoryAsync(master); } if (catTapped.CategoryObj.GetType() == typeof(Category)) { Debug.Write("Tapped CategoryObj is Category"); var category = catTapped.CategoryObj as Category; if (((category.ChildCategory?.Count ?? 0) > 0) && (catTapped.Title.IndexOf($"Wszystkie w {category.Title}") == -1)) { await DisplayCategoryAsync(category); // displaing more } else { category.SelectedChildCategory = null; await Select(catTapped, category); } } if (catTapped.CategoryObj.GetType() == typeof(ChildCategory)) { Debug.Write("Tapped CategoryObj is ChildCategory"); var child = catTapped.CategoryObj as ChildCategory; await Select(catTapped, child?.ParentCategory, child); } }
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; } } } }