Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static void LoadItems(List <Item> items)
        {
            List <View> metaGridChildren     = new List <View>();
            List <View> unplacedGridChildren = new List <View>();

            foreach (Item item in items)
            {
                // Create Itemlayout from item
                ItemLayout itemLayout = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, item).AddMainImage()
                                        .AddExpirationMark()
                                        .AddTitle()
                                        .AddInfoIcon();
                ItemLayout itemLayoutCopy = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, item).AddMainImage()
                                            .AddExpirationMark()
                                            .AddTitle()
                                            .AddInfoIcon();

                itemLayout.RecalculateDate();
                itemLayoutCopy.RecalculateDate();

                ContentManager.MetaItemBase.Add(item.ID, itemLayout);

                metaGridChildren.Add(itemLayout);

                // Record existing ID to the generator
                IDGenerator.SkipID(ContentManager.itemStorageIdGenerator, item.ID);

                // Add to unplaced dictionary if item is not stored
                if (!item.Stored)
                {
                    unplacedGridChildren.Add(itemLayoutCopy);
                    ContentManager.UnplacedItemBase.Add(item.ID, itemLayoutCopy);
                }
            }

            // populates both grids with corresponding children
            GridManager.AddGridItem(ContentManager.metaGridName, metaGridChildren, true);
            GridManager.AddGridItem(ContentManager.unplacedGridName, unplacedGridChildren, true);
        }
Exemplo n.º 3
0
        // First copy for unplacedGrid, second for metaGrid, third is optional for partial grid
        private void SaveInput(List <ItemLayout> newItemLayouts, List <ItemLayout> newItemLayoutsCopy, List <ItemLayout> newItemLayoutsCopy2 = null)
        {
            foreach (Item _item in newItem)
            {
                ItemLayout itemLayout = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, _item)
                                        .AddMainImage()
                                        .AddExpirationMark()
                                        .AddTitle()
                                        .AddInfoIcon();
                Console.WriteLine("AddView 443 item name " + _item.Name);
                ItemLayout itemLayoutCopy = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, _item)
                                            .AddMainImage()
                                            .AddExpirationMark()
                                            .AddTitle()
                                            .AddInfoIcon();

                ItemLayout itemLayoutCopy2 = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, _item)
                                             .AddMainImage()
                                             .AddExpirationMark()
                                             .AddTitle()
                                             .AddInfoIcon();

                newItemLayouts.Add(itemLayout);
                newItemLayoutsCopy.Add(itemLayoutCopy);
                if (newItemLayoutsCopy2 != null)
                {
                    newItemLayoutsCopy2.Add(itemLayoutCopy2);
                }
                ContentManager.MetaItemBase.Add(_item.ID, itemLayout);
                ContentManager.UnplacedItemBase.Add(_item.ID, itemLayoutCopy);
            }


            GridManager.AddGridItem(GridManager.GetGrid(ContentManager.metaGridName), newItemLayouts, false);
            GridManager.AddGridItem(GridManager.GetGrid(ContentManager.unplacedGridName), newItemLayoutsCopy, false);
            Console.WriteLine("AddView 471 partial unplaced grid children count " + newItemLayoutsCopy2.Count);
        }
Exemplo n.º 4
0
        private void changeSelectedIcon()
        {
            presetResult.Clear(); presetResultSorter.Clear();
            foreach (IconLayout icon in ContentManager.PresetIcons)
            {
                var nameList = icon.iconNames;
                int match    = 0;

                foreach (var name in nameList)
                {
                    var itemName = item.Name == null ? new string[0] : item.Name.Split(' ');
                    foreach (string n in itemName)
                    {
                        // check if name is same or contains name with all lower case, all uper case, and first letter uppercase
                        if (name.Contains(n) || name.Contains(n.ToLower()) || name.Contains(n.ToUpper()) || name.Contains(char.ToUpper(n[0]) + n.Substring(1)))
                        {
                            match--;
                        }
                    }
                }

                icon.OnClickIconAction += (button) =>
                {
                    toggleIconSelect(button, presetSelectGrid);
                    item.Icon = icon.GetImageSource();
                };
                presetResultSorter.Add(match);
                presetResult.Add(icon);
                match = 0;
            }

            toggleIconSelect(null, presetSelectGrid);
            ListSorter.SortToListAscending(presetResultSorter, presetResult);
            GridManager.AddGridItem(presetSelectGrid, presetResult, true, GridOrganizer.OrganizeMode.VerticalLeft);
            Console.WriteLine("AddView 177 preset children " + presetSelectGrid.Children.Count + " preset column count " + presetSelectGrid.ColumnDefinitions.Count);
        }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
        public UnplacedPage(Action <Item> localUnplacedEvent, Action <Item> baseUnplaceEvent, Action <Item> deleteItemLocal, Action <Item> deleteItemBase)
        {
            var titleGrid    = new TopPage("Items", useReturnButton: false).GetGrid();
            var addNewButton = new ImageButton()
            {
                Source = ContentManager.addIcon, BackgroundColor = Color.Transparent, Margin = new Thickness(side_margin, between_margin)
            };

            // Renewing contents in meta grid
            metaGrid = GridManager.GetGrid(ContentManager.metaGridName);
            GridManager.AddGridItem(metaGrid, ContentManager.MetaItemBase.Values, true);

            var addView = new AddView(localUnplacedEvent, baseUnplaceEvent, "", false);

            searchAllBar = new SearchBar()
            {
                Margin = new Thickness(side_margin, 0)
            };
            searchAllBar.Text       = ContentManager.defaultSearchAllBarText;
            searchAllBar.TextColor  = Color.Black;
            searchAllBar.Focused   += (obj, args) => searchAllBar.Text = "";
            searchAllBar.Unfocused += (obj, args) => { if (searchAllBar.Text.Length == 0)
                                                       {
                                                           searchAllBar.Text = ContentManager.defaultSearchAllBarText;
                                                       }
            };
            searchAllBar.Unfocused += (obj, args) => GridManager.FilterItemGrid(ContentManager.MetaItemBase.Values, metaGrid, searchAllBar.Text);
            addNewButton.Clicked   += (obj, args) => { addView.ResetForm(); ContentManager.pageController.ToAddView(addView); };

            var sortSelectorIcon = new Image()
            {
                Source = ContentManager.sortIcon
            };
            var sortSelector = new Picker()
            {
                Margin      = new Thickness(side_margin, between_margin),
                ItemsSource = new List <string>()
                {
                    expIndicatorString, alphaIndicatorString
                },
            };

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

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


            gridScroll = new ScrollView()
            {
                Margin = new Thickness(side_margin),
                VerticalScrollBarVisibility = ScrollBarVisibility.Always,
                HeightRequest = Height * 0.8,
                Content       = metaGrid
            };

            AbsoluteLayout.SetLayoutBounds(titleGrid, new Rectangle(0, 0, 1, TopPage.top_bar_height_proportional));
            AbsoluteLayout.SetLayoutFlags(titleGrid, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(searchAllBar, new Rectangle(0, 0.13, 0.8, .1));
            AbsoluteLayout.SetLayoutFlags(searchAllBar, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(addNewButton, new Rectangle(0, .25, 100, 100));
            AbsoluteLayout.SetLayoutFlags(addNewButton, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(sortSelector, new Rectangle(1, 0.13, .2, .1));
            AbsoluteLayout.SetLayoutFlags(sortSelector, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(sortSelectorIcon, AbsoluteLayout.GetLayoutBounds(sortSelector));
            AbsoluteLayout.SetLayoutFlags(sortSelectorIcon, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(gridScroll, new Rectangle(0, 1, 1, .625));
            AbsoluteLayout.SetLayoutFlags(gridScroll, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(addView, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(addView, AbsoluteLayoutFlags.All);
            content = new AbsoluteLayout()
            {
                Children =
                {
                    titleGrid,
                    searchAllBar,
                    addNewButton,
                    sortSelectorIcon,
                    sortSelector,
                    gridScroll
                }
            };

            Content = content;
        }
Exemplo n.º 7
0
 public void UpdateLayout()
 {
     metaGrid = GridManager.GetGrid(ContentManager.metaGridName);
     GridManager.AddGridItem(metaGrid, ContentManager.MetaItemBase.Values, true);
 }
Exemplo n.º 8
0
        public InfoView(Item item)
        {
            // Calculating sizes
            button_width = ContentManager.screenWidth * info_view_width_proportional / 3;
            Grid mainGrid = new Grid()
            {
                HeightRequest  = ContentManager.screenHeight * info_view_height_proportional * 0.75,
                Margin         = new Thickness(side_margin, 0),
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = 1
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = 1
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                    new RowDefinition()
                    {
                        Height = 1
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    },
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = GridLength.Star
                    },
                    new ColumnDefinition()
                    {
                        Width = GridLength.Star
                    },
                }
            };

            var closeButton = new Button()
            {
                BackgroundColor   = Color.Gray, Text = "X", TextColor = Color.Black,
                HorizontalOptions = LayoutOptions.End, WidthRequest = close_button_size, HeightRequest = close_button_size, CornerRadius = 0, Padding = 0
            };

            closeButton.Clicked += (o, a) => ContentManager.pageController.RemoveInfoView(this);
            var itemName = new Label()
            {
                Text = item.Name, TextColor = Color.Black, FontSize = 25, HorizontalTextAlignment = TextAlignment.Center
            };
            var itemNameDivider = new BoxView()
            {
                HeightRequest = 1, WidthRequest = ContentManager.screenWidth * 0.5, Color = Color.Gray
            };
            var itemImage = new Image()
            {
                Source = item.Icon.Substring(6), WidthRequest = 120, HeightRequest = 120, Aspect = Aspect.Fill, HorizontalOptions = LayoutOptions.Center
            };

            var expirationDateTitle = new Label()
            {
                Text = "Expiration Date:", TextColor = Color.Black, FontSize = grid_font_size
            };
            var expDateText         = item.daysUntilExp < 0 ? "?" : item.expMonth + "/" + item.expDay + "/" + item.expYear;
            var expirationDateLabel = new Label()
            {
                Text = expDateText, TextColor = Color.Black, FontSize = grid_font_size, HorizontalTextAlignment = TextAlignment.End
            };
            var expirationDateDivider = new BoxView()
            {
                HeightRequest = 1, WidthRequest = ContentManager.screenWidth * 0.5, Color = Color.Gray
            };

            var daysToExpString       = item.daysUntilExp < 0 ? "?" : item.daysUntilExp.ToString();
            var daysToExpirationTitle = new Label()
            {
                Text = "Days Until Expiration:", TextColor = Color.Black, FontSize = grid_font_size
            };
            var daysToExpirationLabel = new Label()
            {
                Text = daysToExpString, TextColor = Color.Black, FontSize = grid_font_size, HorizontalTextAlignment = TextAlignment.End
            };
            var expirationDayDivider = new BoxView()
            {
                HeightRequest = 1, WidthRequest = ContentManager.screenWidth * 0.5, Color = Color.Gray
            };

            var amountTitle = new Label()
            {
                Text = "Amount: ", TextColor = Color.Black, FontSize = grid_font_size
            };
            var amountLabel = new Label()
            {
                Text = item.Amount.ToString(), TextColor = Color.Black, FontSize = grid_font_size, WidthRequest = 30, HorizontalTextAlignment = TextAlignment.End
            };
            var amountDivider = new BoxView()
            {
                HeightRequest = 1, WidthRequest = ContentManager.screenWidth * 0.5, Color = Color.Gray
            };

            var locationTitle = new Label()
            {
                Text = "Location:", TextColor = Color.Black, FontSize = grid_font_size
            };
            var locationLabel = new Label()
            {
                TextColor = Color.Black, FontSize = grid_font_size, HorizontalTextAlignment = TextAlignment.End
            };

            locationLabel.Text = item.Stored ? item.StorageName : "Not Placed";

            mainGrid.Children.Add(expirationDateTitle, 0, 0);
            mainGrid.Children.Add(expirationDateLabel, 1, 0);
            mainGrid.Children.Add(expirationDateDivider, 0, 1);
            Grid.SetColumnSpan(expirationDateDivider, 2);
            mainGrid.Children.Add(daysToExpirationTitle, 0, 2);
            mainGrid.Children.Add(daysToExpirationLabel, 1, 2);
            mainGrid.Children.Add(expirationDayDivider, 0, 3);
            Grid.SetColumnSpan(expirationDayDivider, 2);
            mainGrid.Children.Add(amountTitle, 0, 4);
            mainGrid.Children.Add(amountLabel, 1, 4);
            mainGrid.Children.Add(amountDivider, 0, 5);
            Grid.SetColumnSpan(amountDivider, 2);
            mainGrid.Children.Add(locationTitle, 0, 6);
            mainGrid.Children.Add(locationLabel, 1, 6);

            var toStorageViewButton = new Button()
            {
                BackgroundColor   = Color.FromRgba(0, 100, 20, 80), Text = "View In Storage", TextColor = Color.Black,
                HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.EndAndExpand, Margin = new Thickness(0, vertical_margin)
            };
            var addButton = new Button()
            {
                BackgroundColor   = Color.FromRgba(0, 100, 0, 80),
                Text              = "Add",
                WidthRequest      = button_width,
                TextColor         = Color.Black,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand,
                Margin            = new Thickness(0, 0, 0, vertical_margin)
            };
            var consumeButton = new Button()
            {
                BackgroundColor   = Color.FromRgba(100, 20, 0, 80),
                Text              = "Consume",
                WidthRequest      = button_width,
                TextColor         = Color.Black,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand,
                Margin            = new Thickness(0, 0, 0, vertical_margin)
            };

            toStorageViewButton.BackgroundColor = item.Stored ? Color.FromRgba(0, 100, 20, 80) : Color.Gray;
            toStorageViewButton.Clicked        += (obj, args) =>
            {
                if (item.Stored)
                {
                    ContentManager.pageController.RemoveInfoView(this);
                    if (!ContentManager.pageController.IsOnPage <CabinetViewPage>())
                    {
                        ContentManager.pageController.ToViewItemPage(item.StorageName, item.StorageCellIndex, item.StorageType);
                    }
                }
            };

            var gradientLineBrush = new LinearGradientBrush(new GradientStopCollection()
            {
                new GradientStop(Color.Transparent, 0.1f),
                new GradientStop(Color.FromRgba(0, 255, 0, 80), 0.5f),
                new GradientStop(Color.Transparent, 1)
            }, new Point(0, 0), new Point(0, 1));
            var gradientLine = new BoxView()
            {
                Background    = gradientLineBrush,
                HeightRequest = 200,
            };



            void animateAmountChange(bool add)
            {
                // Get x, y, w, h in proprotional terms.
                var dhGradientLine = ContentManager.screenHeight - gradientLine.HeightRequest;
                var y = ContentManager.screenHeight * info_view_height_proportional / 2 + ContentManager.screenHeight / 2 - gradientLine.HeightRequest;

                y /= dhGradientLine;
                var h             = gradientLine.HeightRequest / ContentManager.screenHeight;
                var gradientLineY = add ? y : 0;

                ContentManager.pageController.OverlayAnimation(gradientLine, new Rect(0.5, gradientLineY, info_view_width_proportional, h),
                                                               ViewExtensions.LinearInterpolator(gradientLine, ContentManager.screenHeight * info_view_height_proportional - gradientLine.HeightRequest, 500, t => gradientLine.TranslationY = add ? -t : t, Easing.CubicInOut));

                var amountLabelBounds = amountLabel.Bounds;
                var amountChangeLabel = new Label()
                {
                    TextColor = Color.Gray, FontSize = 40, FontAttributes = FontAttributes.Bold, WidthRequest = 50, HeightRequest = 50, HorizontalTextAlignment = TextAlignment.End
                };

                amountChangeLabel.Text = add ? "+1" : "-1";
                var dwAmount = ContentManager.screenWidth - amountChangeLabel.WidthRequest;
                var dhAmount = ContentManager.screenHeight - amountChangeLabel.HeightRequest;

                ContentManager.pageController.OverlayAnimation(amountChangeLabel,
                                                               new Rect(amountLabel.GetAbsolutePosition().X / dwAmount, amountLabel.GetAbsolutePosition().Y / dhAmount, amountChangeLabel.WidthRequest / ContentManager.screenWidth, amountChangeLabel.HeightRequest / ContentManager.screenHeight),
                                                               amountChangeLabel.LinearInterpolator(80, 2000, t => { amountChangeLabel.TranslationY = -t; amountChangeLabel.Opacity = 1 - t / 100; }, Easing.CubicOut),
                                                               () => { amountChangeLabel.TranslationY = 0; });
            }

            addButton.Clicked += (obj, args) =>
            {
                // add amount
                item.Amount++;
                // animate
                animateAmountChange(true);
                amountLabel.Text = item.Amount.ToString();

                // Save data locally or to cloud
                if (ContentManager.isLocal)
                {
                    LocalStorageController.UpdateItem(item);
                }
                else
                {
                    FireBaseController.SaveItem(item);
                }
            };
            consumeButton.Clicked += (obj, args) =>
            {
                // Subtract amount
                item.Amount--;
                // If not fully consumed, keep track of it
                if (item.Amount > 0)
                {
                    animateAmountChange(false);
                    amountLabel.Text = item.Amount.ToString();
                    // Save data locally or to cloud
                    if (ContentManager.isLocal)
                    {
                        LocalStorageController.UpdateItem(item);
                    }
                    else
                    {
                        FireBaseController.SaveItem(item);
                    }
                }
                // If fully consumed, remove it.
                else
                {
                    // If item not stored, remove it from unplaced grid
                    if (!item.Stored)
                    {
                        var itemLayoutUnplaced = ContentManager.UnplacedItemBase[item.ID];
                        var unplacedGrid       = GridManager.GetGrid(ContentManager.unplacedGridName);
                        if (unplacedGrid.Children.Contains(itemLayoutUnplaced))
                        {
                            unplacedGrid.Children.Remove(itemLayoutUnplaced);
                        }
                    }
                    ContentManager.UnplacedItemBase.Remove(item.ID);

                    // Remove item from meta grid
                    var itemLayoutMeta = ContentManager.MetaItemBase[item.ID];
                    var metaGrid       = GridManager.GetGrid(ContentManager.metaGridName);
                    ContentManager.MetaItemBase.Remove(item.ID);
                    GridManager.AddGridItem(metaGrid, ContentManager.MetaItemBase.Values, true);

                    // Exit out of infoView
                    ContentManager.pageController.RemoveInfoView(this);

                    // Save data locally and to cloud
                    if (ContentManager.isLocal)
                    {
                        LocalStorageController.DeleteItem(item);
                    }
                    else
                    {
                        FireBaseController.DeleteItem(item);
                    }

                    // If item is stored, delete it from storage
                    if (item.Stored)
                    {
                        // Delete item from storage cell
                        var gridCell = item.StorageType == ContentManager.fridgeStorageType ? ContentManager.FridgeMetaBase[item.StorageName].GetGridCell(item.StorageCellIndex) :
                                       ContentManager.CabinetMetaBase[item.StorageName].GetGridCell(item.StorageCellIndex);
                        var         cellGrid  = gridCell.GetItemGrid();
                        List <View> childList = cellGrid.Children.ToList();
                        foreach (ItemLayout child in cellGrid.Children)
                        {
                            if (item.ID == child.ItemData.ID)
                            {
                                gridCell.RemoveItem(child);
                                break;
                            }
                        }
                        //Update storage cell children
                        //gridCell.AddItem(childList);
                    }
                }
            };

            pageContainer = new StackLayout()
            {
                BackgroundColor = Color.Beige,
                Children        = { closeButton, itemName, itemNameDivider, itemImage, mainGrid, toStorageViewButton, addButton,
                                    new StackLayout()
                                    {
                                        Orientation = StackOrientation.Horizontal,
                                        Children    = { addButton, consumeButton }
                                    } }
            };
        }
Exemplo n.º 9
0
        // 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
                }
            };
        }
Exemplo n.º 10
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;
        }