Ejemplo n.º 1
0
        public async void InitializePageSequence()
        {
            Console.WriteLine("PageController 32 []]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] " + ContentManager.isUserNew + ContentManager.isLocal);

            this.BarBackgroundColor = Color.WhiteSmoke;
            this.BarTextColor       = Color.Black;
            this.UnselectedTabColor = Color.Gray;
            this.SelectedTabColor   = ContentManager.ThemeColor;

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

            ContentManager.AddOnBackgroundChangeListener(c => currentPageContainer.BackgroundColor = c);
            if (ContentManager.isUserNew)
            {
                SetUpPage setupPage = new SetUpPage();
                setupPage.Title = "Zesty";
                Children.Add(setupPage);
                Console.WriteLine("PageCOntroller 53 is change native view action null " + (ContentManager.SetNativeViewFunction == null));
                ContentManager.SetNativeViewFunction(setupPage);
            }
            else
            {
                if (ContentManager.isLocal)
                {
                    ContentManager.sessionUserProfile = await LocalStorageController.GetUserAsync();
                }
                ToMainPage();
            }
        }
Ejemplo n.º 2
0
        private async void UpdateShelf(string name, ItemLayout itemLayout, int cellIndex)
        {
            // Update copies: Meta Item Base contains copies of items that should be updated
            ItemLayout metaItemLayout     = ContentManager.MetaItemBase[itemLayout.ItemData.ID];
            ItemLayout unplacedItemLayout = ContentManager.UnplacedItemBase[itemLayout.ItemData.ID];

            itemLayout.iconImage.RemoveEffect(typeof(ScreenTouch));
            itemLayout.IsVisible = false;


            metaItemLayout.ItemData.SetStorage(name, cellIndex, ContentManager.GetStorageType());
            itemLayout.ItemData.SetStorage(name, cellIndex, ContentManager.GetStorageType());

            ContentManager.UnplacedItemBase.Remove(itemLayout.ItemData.ID);
            GridManager.RemoveGridItem(ContentManager.unplacedGridName, unplacedItemLayout);

            // Weird fact: the animation actually allows the touchEffect cycle to complete without complaining that the item is disposed.
            var storage        = ContentManager.GetSelectedStorage(name);
            var cellBackground = storage.GetGridCell(cellIndex).GetBackground();
            await ViewExtensions.QuadraticInterpolator(cellBackground, 0.2, 250, d => cellBackground.Scale = d + 1, null);

            GridManager.RemoveGridItem(partialUnplacedGrid, itemLayout);

            storage.AddGridItems(cellIndex, new List <View>()
            {
                itemLayout
            });

            if (ContentManager.isLocal)
            {
                LocalStorageController.UpdateItem(itemLayout.ItemData);
            }
            else
            {
                FireBaseController.SaveItem(itemLayout.ItemData);
            }
        }
Ejemplo n.º 3
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 }
                                    } }
            };
        }
Ejemplo n.º 4
0
        public SetUpPage()
        {
            title = new Label()
            {
                Text = "Welcome To Zesty", FontSize = 25, FontFamily = "Oswald-Regular", TextColor = Color.Black,
                HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.StartAndExpand, Margin = new Thickness(0, title_top_margin, 0, 0)
            };
            var accountName = new Label()
            {
                Text = "Username", FontSize = 18, FontFamily = "Raleway-Regular", TextColor = Color.Black, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalTextAlignment = TextAlignment.Center
            };
            var accountInput = new Entry()
            {
                Placeholder = "Star Chef", PlaceholderColor = Color.Gray, WidthRequest = ContentManager.screenWidth / 2
            };
            var confirmButton = new Button()
            {
                Text            = "Confirm", FontFamily = "Oswald-Regular", FontSize = 20, TextColor = Color.Black, Margin = new Thickness(side_margin, vert_margin),
                BackgroundColor = Color.WhiteSmoke, CornerRadius = 5, BorderColor = Color.Black, BorderWidth = 1
            };

            confirmButton.Clicked += async(obj, arg) =>
            {
                if (ContentManager.isLocal)
                {
                    var name = accountInput.Text == null ? "Zesty Chef" : accountInput.Text;
                    ContentManager.sessionUserProfile = new UserProfile()
                    {
                        Name      = name,
                        IconImage = ContentManager.ProfileIcons[0],
                        IsLocal   = true
                    };
                    LocalStorageController.AddUser(ContentManager.sessionUserProfile);
                    LocalStorageController.SetMetaUserInfo(new MetaUserInfo(true));
                }
                else
                {
                    ContentManager.sessionUserProfile.Name = accountInput.Text;
                    var remoteUser = new UserProfile()
                    {
                        Name      = accountInput.Text,
                        Email     = ContentManager.sessionUserProfile.Email,
                        IconImage = ContentManager.ProfileIcons[0],
                        IsLocal   = false
                    };
                    await FireBaseController.AddUser(remoteUser);

                    // Need to add remote user to local file to ensure notification sends warning w/ correct user info
                    LocalStorageController.AddUser(remoteUser);
                    LocalStorageController.SetMetaUserInfo(new MetaUserInfo(false));
                }
                await content.QuadraticFlight(10, 90, -80, 100, t => content.TranslationY = t.Y, 1500);

                ContentManager.pageController.ToMainPage();
            };

            content = new StackLayout()
            {
                WidthRequest    = ContentManager.screenWidth,
                BackgroundColor = ContentManager.ThemeColor,
                Children        =
                {
                    title,
                    new StackLayout()
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HeightRequest     = ContentManager.screenHeight * name_input_height_proportional,
                        Margin            = new Thickness(side_margin, ContentManager.screenHeight / 2 - title_top_margin - (vert_margin * 3),               side_margin, 0),
                        Children          =
                        {
                            accountName,accountInput
                        }
                    },
                    confirmButton
                }
            };

            Content = new StackLayout()
            {
                BackgroundColor = ContentManager.ThemeColor, Children = { content }
            };
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retrieves the view that allows user to edit profile image, name, and email
        /// </summary>
        /// <returns></returns>
        private View GetEditUserView()
        {
            var stackLayout = new StackLayout();
            var grid        = new Grid()
            {
                Margin          = new Thickness(20),
                BackgroundColor = Color.Lavender,
                VerticalOptions = LayoutOptions.EndAndExpand,
                RowDefinitions  =
                {
                    new RowDefinition(),
                    new RowDefinition(),
                    new RowDefinition()
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition(),
                    new ColumnDefinition()
                }
            };

            userIconCarousel = new CarouselView()
            {
                HeightRequest = icon_size, HorizontalOptions = LayoutOptions.Center, PeekAreaInsets = new Thickness(icon_size / 4, 0), Loop = false, IsScrollAnimated = true
            };
            userIconCarousel.ItemTemplate = new DataTemplate(() =>
            {
                ImageButton icon = new ImageButton()
                {
                    IsEnabled = false, WidthRequest = icon_size, HeightRequest = icon_size, CornerRadius = icon_size / 2
                };
                icon.SetBinding(ImageButton.SourceProperty, "Source");

                return(icon);
            });
            List <ProfileIcon> iconList = new List <ProfileIcon>();

            foreach (var icon in ContentManager.ProfileIcons)
            {
                iconList.Add(new ProfileIcon()
                {
                    Source = icon
                });
            }
            userIconCarousel.ItemsSource = iconList;
            currentIconIndex             = ContentManager.ProfileIcons.IndexOf(ContentManager.ProfileIcons.Find(s => s.Equals(ContentManager.sessionUserProfile.IconImage)));
            Console.WriteLine("Preference 189 current icon index " + currentIconIndex);
            var nameLabel = new Label()
            {
                Text = "Name", FontFamily = main_font, FontSize = small_font_size, TextColor = Color.Black
            };
            var usernameEntry = new Entry()
            {
                Text = ContentManager.sessionUserProfile.Name
            };
            var emailLabel = new Label()
            {
                Text = "Email", FontFamily = main_font, FontSize = small_font_size, TextColor = Color.Black
            };

            emailLabel.Text = ContentManager.sessionUserProfile.Email == null || ContentManager.sessionUserProfile.Email.Equals("") ? "" : ContentManager.sessionUserProfile.Email;
            var emailEntry = new Entry()
            {
                Text = emailLabel.Text
            };
            var saveButton = new Button()
            {
                Text = "Confirm", FontFamily = main_font, TextColor = Color.Black, CornerRadius = 3
            };

            grid.Children.Add(nameLabel, 0, 0);
            grid.Children.Add(usernameEntry, 1, 0);
            if (!ContentManager.isLocal)
            {
                grid.Children.Add(emailLabel, 0, 1);
                grid.Children.Add(emailEntry, 1, 1);
            }
            grid.Children.Add(saveButton, 0, 2);
            Grid.SetColumnSpan(saveButton, 2);

            saveButton.Clicked += async(o, a) =>
            {
                ContentManager.sessionUserProfile.ChangeProfileWithListener(usernameEntry.Text, emailEntry.Text, (userIconCarousel.CurrentItem as ProfileIcon).Source);

                if (ContentManager.isLocal)
                {
                    LocalStorageController.UpdateUser(ContentManager.sessionUserProfile);
                }
                else
                {
                    await FireBaseController.UpdateUser(new UserProfile()
                    {
                        Name      = usernameEntry.Text,
                        Email     = emailEntry.Text,
                        IconImage = (userIconCarousel.CurrentItem as ProfileIcon).Source,
                        IsLocal   = ContentManager.sessionUserProfile.IsLocal
                    });
                }

                ContentManager.pageController.RemoveViewOverlay(stackLayout);
            };

            stackLayout.Children.Add(userIconCarousel);
            stackLayout.Children.Add(grid);
            stackLayout.BackgroundColor = Color.Beige;

            return(stackLayout);
        }
Ejemplo n.º 7
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;
        }