private void FilterMenuItems(string numeratorValue)
 {
     if (!string.IsNullOrEmpty(numeratorValue) && Char.IsLower(numeratorValue[0]))
     {
         _filtered = true;
         SubCategories.Clear();
         MenuItems.Clear();
         var items = Categories.Select(x => x.Category).SelectMany(x => x.ScreenMenuItems).Where(
             x => numeratorValue.ToLower().Split(' ').All(y => x.Name.ToLower().Contains(y)))
                     .Select(x => new ScreenMenuItemButton(x, MenuItemCommand, SelectedCategory));
         MenuItems.AddRange(items.OrderBy(x => x.FindOrder(numeratorValue)).Take(30));
     }
     else if (_filtered)
     {
         _filtered = false;
         UpdateMenuButtons(SelectedCategory);
     }
 }
Exemplo n.º 2
0
        private void UpdateMenuButtons(ScreenMenuCategory category)
        {
            MenuItems = CreateMenuButtons(category, CurrentPageNo, CurrentTag ?? "");

            SubCategories.Clear();
            SubCategories.AddRange(
                AppServices.DataAccessService.GetSubCategories(category, CurrentTag)
                .Select(x => new ScreenSubCategoryButton(x, SubCategoryCommand, category.MButtonColor, category.SubButtonHeight)));

            if (!string.IsNullOrEmpty(CurrentTag))
            {
                var backButton = new ScreenSubCategoryButton(CurrentTag.Replace(CurrentTag.Split(',').Last(), "").Trim(new[] { ',', ' ' }), SubCategoryCommand, "Gainsboro", category.SubButtonHeight, true);
                SubCategories.Add(backButton);
            }

            if (Categories != null && MenuItems.Count == 0)
            {
                if (category.NumeratorType == 2 && SubCategories.Count == 0)
                {
                    InteractionService.ShowKeyboard();
                }

                MenuItems.Clear();

                if (category.MaxItems > 0)
                {
                    IEnumerable <ScreenMenuItem> sitems = category.ScreenMenuItems.OrderBy(x => x.Order);
                    if (SubCategories.Count == 0)
                    {
                        sitems = Categories.Select(x => x.Category).SelectMany(x => x.ScreenMenuItems);
                    }
                    var items = sitems.Select(x => new ScreenMenuItemButton(x, MenuItemCommand, SelectedCategory));
                    if (category.SortType == 1)
                    {
                        items = items.OrderByDescending(x => x.UsageCount);
                    }
                    MenuItems.AddRange(items.Take(category.MaxItems));
                }
            }

            RaisePropertyChanged("MenuItems");
            RaisePropertyChanged("IsPageNumberNavigatorVisible");
            RaisePropertyChanged("MenuItemsVerticalAlignment");
        }
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Properties.Clear();
                Categories.Clear();
                SubCategories.Clear();

                var props = await GetProperties();

                foreach (var prop in props)
                {
                    Properties.Add(prop);
                }
                var cats = await GetCategories();

                foreach (var cat in cats)
                {
                    Categories.Add(cat);
                }
                var subs = await GetSubCategories();

                foreach (var sub in subs)
                {
                    SubCategories.Add(sub);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }