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; }
// DirectGridFootIndex: when page loads, partial grids directly goes to the set of items with the first item being this index. public CabinetAddPage(string _storageName, int directGridFootIndex = 0) { storageName = _storageName; storageView = ContentManager.GetStorageView(storageName); storageView.WidthRequest = ContentManager.screenWidth; storageView.HeightRequest = ContentManager.screenHeight * .75; storageView.VerticalOptions = LayoutOptions.EndAndExpand; animateStorage(); async void animateStorage() { await storageView.LinearInterpolator(animation_offestX, 200, (d) => { storageView.TranslationY = animation_offestX - d; }); } //-- set up unplaced grid unplacedGrid = GridManager.GetGrid(ContentManager.unplacedGridName); partialUnplacedGrid = GridManager.InitializeGrid(ContentManager.pUnplacedGridName, 2, 4, GridLength.Star, GridLength.Star); partialUnplacedGrid.Margin = new Thickness(grid_margin, 0); // add listener to set TouchEffect for each new item added. If grid already exist partialUnplacedGrid.ChildAdded += (o, v) => { EffectManager.UpdateScreenTouchBounds(v.Element as ItemLayout, storageName, UpdateShelf); }; // Add listener to remove partial unplaced grid child unplacedGrid.ChildRemoved += (o, a) => { foreach (ItemLayout child in partialUnplacedGrid.Children) { if ((a.Element as ItemLayout).ItemData.ID == child.ItemData.ID) { partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true); break; } } }; Console.WriteLine("CabinetAddPage 42 Unplaced children length " + unplacedGrid.Children.Count); // initialize grid by constraining UnplacedGrid and Converter itemLayoutCopier = (v) => { return(new ItemLayout(50, 50, (v as ItemLayout).ItemData) .AddMainImage() .AddExpirationMark() .AddTitle() .AddInfoIcon()); }; partialUnplacedGrid = GridManager.ConstrainGrid(GridManager.GetGrid(ContentManager.unplacedGridName), directGridFootIndex, directGridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true); addView = new AddView(LocalStorageController.AddItem, FireBaseController.SaveItem, storageName, true, partialUnplacedGrid); // title grid var titleGrid = new TopPage(_storageName, () => { foreach (ItemLayout child in partialUnplacedGrid.Children) { child.iconImage.RemoveEffect(typeof(ScreenTouch)); } foreach (StorageCell child in ContentManager.GetSelectedStorage(storageName).GetGridCells()) { child.GetButton().RemoveEffect(typeof(ImageTint)); } GridManager.RemoveGrid(ContentManager.pUnplacedGridName); }).GetGrid(); gridFootIndex = directGridFootIndex; var gridPageSelectGrid = new Grid() { Margin = new Thickness(grid_margin, 0), ColumnDefinitions = { new ColumnDefinition() { Width = 50 }, new ColumnDefinition() { Width = 30 }, new ColumnDefinition() { Width = 30 }, new ColumnDefinition() { Width = GridLength.Auto } } }; var nextPage = new ImageButton() { Source = ContentManager.countIcon }; nextPage.Clicked += (obj, args) => { Console.WriteLine("CabinetAddPage grid foot index " + gridFootIndex); gridFootIndex += 7; partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true); }; var lastPage = new ImageButton() { Source = ContentManager.countIcon, Rotation = 180 }; lastPage.Clicked += (obj, args) => { Console.WriteLine("CabinetAddPage grid foot index " + gridFootIndex); gridFootIndex = gridFootIndex - 7 < 0 ? 0 : gridFootIndex - 7; partialUnplacedGrid = GridManager.ConstrainGrid(unplacedGrid, gridFootIndex, gridFootIndex + 7, partialUnplacedGrid, itemLayoutCopier, true); }; var addNewButton = new ImageButton() { Source = ContentManager.addIcon, BackgroundColor = Color.Transparent }; addNewButton.Clicked += (obj, args) => { addView.ResetForm(); ContentManager.pageController.ToAddView(addView); }; var searchBar = new SearchBar() { Text = ContentManager.defaultSearchAllBarText, MinimumWidthRequest = 300 }; searchBar.Focused += (obj, args) => searchBar.Text = ""; searchBar.Unfocused += (obj, args) => { if (searchBar.Text.Length == 0) { searchBar.Text = ContentManager.defaultSearchAllBarText; } GridManager.FilterItemGrid(ContentManager.UnplacedItemBase.Values, partialUnplacedGrid, searchBar.Text); }; gridPageSelectGrid.Children.Add(lastPage, 1, 0); gridPageSelectGrid.Children.Add(nextPage, 2, 0); gridPageSelectGrid.Children.Add(addNewButton, 0, 0); gridPageSelectGrid.Children.Add(searchBar, 3, 0); pageContainer = new AbsoluteLayout(); pageContainer.BackgroundColor = ContentManager.ThemeColor; ContentManager.AddOnBackgroundChangeListener(c => pageContainer.BackgroundColor = c); pageContainer.Children.Add(titleGrid, new Rectangle(0, 0, 1, TopPage.top_bar_height_proportional), AbsoluteLayoutFlags.All); pageContainer.Children.Add(storageView, new Rectangle(1, 1, 1, .5), AbsoluteLayoutFlags.All); pageContainer.Children.Add(gridPageSelectGrid, new Rectangle(0, .12, 1, .09), AbsoluteLayoutFlags.All); pageContainer.Children.Add(partialUnplacedGrid, new Rectangle(0, .28, 1, .3), AbsoluteLayoutFlags.All); Content = new AbsoluteLayout() { Children = { pageContainer } }; AbsoluteLayout.SetLayoutBounds(pageContainer, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(pageContainer, AbsoluteLayoutFlags.All); }
protected override void OnDisappearing() { base.OnDisappearing(); GridManager.FilterItemGrid(ContentManager.MetaItemBase.Values, metaGrid, ""); }
// 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 } }; }