コード例 #1
0
        public void ShowAlert(string title, string body, string confirmString, string cancelString, Action onConfirmAction, Action onCancelAction)
        {
            Button confirmButton = new Button()
            {
                Text = confirmString, TextColor = Color.Black, BackgroundColor = Color.AntiqueWhite, CornerRadius = 10
            };
            Button cancelButton = new Button()
            {
                Text = cancelString, TextColor = Color.Black, BackgroundColor = Color.AntiqueWhite, CornerRadius = 10
            };
            Grid buttonGrid = GridManager.InitializeGrid(1, 2, GridLength.Star, GridLength.Star);

            buttonGrid.VerticalOptions = LayoutOptions.EndAndExpand;
            GridManager.AddGridItem(buttonGrid, new List <View>()
            {
                confirmButton, cancelButton
            }, false);

            Frame frame = new Frame()
            {
                BackgroundColor = Color.Bisque,
                CornerRadius    = 45,
                Content         = new StackLayout()
                {
                    Children =
                    {
                        new Label()
                        {
                            Text = title, TextColor = Color.Black, FontFamily = "Oswald-Medium", FontSize = 25, HorizontalTextAlignment = TextAlignment.Center
                        },
                        new Label()
                        {
                            Text = body, TextColor = Color.Black, Margin = new Thickness(10), FontFamily = "Raleway-Regular", FontSize = 15
                        },
                        buttonGrid
                    }
                }
            };

            confirmButton.Clicked += (o, a) => { onConfirmAction?.Invoke(); RemoveViewOverlay(frame); };
            cancelButton.Clicked  += (o, a) => { onCancelAction?.Invoke(); RemoveViewOverlay(frame); };

            frame.AnchorX = 0.5;
            frame.AnchorY = 0.5;

            SetViewOverlay(frame, 300, 300, 0.5, 0.5, AbsoluteLayoutFlags.PositionProportional);
        }
コード例 #2
0
ファイル: AddView.cs プロジェクト: Bingostew/Zesty
        /// <summary>
        /// Initialized an instance of add form with a num pad.
        /// </summary>
        ///
        /// <returns></returns>
        public AddView(Action <Item> localUnplacedEvent, Action <Item> baseUnplacedEvent,
                       string storageName = "", bool limited = true, Grid partialUnplacedGrid = null)
        {
            BackgroundColor = ContentManager.ThemeColor;
            ContentManager.AddOnBackgroundChangeListener(c => BackgroundColor = c);

            item = new Item().SetItem(-1, -1, -1, 1, "product", ContentManager.addIcon);
            Grid currentGrid = new Grid();

            Vector2D <int> selectGridIndex = new Vector2D <int>(0, 5);

            presetSelectGrid            = GridManager.InitializeGrid("Partial Preset Grid", 2, 1, formIconWidthHeight, formIconWidthHeight);
            presetSelectGrid.RowSpacing = form_icon_margin; presetSelectGrid.ColumnSpacing = form_icon_margin;
            presetScrollView            = new ScrollView()
            {
                Content = presetSelectGrid, Orientation = ScrollOrientation.Horizontal, Margin = new Thickness(0, form_grid_spacing)
            };
            defaultSelectGrid            = GridManager.InitializeGrid("Partial Default Grid", 2, 1, formIconWidthHeight, formIconWidthHeight);
            defaultSelectGrid.RowSpacing = form_icon_margin; defaultSelectGrid.ColumnSpacing = form_icon_margin;
            GridManager.AddGridItem(defaultSelectGrid, ContentManager.GeneralIcons, true, GridOrganizer.OrganizeMode.VerticalLeft);
            defaultScrollView = new ScrollView()
            {
                Content = defaultSelectGrid, Orientation = ScrollOrientation.Horizontal, Margin = new Thickness(0, form_grid_spacing)
            };

            foreach (IconLayout icon in ContentManager.GeneralIcons)
            {
                icon.OnClickIconAction = (imageButton) =>
                {
                    toggleIconSelect(imageButton, defaultSelectGrid); item.Icon = icon.GetImageSource();
                };
            }

            autoDetectLabel = new Label()
            {
                FontSize = 15, TextColor = Color.Black, BackgroundColor = Color.White, IsVisible = false, AnchorX = 0
            };

            Grid form = new Grid()
            {
                BackgroundColor = ContentManager.ThemeColor,
                RowSpacing      = form_grid_spacing,
                ColumnSpacing   = form_grid_spacing,
                RowDefinitions  =
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = 120
                    },
                    new ColumnDefinition()
                }
            };

            ContentManager.AddOnBackgroundChangeListener(c => form.BackgroundColor = c);

            void ClearText(Button button)
            {
                button.Text = "";
                toggleSelect(selectorIndex, formSelector, selectedColor, unselectedColor);
            }

            nameInput = new Entry()
            {
                HeightRequest   = form_height_proportional * ContentManager.screenHeight / form_grid_row_count, Placeholder = "Product",
                BackgroundColor = unselectedColor, PlaceholderColor = Color.Black, Margin = new Thickness(0, form_label_horizontal_margin, form_label_horizontal_margin, 0)
            };
            nameInput.Unfocused += (obj, args) => { nameInput.BackgroundColor = unselectedColor; item.Name = nameInput.Text; autoDetectExpiration(nameInput.Text); if (imageSelectorIndex == 0)
                                                    {
                                                        changeSelectedIcon();
                                                    }
            };
            nameInput.Focused   += (obj, args) => { nameInput.BackgroundColor = selectedColor; };
            nameInput.Completed += (obj, args) => { item.Name = nameInput.Text; if (imageSelectorIndex == 0)
                                                    {
                                                        changeSelectedIcon();
                                                    }
            };
            var nameLabel = new Label()
            {
                Text = "Name: ", FontSize = form_label_font_size, TextColor = Color.Black, Margin = new Thickness(form_label_horizontal_margin, 0), VerticalTextAlignment = TextAlignment.Center
            };
            var dateLabel = new Label()
            {
                Text = "Exp. Date: ", FontSize = form_label_font_size, TextColor = Color.Black, Margin = new Thickness(form_label_horizontal_margin, 0), VerticalTextAlignment = TextAlignment.Center
            };
            var amountLabel = new Label()
            {
                Text = "Amount: ", FontSize = form_label_font_size, TextColor = Color.Black, Margin = new Thickness(form_label_horizontal_margin, 0), VerticalTextAlignment = TextAlignment.Center
            };
            var iconLabel = new Label()
            {
                Text = "Icon: ", FontSize = form_label_font_size, TextColor = Color.Black, HeightRequest = formGridRowHeight, VerticalTextAlignment = TextAlignment.Center
            };
            var dateMonth = new Button()
            {
                BorderColor = Color.Black, BorderWidth = form_input_border_width, BackgroundColor = Color.Transparent, TextColor = Color.Black
            };

            dateMonth.Clicked += (obj, arg) => { selectorIndex = 0; ClearText(dateMonth); };
            var dateDay = new Button()
            {
                BorderColor = Color.Black, BorderWidth = form_input_border_width, BackgroundColor = Color.Transparent, TextColor = Color.Black
            };

            dateDay.Clicked += (obj, arg) => { selectorIndex = 1; ClearText(dateDay); };
            var dateYear = new Button()
            {
                BorderColor = Color.Black, BorderWidth = form_input_border_width, TextColor = Color.Black
            };

            dateYear.Clicked += (obj, arg) => { selectorIndex = 2; ClearText(dateYear); };
            var amountInput = new Button()
            {
                BorderColor = Color.Black, BorderWidth = form_input_border_width, BackgroundColor = Color.Transparent,
                Margin      = new Thickness(0, 0, form_label_horizontal_margin, 0), TextColor = Color.Black
            };

            amountInput.Clicked += (obj, arg) => { selectorIndex = 3; ClearText(amountInput); };
            Grid expGrid = GridManager.InitializeGrid(1, 3, GridLength.Star, GridLength.Star);

            expGrid.ColumnSpacing = form_grid_spacing;
            expGrid.Margin        = new Thickness(0, 0, form_label_horizontal_margin, 0);
            GridManager.AddGridItem(expGrid, new List <View>()
            {
                dateMonth, dateDay, dateYear
            }, true);

            var iconSelect1 = new Button()
            {
                HeightRequest = formGridRowHeight, Text = "Preset", TextColor = Color.Black, CornerRadius = form_icon_select_border_radius,
                BorderColor   = Color.Black, BorderWidth = 2
            };

            iconSelect1.Clicked += (obj, arg) =>
            {
                imageSelectorIndex = 0; toggleSelect(0, imageSelector, selectedColor, unselectedColor);

                defaultScrollView.IsVisible = false;
                presetScrollView.IsVisible  = true;
                changeSelectedIcon();
            };
            var iconSelect2 = new Button()
            {
                HeightRequest = formGridRowHeight, Text = "General", TextColor = Color.Black, CornerRadius = form_icon_select_border_radius,
                BorderColor   = Color.Black, BorderWidth = 2
            };

            iconSelect2.Clicked += (obj, arg) =>
            {
                imageSelectorIndex          = 1; toggleSelect(1, imageSelector, selectedColor, unselectedColor);
                defaultScrollView.IsVisible = true;
                presetScrollView.IsVisible  = false;
                Console.WriteLine("AddView 144 default select grid children length " + defaultSelectGrid.Children.Count + " " + ((Grid)defaultScrollView.Content).Children.Count);
            };

            Grid iconLabelGrid = GridManager.InitializeGrid(3, 1, GridLength.Star, GridLength.Star);

            GridManager.AddGridItem(iconLabelGrid, new List <View>()
            {
                iconLabel, iconSelect1, iconSelect2
            }, false);
            iconLabelGrid.Margin = new Thickness(form_label_horizontal_margin, form_grid_spacing);

            void toggleSelect(int index, List <Button> buttonList, Color colorTo, Color normal)
            {
                foreach (var button in buttonList)
                {
                    button.BackgroundColor = normal;
                }
                buttonList[index].BackgroundColor = colorTo;
            }

            formSelector.Add(dateMonth);
            formSelector.Add(dateDay);
            formSelector.Add(dateYear);
            formSelector.Add(amountInput);
            imageSelector.Add(iconSelect1);
            imageSelector.Add(iconSelect2);

            form.Children.Add(nameLabel, 0, 0);
            form.Children.Add(nameInput, 1, 0);
            form.Children.Add(dateLabel, 0, 1);
            form.Children.Add(expGrid, 1, 1);
            form.Children.Add(amountLabel, 0, 2);
            form.Children.Add(amountInput, 1, 2);
            form.Children.Add(presetScrollView, 1, 3);
            form.Children.Add(defaultScrollView, 1, 3);
            form.Children.Add(iconLabelGrid, 0, 3);
            Grid.SetRowSpan(presetScrollView, 2);
            Grid.SetRowSpan(iconLabelGrid, 2);
            Grid.SetRowSpan(defaultScrollView, 2);

            void setItem(int newText, int index)
            {
                switch (selectorIndex)
                {
                case 0: item.expMonth = newText; break;

                case 1: item.expDay = newText; break;

                case 2: item.expYear = newText; break;

                case 3: item.Amount = newText; break;
                }
            }

            void changeText(string addedText)
            {
                // limiting digits: month / day: 2 digits. Year: 4 digits. Amount : 3 digits.
                int    limit   = selectorIndex == 2 ? 4 : selectorIndex == 3 ? 3 : 2;
                string oldText = formSelector[selectorIndex].Text ?? "";
                string newText = oldText;

                if (oldText.Length < limit)
                {
                    toggleSelect(selectorIndex, formSelector, selectedColor, unselectedColor);
                    newText = oldText + addedText;
                    formSelector[selectorIndex].Text = newText;
                    if (oldText.Length == limit - 1 && selectorIndex < formSelector.Count - 1)
                    {
                        var inputInt = int.Parse(newText);
                        switch (selectorIndex)
                        {
                        case 0:
                            if (inputInt > 12)
                            {
                                newText = "12";
                            }
                            if (int.Parse(newText.ToCharArray()[0].ToString()) == 0)
                            {
                                newText.Remove(0, 1);
                            }
                            if (inputInt <= 0)
                            {
                                newText = "1";
                            }
                            break;

                        case 1:
                            var text = formSelector[0].Text ?? "1";
                            if (int.Parse(text.ToCharArray()[0].ToString()) == 0)
                            {
                                text.Remove(0, 1);
                            }
                            var maxDay = DateCalculator.GetMonthList()[int.Parse(text) - 1];
                            if (inputInt > maxDay)
                            {
                                newText = maxDay.ToString();
                            }
                            if (inputInt <= 0)
                            {
                                newText = "1";
                            }
                            break;

                        case 3:
                            if (inputInt < 0)
                            {
                                newText = "1";
                            }
                            break;
                        }
                        formSelector[selectorIndex].Text = newText;
                        setItem(int.Parse(newText), selectorIndex);
                        selectorIndex++;
                        toggleSelect(selectorIndex, formSelector, selectedColor, unselectedColor);
                    }
                    else
                    {
                        setItem(int.Parse(newText), selectorIndex);
                    }
                }
                else if (selectorIndex < formSelector.Count - 1)
                {
                    newText = oldText + addedText;
                    formSelector[selectorIndex].Text = newText;
                    setItem(int.Parse(newText), selectorIndex);
                    selectorIndex++; toggleSelect(selectorIndex, formSelector, selectedColor, unselectedColor);
                }
            }

            Grid numPadGrid = GridManager.InitializeGrid(4, 3, GridLength.Star, GridLength.Star);

            numPadGrid.BackgroundColor = ContentManager.ThemeColor;
            ContentManager.AddOnBackgroundChangeListener(c => numPadGrid.BackgroundColor = c);
            numPadGrid.Margin        = new Thickness(form_label_horizontal_margin, 0);
            numPadGrid.RowSpacing    = numpad_spacing;
            numPadGrid.ColumnSpacing = numpad_spacing;

            List <View> numPadList = new List <View>();

            for (int i = 1; i < 10; i++)
            {
                var button = new Button()
                {
                    Text = i.ToString(), TextColor = Color.Black, Margin = new Thickness(0), BackgroundColor = numpadBackground, FontSize = numpad_font_size
                };
                int index = i;
                button.Clicked += (obj, arg) => changeText(index.ToString());
                numPadList.Add(button);
            }

            var numpadBottomLeftEmptyBuffer = new Button()
            {
                IsVisible = false
            };
            var zeroButton = new Button()
            {
                Text = "0", TextColor = Color.Black, FontSize = numpad_font_size, BackgroundColor = numpadBackground
            };

            zeroButton.Clicked += (obj, arg) => changeText("0");

            numPadList.Add(numpadBottomLeftEmptyBuffer);
            numPadList.Add(zeroButton);

            numPadGrid.OrganizeGrid(numPadList, GridOrganizer.OrganizeMode.HorizontalLeft);

            var scanButton = new Button()
            {
                Text = "Scan", TextColor = Color.Black, FontAttributes = FontAttributes.Bold, BackgroundColor = numpadBackground
            };
            var exitButton = new Button()
            {
                Text = "Exit", BackgroundColor = Color.WhiteSmoke, TextColor = Color.Black, Margin = new Thickness(5), BorderColor = Color.Black, BorderWidth = 1
            };
            var newFormButton = new Button()
            {
                BackgroundColor = Color.WhiteSmoke, Text = "Add", TextColor = Color.Black, Margin = new Thickness(5), BorderColor = Color.Black, BorderWidth = 1
            };

            manualEditLayout = new AbsoluteLayout()
            {
                HorizontalOptions = LayoutOptions.Center,
                HeightRequest     = ContentManager.screenHeight,
                WidthRequest      = ContentManager.screenWidth,
                BackgroundColor   = ContentManager.ThemeColor,
                Children          =
                {
                    form,
                    autoDetectLabel,
                    numPadGrid,
                    scanButton,
                    newFormButton,
                    exitButton
                }
            };

            scanButton.Clicked += (o, a) =>
            {
                ContentManager.pageController.ToScanPage(this);
            };
            async void OnNewItemAdded(object obj, EventArgs args)
            {
                var animatedImage = new Image()
                {
                    Source = item.Icon.Substring(6), Aspect = Aspect.Fill
                };

                manualEditLayout.Children.Add(animatedImage, new Rectangle(0.5, 0.9, 100, 100), AbsoluteLayoutFlags.PositionProportional);
                await animatedImage.QuadraticFlight(15, 75, -80, 30, (v) => { animatedImage.TranslationX = -v.X; animatedImage.TranslationY = -v.Y; }, 1500, easing : Easing.Linear);
            }

            newFormButton.Clicked += OnNewItemAdded;
            newFormButton.Clicked += (obj, args) =>
            {
                Item itemInstance = new Item().SetItem(item.expYear, item.expMonth, item.expDay, item.Amount, item.Name, item.Icon);
                Console.WriteLine("Addview 309 item icon " + itemInstance.Icon + " " + item.Icon);
                itemInstance.SetDaysUntilExpiration();
                newItem.Add(itemInstance);
                if (ContentManager.isLocal)
                {
                    localUnplacedEvent?.Invoke(itemInstance);
                }
                else
                {
                    Console.WriteLine("Addview 302 base unplace storage");
                    baseUnplacedEvent?.Invoke(itemInstance);
                }
                ResetForm();
            };

            AbsoluteLayout.SetLayoutBounds(autoDetectLabel, new Rectangle(0, 0, 1, .06));
            AbsoluteLayout.SetLayoutFlags(autoDetectLabel, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(form, new Rectangle(0, 0, 1, form_height_proportional));
            AbsoluteLayout.SetLayoutFlags(form, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(numPadGrid, new Rectangle(.5, .7, 1, numpad_height_proportional));
            AbsoluteLayout.SetLayoutFlags(numPadGrid, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(scanButton, new Rectangle(.5, .88, .5, .08));
            AbsoluteLayout.SetLayoutFlags(scanButton, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(newFormButton, new Rectangle(0, 1, 0.5, .1));
            AbsoluteLayout.SetLayoutFlags(newFormButton, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(exitButton, new Rectangle(1, 1, 0.5, .1));
            AbsoluteLayout.SetLayoutFlags(exitButton, AbsoluteLayoutFlags.All);

            exitButton.Clicked += (obj, args) =>
            {
                List <ItemLayout> newItemLayouts      = new List <ItemLayout>();
                List <ItemLayout> newItemLayoutsCopy  = new List <ItemLayout>();
                List <ItemLayout> newItemLayoutsCopy2 = new List <ItemLayout>();

                SaveInput(newItemLayouts, newItemLayoutsCopy, newItemLayoutsCopy2);

                if (partialUnplacedGrid != null)
                {
                    GridManager.AddGridItem(partialUnplacedGrid, newItemLayoutsCopy2, false);
                }

                newItemLayouts.Clear();
                newItemLayoutsCopy.Clear();
                newItemLayoutsCopy2.Clear();
                ResetForm();
                newItem.Clear();
                ContentManager.pageController.ReturnToPrevious();
            };

            Content = manualEditLayout;
        }
コード例 #3
0
        // DirectGridFootIndex: when page loads, partial grids directly goes to the set of items with the first item being this index.
        public CabinetAddPage(string _storageName, int directGridFootIndex = 0)
        {
            storageName = _storageName;

            storageView = ContentManager.GetStorageView(storageName);
            storageView.WidthRequest    = ContentManager.screenWidth;
            storageView.HeightRequest   = ContentManager.screenHeight * .75;
            storageView.VerticalOptions = LayoutOptions.EndAndExpand;
            animateStorage();

            async void animateStorage()
            {
                await storageView.LinearInterpolator(animation_offestX, 200, (d) => { storageView.TranslationY = animation_offestX - d; });
            }

            //-- set up unplaced grid
            unplacedGrid               = GridManager.GetGrid(ContentManager.unplacedGridName);
            partialUnplacedGrid        = GridManager.InitializeGrid(ContentManager.pUnplacedGridName, 2, 4, GridLength.Star, GridLength.Star);
            partialUnplacedGrid.Margin = new Thickness(grid_margin, 0);
            // add listener to set TouchEffect for each new item added. If grid already exist
            partialUnplacedGrid.ChildAdded += (o, v) =>
            {
                EffectManager.UpdateScreenTouchBounds(v.Element as ItemLayout, storageName, UpdateShelf);
            };
            // Add listener to remove partial unplaced grid child
            unplacedGrid.ChildRemoved += (o, a) =>
            {
                foreach (ItemLayout child in partialUnplacedGrid.Children)
                {
                    if ((a.Element as ItemLayout).ItemData.ID == child.ItemData.ID)
                    {
                        partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true);
                        break;
                    }
                }
            };
            Console.WriteLine("CabinetAddPage 42 Unplaced children length " + unplacedGrid.Children.Count);
            // initialize grid by constraining UnplacedGrid and Converter
            itemLayoutCopier = (v) =>
            {
                return(new ItemLayout(50, 50, (v as ItemLayout).ItemData)
                       .AddMainImage()
                       .AddExpirationMark()
                       .AddTitle()
                       .AddInfoIcon());
            };
            partialUnplacedGrid = GridManager.ConstrainGrid(GridManager.GetGrid(ContentManager.unplacedGridName), directGridFootIndex, directGridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true);
            addView             = new AddView(LocalStorageController.AddItem, FireBaseController.SaveItem, storageName, true, partialUnplacedGrid);

            // title grid
            var titleGrid = new TopPage(_storageName, () =>
            {
                foreach (ItemLayout child in partialUnplacedGrid.Children)
                {
                    child.iconImage.RemoveEffect(typeof(ScreenTouch));
                }
                foreach (StorageCell child in ContentManager.GetSelectedStorage(storageName).GetGridCells())
                {
                    child.GetButton().RemoveEffect(typeof(ImageTint));
                }
                GridManager.RemoveGrid(ContentManager.pUnplacedGridName);
            }).GetGrid();


            gridFootIndex = directGridFootIndex;
            var gridPageSelectGrid = new Grid()
            {
                Margin            = new Thickness(grid_margin, 0),
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = 50
                    },
                    new ColumnDefinition()
                    {
                        Width = 30
                    },
                    new ColumnDefinition()
                    {
                        Width = 30
                    },
                    new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    }
                }
            };
            var nextPage = new ImageButton()
            {
                Source = ContentManager.countIcon
            };

            nextPage.Clicked += (obj, args) =>
            {
                Console.WriteLine("CabinetAddPage grid foot index " + gridFootIndex);
                gridFootIndex      += 7;
                partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true);
            };
            var lastPage = new ImageButton()
            {
                Source = ContentManager.countIcon, Rotation = 180
            };

            lastPage.Clicked += (obj, args) =>
            {
                Console.WriteLine("CabinetAddPage grid foot index " + gridFootIndex);
                gridFootIndex       = gridFootIndex - 7 < 0 ? 0 : gridFootIndex - 7;
                partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true);
            };
            var addNewButton = new ImageButton()
            {
                Source = ContentManager.addIcon, BackgroundColor = Color.Transparent
            };

            addNewButton.Clicked += (obj, args) => { addView.ResetForm(); ContentManager.pageController.ToAddView(addView); };
            var searchBar = new SearchBar()
            {
                Text = ContentManager.defaultSearchAllBarText, MinimumWidthRequest = 300
            };

            searchBar.Focused   += (obj, args) => searchBar.Text = "";
            searchBar.Unfocused += (obj, args) =>
            {
                if (searchBar.Text.Length == 0)
                {
                    searchBar.Text = ContentManager.defaultSearchAllBarText;
                }
                GridManager.FilterItemGrid(ContentManager.UnplacedItemBase.Values, partialUnplacedGrid, searchBar.Text);
            };

            gridPageSelectGrid.Children.Add(lastPage, 1, 0);
            gridPageSelectGrid.Children.Add(nextPage, 2, 0);
            gridPageSelectGrid.Children.Add(addNewButton, 0, 0);
            gridPageSelectGrid.Children.Add(searchBar, 3, 0);

            pageContainer = new AbsoluteLayout();
            pageContainer.BackgroundColor = ContentManager.ThemeColor;
            ContentManager.AddOnBackgroundChangeListener(c => pageContainer.BackgroundColor = c);
            pageContainer.Children.Add(titleGrid, new Rectangle(0, 0, 1, TopPage.top_bar_height_proportional), AbsoluteLayoutFlags.All);
            pageContainer.Children.Add(storageView, new Rectangle(1, 1, 1, .5), AbsoluteLayoutFlags.All);
            pageContainer.Children.Add(gridPageSelectGrid, new Rectangle(0, .12, 1, .09), AbsoluteLayoutFlags.All);
            pageContainer.Children.Add(partialUnplacedGrid, new Rectangle(0, .28, 1, .3), AbsoluteLayoutFlags.All);

            Content = new AbsoluteLayout()
            {
                Children =
                {
                    pageContainer
                }
            };
            AbsoluteLayout.SetLayoutBounds(pageContainer, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(pageContainer, AbsoluteLayoutFlags.All);
        }
コード例 #4
0
ファイル: CabinetViewPage.cs プロジェクト: Bingostew/Zesty
        // If directSelectIndex is > -1, then the cell with this index will be displayed immediately after user enters the view.
        public CabinetViewPage(string name, Action <Item> deleteItemLocal, Action <Item> deleteItemBase, Action <Item> updateItemLocal, Action <Item> updateItemBase,
                               ContentManager.StorageSelection storageSelection, int directSelectIndex = -1)
        {
            updateItemLocalEvent = updateItemLocal;
            updateItemBaseEvent  = updateItemBase;
            deleteItemBaseEvent  = deleteItemBase;
            deleteItemLocalEvent = deleteItemLocal;

            var titleGrid = new TopPage(name, extraReturnAction: () =>
            {
                foreach (var cell in storage.GetGridCells())
                {
                    cell.GetButton().RemoveEffect(typeof(ImageTint));
                }
            }).GetGrid();

            titleGrid.HeightRequest = ContentManager.screenHeight * TopPage.top_bar_height_proportional;

            var   backgroundImage = storageSelection == ContentManager.StorageSelection.fridge ? ContentManager.fridgeIcon : ContentManager.cabinetCellIcon;
            Image backgroundCell  = new Image()
            {
                Source = backgroundImage, Aspect = Aspect.Fill, WidthRequest = ContentManager.screenWidth - (layout_margin * 2)
            };
            ImageButton backButton = new ImageButton()
            {
                Source = ContentManager.backButton, BackgroundColor = Color.Transparent, WidthRequest = 100, HeightRequest = 100
            };

            backButton.Clicked += (obj, args) =>
            {
                viewOverlay.IsVisible = false;
            };

            // searching and sorting
            var sortSelectorIcon = new ImageButton()
            {
                Source          = ContentManager.sortIcon,
                BackgroundColor = Color.Transparent
            };
            var sortSelector = new Picker()
            {
                Margin      = new Thickness(layout_margin),
                ItemsSource = new List <string>()
                {
                    expIndicatorString, alphaIndicatorString
                },
                Title = "Sort Order",
            };
            var searchBar = new SearchBar()
            {
                Margin      = new Thickness(layout_margin),
                Placeholder = "Search"
            };
            var toolGrid = new Grid()
            {
                Margin         = new Thickness(layout_margin, 0),
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = ContentManager.screenHeight * tool_grid_height_proportional
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(5, GridUnitType.Star)
                    }, new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                }
            };

            toolGrid.Children.Add(searchBar, 0, 0);
            toolGrid.Children.Add(sortSelectorIcon, 1, 0);
            toolGrid.Children.Add(sortSelector, 1, 0);

            viewOverlay = new AbsoluteLayout()
            {
                IsVisible       = false,
                BackgroundColor = ContentManager.ThemeColor,
                WidthRequest    = ContentManager.screenWidth - (layout_margin * 2),
                HeightRequest   = ContentManager.screenHeight * 0.4,
                Margin          = new Thickness(layout_margin, 0, layout_margin, layout_margin),
                Children        =
                {
                    backgroundCell
                }
            };
            ContentManager.AddOnBackgroundChangeListener(c => viewOverlay.BackgroundColor = c);

            ScrollView gridContainer = new ScrollView()
            {
                WidthRequest = ContentManager.screenWidth
            };

            gridContainer.Scrolled += (o, a) => Console.WriteLine("CabinetView 74 gridcontainer scrolled");
            viewOverlay.Children.Add(gridContainer, AbsoluteLayout.GetLayoutBounds(backgroundCell), AbsoluteLayout.GetLayoutFlags(backgroundCell));

            sortSelector.SelectedIndexChanged += (obj, args) =>
            {
                if (currentGrid != null)
                {
                    switch (sortSelector.SelectedItem)
                    {
                    case expIndicatorString: GridOrganizer.SortItemGrid(currentGrid, GridOrganizer.ItemSortingMode.Expiration_Close); break;

                    case alphaIndicatorString: GridOrganizer.SortItemGrid(currentGrid, GridOrganizer.ItemSortingMode.A_Z); break;
                    }
                }
            };

            searchBar.Unfocused += (o, a) =>
            {
                var  currentGridChildren = currentGrid.Children.Cast <ItemLayout>();
                Grid filteredGrid        = GridManager.InitializeGrid(1, 4, new GridLength(ContentManager.item_layout_size, GridUnitType.Absolute), GridLength.Star);
                GridManager.FilterItemGrid(currentGridChildren, filteredGrid, searchBar.Text);
                gridContainer.Content = filteredGrid;
            };

            // storage model
            var storageView = ContentManager.GetStorageView(storageSelection, name);

            storageView.HeightRequest = ContentManager.screenHeight * storage_height_proportional;
            storage = ContentManager.GetSelectedStorage(storageSelection, name);
            var storageViewWidth = storageSelection == ContentManager.StorageSelection.cabinet ? storage_width_proportional_cabinet : storage_width_proportional_fridge;

            // expiration info grid
            var totalItemIcon = new ImageButton()
            {
                Source = ContentManager.allItemIcon, BackgroundColor = Color.Transparent
            };
            var totalItemLabel = new Label()
            {
                TextColor = Color.Black, FontFamily = "oswald_regular", VerticalTextAlignment = TextAlignment.Center, FontSize = main_font_size
            };
            var expiredIcon = new ImageButton()
            {
                Source = ContentManager.expWarningIcon, BackgroundColor = Color.Transparent
            };
            var expiredAmountLabel = new Label()
            {
                TextColor = Color.Black, FontFamily = "oswald_regular", VerticalTextAlignment = TextAlignment.Center, FontSize = main_font_size
            };
            var almostExpiredIcon = new ImageButton()
            {
                Source = ContentManager.expWarningIcon, BackgroundColor = Color.Transparent
            };
            var almostExpiredAmountLabel = new Label()
            {
                TextColor = Color.Black, FontFamily = "oswald_regular", VerticalTextAlignment = TextAlignment.Center, FontSize = main_font_size
            };
            var expInfoGrid = new Grid()
            {
                RowDefinitions =
                {
                    new RowDefinition(),
                    new RowDefinition(),
                    new RowDefinition()
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    }, new ColumnDefinition()
                    {
                        Width = new GridLength(2, GridUnitType.Star)
                    }
                }
            };

            GridManager.AddGridItem(expInfoGrid, new List <View>()
            {
                totalItemIcon, totalItemLabel, expiredIcon, expiredAmountLabel, almostExpiredIcon, almostExpiredAmountLabel
            }, true);

            var storageViewAndExpGrid = GridManager.InitializeGrid(1, 2, GridLength.Star, GridLength.Star);

            storageViewAndExpGrid.HeightRequest = ContentManager.screenHeight * storage_height_proportional;
            GridManager.AddGridItem(storageViewAndExpGrid, new List <View>()
            {
                storageView, expInfoGrid
            }, true);

            // sets the text info for all item amount, expired item amount, and almost expired item amount
            void calculateExpirationAmount(Grid itemLayoutGrid)
            {
                int expiredItemCount       = 0;
                int almostExpiredItemCount = 0;

                foreach (ItemLayout item in itemLayoutGrid.Children)
                {
                    if (item.ItemData.daysUntilExp == 0)
                    {
                        expiredItemCount++;
                    }
                    else if (item.ItemData.daysUntilExp <= 7 && item.ItemData.daysUntilExp > 0)
                    {
                        almostExpiredItemCount++;
                    }
                }
                totalItemLabel.Text           = "Items: " + itemLayoutGrid.Children.Count;
                expiredAmountLabel.Text       = "Expired: " + expiredItemCount;
                almostExpiredAmountLabel.Text = "Almost Expired: " + almostExpiredItemCount;
            }

            foreach (var cell in storage.GetGridCells())
            {
                // Set up listener to show overlay
                ImageButton button = cell.GetButton();
                var         grid   = cell.GetItemGrid();
                currentGrid        = grid;
                grid.ChildRemoved += (o, a) => { calculateExpirationAmount(grid); };
                grid.WidthRequest  = WidthRequest = ContentManager.screenWidth - (layout_margin * 2);
                grid.Margin        = new Thickness(layout_margin, 0);

                button.Clicked += async(obj, args) =>
                {
                    viewOverlay.IsVisible = true;
                    gridContainer.Content = grid;
                    var viewOverlayXOffset = ContentManager.screenWidth * 0.75;
                    await viewOverlay.LinearInterpolator(viewOverlayXOffset, 200, t => viewOverlay.TranslationX = viewOverlayXOffset - t);

                    calculateExpirationAmount(grid);
                    grid.IsVisible = true;
                };

                foreach (var child in grid.Children)
                {
                    child.IsVisible = true;
                }
            }
            Console.WriteLine("Cabinet View 136 " + directSelectIndex);
            // Set direct view of cell
            if (directSelectIndex >= 0)
            {
                Console.WriteLine("CabinetView 140 View item grid children: overlayed");
                viewOverlay.IsVisible = true;
                var cell = storage.GetGridCell(directSelectIndex);
                var grid = cell.GetItemGrid();
                gridContainer.Content = grid;
                grid.IsVisible        = true;
                cell.GetButton().AddEffect(new ImageTint()
                {
                    tint = ContentManager.button_tint_color
                });
            }

            Content = new StackLayout()
            {
                HeightRequest = ContentManager.screenHeight,
                WidthRequest  = ContentManager.screenWidth,
                Children      =
                {
                    titleGrid,
                    storageViewAndExpGrid,
                    toolGrid,
                    viewOverlay
                }
            };
        }
コード例 #5
0
ファイル: ContentManager.cs プロジェクト: Bingostew/Zesty
        public static async void InitializeApp()
        {
            item_layout_size = screenWidth / 4;

            // Initialize ID Groups
            IDGenerator.InitializeIDGroup(itemStorageIdGenerator);
            IDGenerator.InitializeIDGroup(cabinetEditIdGenerator);
            IDGenerator.InitializeIDGroup(fridgeEditIdGenerator);
            IDGenerator.InitializeIDGroup(storageCellIdGenerator);
            IDGenerator.InitializeIDGroup(IOSNotificationIdGenerator);
            LocalStorageController.ResetDatabase(); // WARNING: FOR TESTING PURPOSES ONLY
            LocalStorageController.InitializeLocalDataBase();

            // Initialize Important Grids
            GridManager.InitializeGrid(metaGridName, 9, 4, GridLength.Auto, GridLength.Star);
            GridManager.InitializeGrid(unplacedGridName, 0, 4, GridLength.Star, GridLength.Star);

            Console.WriteLine("ContentManger 75 is user new -=================================================================== " + ContentManager.isUserNew + ContentManager.isLocal);
            // Load saved data
            if (!isUserNew)
            {
                List <Cabinet> localCabinets = await LocalStorageController.GetTableListAsync <Cabinet>();

                List <Fridge> localFridges = await LocalStorageController.GetTableListAsync <Fridge>();

                List <StorageCell> localStorageCells = await LocalStorageController.GetTableListAsync <StorageCell>();

                List <Item> localItems = await LocalStorageController.GetTableListAsync <Item>();

                List <Cabinet>     baseCabinets     = new List <Cabinet>();
                List <Fridge>      baseFridges      = new List <Fridge>();
                List <StorageCell> baseStorageCells = new List <StorageCell>();
                List <Item>        baseItems        = new List <Item>();

                if (!isLocal)
                {
                    // Populating list with firebase
                    baseCabinets     = (await FireBaseController.GetCabinets()).ToList().ConvertAll(o => o.Object);
                    baseFridges      = (await FireBaseController.GetFridges()).ToList().ConvertAll(o => o.Object);
                    baseItems        = (await FireBaseController.GetItems()).ToList().ConvertAll(o => o.Object);
                    baseStorageCells = (await FireBaseController.GetStorageCells());


                    // Load with cloud data
                    ContentLoader.LoadItems(baseItems);
                    ContentLoader.LoadCabinets(baseCabinets, baseStorageCells, baseItems);
                    ContentLoader.LoadFridges(baseFridges, baseStorageCells, baseItems);
                }
                else
                {
                    // Load with local data
                    ContentLoader.LoadItems(localItems);
                    ContentLoader.LoadCabinets(localCabinets, localStorageCells, localItems);
                    ContentLoader.LoadFridges(localFridges, localStorageCells, localItems);
                }
            }

            if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet)
            {
                Console.WriteLine("Contentmanager 135 User Has Internet :)");
            }
            else
            {
                Console.WriteLine("Contentmanager 138 User Has No Internet :<(");
            }

            // start UI sequence
            pageController.InitializePageSequence();
        }
コード例 #6
0
        public PreferencePage()
        {
            // Register background change listener
            BackgroundColor = ContentManager.ThemeColor;
            ContentManager.AddOnBackgroundChangeListener(c => BackgroundColor = c);
            // Title section
            var titleGrid    = GridManager.InitializeGrid(1, 3, 50, GridLength.Star);
            var returnButton = new ImageButton()
            {
                Source = ContentManager.backButton, BackgroundColor = Color.Transparent
            };
            var pageTitleLabel = new Label()
            {
                Text = "Setting", FontFamily = title_font, FontSize = 30, TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center
            };

            GridManager.AddGridItem(titleGrid, new List <View> {
                returnButton, pageTitleLabel
            }, false);
            returnButton.Clicked += (o, a) => ContentManager.pageController.ReturnToPrevious();

            // User profile section
            var user = ContentManager.sessionUserProfile;
            var userProfileSection = new Grid()
            {
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = icon_size + 10
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = icon_size + 10
                    },
                    new ColumnDefinition()
                }
            };


            userIcon = new ImageButton()
            {
                Source = user.IconImage, WidthRequest = icon_size, HeightRequest = icon_size, BackgroundColor = Color.Transparent, CornerRadius = icon_size / 2, Margin = new Thickness(5)
            };
            ContentManager.sessionUserProfile.AddOnProfileChangedListener(u => userIcon.Source = u.IconImage);
            usernameLabel = new Label()
            {
                Text = user.Name, FontFamily = main_font, FontSize = 30, TextColor = Color.Black, Margin = new Thickness(0, 30, 0, 0)
            };
            ContentManager.sessionUserProfile.AddOnProfileChangedListener(u => usernameLabel.Text = u.Name);
            userEmailLabel = new Label()
            {
                FontFamily = main_font, FontSize = small_font_size, TextColor = Color.Black
            };
            ContentManager.sessionUserProfile.AddOnProfileChangedListener(u => userEmailLabel.Text = u.Email == null || u.Email.Equals("") ? "Local Account" : u.Email);
            userEmailLabel.Text = user.Email == null || user.Email.Equals("") ? "Local Account" : user.Email;
            var editProfileButton = new Button()
            {
                Text = "Edit Profile", FontFamily = main_font, FontSize = 15, CornerRadius = 2, Margin = new Thickness(0, 0, 0, 30)
            };
            var profileDivider = new Button()
            {
                BackgroundColor = Color.Gray, HeightRequest = divider_height, Margin = new Thickness(side_margin, 0)
            };

            editProfileButton.Clicked += (o, a) => { ContentManager.pageController.SetViewOverlay(GetEditUserView(), .75, .75, 0.5, 0.5); ScrollToImageIcon(); };

            userProfileSection.Children.Add(userIcon, 0, 0);
            userProfileSection.Children.Add(new StackLayout()
            {
                Spacing       = 0,
                HeightRequest = icon_size,
                Children      = { usernameLabel, userEmailLabel, editProfileButton }
            }, 1, 0);

            // Preference section
            var preferenceSection = new Grid()
            {
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = standard_height
                    },
                    new RowDefinition()
                    {
                        Height = standard_height
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition(),
                    new ColumnDefinition()
                }
            };

            var preferenceLabel = new Label()
            {
                Text = "Preferences", FontSize = title_font_size, FontFamily = title_font, TextColor = Color.Black, Margin = new Thickness(side_margin, 0)
            };
            var themeLabel = new Label()
            {
                Text = "Background Theme", FontFamily = main_font, FontSize = main_font_size, TextColor = Color.Black, Margin = new Thickness(side_margin, 0)
            };
            var themeCarousel = new CarouselView()
            {
                HeightRequest = theme_square_size + 70, PeekAreaInsets = new Thickness(30, 0), Margin = new Thickness(0, 0, side_margin, 0), Loop = false
            };

            themeCarousel.ItemTemplate = new DataTemplate(() =>
            {
                ImageButton image = new ImageButton()
                {
                    IsEnabled   = false, WidthRequest = theme_square_size, HeightRequest = theme_square_size,
                    BorderColor = Color.Black, BorderWidth = 2, CornerRadius = theme_square_size / 2, Margin = new Thickness(20)
                };
                image.SetBinding(Image.SourceProperty, "Image");
                image.SetBinding(Image.BackgroundColorProperty, "Color");

                return(image);
            });
            List <ThemeIcon> themeList = new List <ThemeIcon>()
            {
                new ThemeIcon()
                {
                    Color = Color.Wheat, Source = ContentManager.transIcon
                },
                new ThemeIcon()
                {
                    Color = Color.PapayaWhip, Source = ContentManager.transIcon
                },
                new ThemeIcon()
                {
                    Color = Color.BurlyWood, Source = ContentManager.transIcon
                },
                new ThemeIcon()
                {
                    Color = Color.LemonChiffon, Source = ContentManager.transIcon
                }
            };

            themeCarousel.ItemsSource = themeList;
            int currentThemeIndex = 0;

            themeCarousel.Scrolled += (o, a) =>
            {
                if (a.CenterItemIndex != currentThemeIndex)
                {
                    currentThemeIndex         = a.CenterItemIndex;
                    ContentManager.ThemeColor = themeList[currentThemeIndex].Color;
                }
            };

            var notifLabel = new Label()
            {
                Text = "Notification", FontFamily = main_font, FontSize = main_font_size, TextColor = Color.Black, Margin = new Thickness(side_margin, 0)
            };
            var notifGrid = GridManager.InitializeGrid(3, 2, 50, GridLength.Star);

            notifGrid.Margin = new Thickness(0, 0, side_margin, 0);
            var oneDayNotif = new Switch()
            {
                IsToggled = true, WidthRequest = 80, OnColor = Color.Goldenrod
            };
            var threeDayNotif = new Switch()
            {
                IsToggled = true, WidthRequest = 80, OnColor = Color.Goldenrod
            };
            var oneWeekNotif = new Switch()
            {
                IsToggled = true, WidthRequest = 80, OnColor = Color.Goldenrod
            };
            var oneDayLabel = new Label()
            {
                Text = "1 day", FontSize = small_font_size, FontFamily = main_font, TextColor = Color.Black, VerticalTextAlignment = TextAlignment.Center
            };
            var threeDayLabel = new Label()
            {
                Text = "3 days", FontSize = small_font_size, FontFamily = main_font, TextColor = Color.Black, VerticalTextAlignment = TextAlignment.Center
            };
            var oneWeekLabel = new Label()
            {
                Text = "1 week", FontSize = small_font_size, FontFamily = main_font, TextColor = Color.Black, VerticalTextAlignment = TextAlignment.Center
            };

            oneDayNotif.Toggled   += (o, a) => { ContentManager.sessionUserProfile.enableOneDayWarning = a.Value; updateUser(); };
            threeDayNotif.Toggled += (o, a) => { ContentManager.sessionUserProfile.enableThreeDayWarning = a.Value; updateUser(); };
            oneWeekNotif.Toggled  += (o, a) => { ContentManager.sessionUserProfile.enableOneWeekWarning = a.Value; updateUser(); };
            GridManager.AddGridItem(notifGrid, new List <View>()
            {
                oneDayLabel, oneDayNotif, threeDayLabel, threeDayNotif, oneWeekLabel, oneWeekNotif
            }, true, Utility.GridOrganizer.OrganizeMode.HorizontalRight);

            async void updateUser()
            {
                if (ContentManager.isLocal)
                {
                    LocalStorageController.UpdateUser(ContentManager.sessionUserProfile);
                }
                else
                {
                    await FireBaseController.UpdateUser(ContentManager.sessionUserProfile);
                }
            }

            preferenceSection.Children.Add(preferenceLabel, 0, 0);
            Grid.SetColumnSpan(preferenceLabel, 2);
            preferenceSection.Children.Add(themeLabel, 0, 1);
            preferenceSection.Children.Add(themeCarousel, 1, 1);
            preferenceSection.Children.Add(notifLabel, 0, 2);
            preferenceSection.Children.Add(notifGrid, 1, 2);
            Grid.SetRowSpan(notifGrid, 3);


            content = new ScrollView()
            {
                Content = new StackLayout()
                {
                    HeightRequest = ContentManager.screenHeight,
                    Spacing       = 5,
                    Children      =
                    {
                        titleGrid,
                        userProfileSection,
                        profileDivider,
                        preferenceSection
                    }
                }
            };
            Content = content;
        }