Esempio n. 1
0
        /// <summary>
        /// Filters an ItemLayout grid by the name
        /// </summary>
        /// <param name="source">List with all its items with type ItemLayout.</param>
        /// <param name="output">Grid that will hold the filtered items, can be the same as source grid.</param>
        /// <param name="input">The name to search for</param>
        public static void FilterItemGrid(IEnumerable <ItemLayout> source, Grid output, string input)
        {
            List <View> results = new List <View>();

            foreach (var item in source)
            {
                var match = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    if (i < item.ItemData.Name.Length && string.Equals(input[i].ToString(), item.ItemData.Name[i].ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        match++;
                    }
                    else
                    {
                        match = 0; break;
                    }
                }
                if ((match > 0 && !output.Children.Contains(item)) || input == "" || input == ContentManager.defaultSearchAllBarText)
                {
                    ItemLayout itemLayoutInstance = new ItemLayout(item.Width, item.Height, item.ItemData)
                                                    .AddMainImage()
                                                    .AddExpirationMark()
                                                    .AddTitle()
                                                    .AddInfoIcon();

                    results.Add(itemLayoutInstance);
                }
            }

            AddGridItem(output, results, true);
        }
Esempio n. 2
0
        /// <summary>
        /// Update bounds in which TouchEffect is active
        /// </summary>
        /// <param name="view">View with TouchEffect attached</param>
        /// <param name="storageName">Name of storage the view belongs to</param>
        public static void UpdateScreenTouchBounds(ItemLayout view, string storageName, Action <string, ItemLayout, int> updateShelf)
        {
            var         tryEffect  = view.GetEffect(typeof(ScreenTouch)) as ScreenTouch;
            ScreenTouch touchEvent = new ScreenTouch()
            {
                ContactView = ContentManager.GetSelectedStorage(storageName)
            };

            touchEvent.OnTouchEvent += (obj, args) => OnScreenTouch(args, view, storageName, updateShelf);
            view.iconImage.AddEffect(touchEvent);
        }
Esempio n. 3
0
        /// <summary>
        /// Method to handle what occurs when TouchEffect is active
        /// </summary>
        /// <param name="args"></param>
        /// <param name="itemIcon"></param>
        /// <param name="currentStorageName"></param>
        /// <param name="item"></param>
        /// <param name="grid"></param>
        public static void OnScreenTouch(TouchActionEventArgs args, ItemLayout itemIcon, string currentStorageName, Action <string, ItemLayout, int> updateShelf)
        {
            var itemStorage = ContentManager.GetSelectedStorage(currentStorageName);

            itemIcon.TranslationY += args.Location.Y; itemIcon.TranslationX += args.Location.X;
            if (args.Type == TouchActionEventArgs.TouchActionType.Entered)
            {
                // re-adding the item to be at the front layer
                var pUnplacedGrid = GridManager.GetGrid(ContentManager.pUnplacedGridName);
                var index         = pUnplacedGrid.Children.IndexOf(itemIcon);
                GridManager.AddGridItemAtPosition(pUnplacedGrid, new List <View>()
                {
                    itemIcon
                }, new Vector2D <int>(index % 4, (int)(index / 4)));
            }
            if (args.Type == TouchActionEventArgs.TouchActionType.Released)
            {
                itemIcon.TranslationX = 0;
                itemIcon.TranslationY = 0;
            }


            if (args.IsInContact)
            {
                foreach (StorageCell cell in itemStorage.GetGridCells())
                {
                    cell.GetButton().RemoveEffect(typeof(ImageTint));
                }
                args.ContactView[0].AddEffect(new ImageTint()
                {
                    tint = ContentManager.button_tint_color, ImagePath = ContentManager.buttonTintImage
                });
                if (args.Type == TouchActionEventArgs.TouchActionType.Released)
                {
                    args.ContactView[0].RemoveEffect(typeof(ImageTint));

                    itemIcon.SetStoragePointer(ContentManager.GetStorageView);
                    updateShelf(currentStorageName, itemIcon, args.ContactIndex[0]);
                }
            }
            else if (args.ContactView != null)
            {
                args.ContactView[0].ToggleEffects(new ImageTint()
                {
                    tint = Color.FromRgba(100, 30, 30, 70), ImagePath = ContentManager.buttonTintImage
                }, null);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Set up cabinets when starting application. Must be called after LoadItems().
        /// </summary>
        /// <param name="cabinets">All cabinets.</param>
        /// <param name="storageCells">All storage cells.</param>
        /// <param name="items">All items.</param>
        public static void LoadCabinets(List <Cabinet> cabinets, List <StorageCell> storageCells, List <Item> items)
        {
            foreach (Cabinet cabinet in cabinets)
            {
                Console.WriteLine("Content Loader 58 cabinet ID = " + "[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" + cabinet.ID);
                ContentManager.CabinetMetaBase.Add(cabinet.Name, cabinet);
                // Set the cabinet's grid
                Grid cabinetGrid = new Grid()
                {
                    RowSpacing = 0, ColumnSpacing = 0
                };
                cabinet.SetCabinet(cabinet.Name, cabinetGrid, cabinet.ID);

                // Record cabinet ID
                IDGenerator.SkipID(ContentManager.cabinetEditIdGenerator, cabinet.ID);
                IDGenerator.InitializeIDGroup(cabinet.Name);

                foreach (StorageCell cell in storageCells)
                {
                    // Record cell ID.
                    IDGenerator.SkipID(ContentManager.storageCellIdGenerator, cell.MetaID);
                    // Check if cell belongs to the given cabinet
                    if (cell.StorageName == cabinet.Name)
                    {
                        IDGenerator.SkipID(cabinet.Name, cell.Index);
                        cell.SetStorageCell(new Vector2D <int>(cell.X, cell.Y), cell.Index, cell.StorageName, cabinetGrid, "", cell.ColumnSpan, cell.RowSpan);

                        Console.WriteLine("ContentLoader 78 cabinet name: " + cabinet.Name + " cell storage: " + cell.StorageName + " cell index: " + cell.Index);
                        // Add cell to storage children dictionary
                        cabinet.AddGridCell(cell.Index, cell);

                        List <View> cellChildren = new List <View>();
                        // Add items to gridcells
                        foreach (Item item in items)
                        {
                            //  Console.WriteLine("ContentLoader 78 item storage: " + item.StorageName);
                            // Check if item belongs to both the storage and the cell
                            if (item.StorageName == cabinet.Name && item.StorageCellIndex == cell.Index)
                            {
                                // Adds to the list of children, will be used to populate grid later.
                                ItemLayout itemLayout = new ItemLayout(ContentManager.item_layout_size, ContentManager.item_layout_size, item).AddMainImage()
                                                        .AddExpirationMark()
                                                        .AddTitle()
                                                        .AddInfoIcon();
                                cellChildren.Add(itemLayout);
                            }
                        }
                        cabinet.AddGridItems(cell.Index, cellChildren);

                        // set UI for each cell
                        Image background = new Image()
                        {
                            Source = ContentManager.cabinetCellIcon, Aspect = Aspect.Fill
                        };
                        ImageButton transparentButton = new ImageButton()
                        {
                            Source = ContentManager.transIcon, BackgroundColor = Color.Transparent, Aspect = Aspect.Fill
                        };
                        cabinet.AddGridCellUI(cell.Index, background, transparentButton);

                        // Set row and column span of cell
                        cell.SetRowSpan(cell.RowSpan);
                        cell.SetColumnSpan(cell.ColumnSpan);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Set up fridges when starting application. Must call after LoadItems().
        /// </summary>
        /// <param name="fridges"> List of all stored fridges</param>
        /// <param name="storageCells">List of all stored storage cells.</param>
        /// <param name="items">List of all stored items.</param>
        public static void LoadFridges(List <Fridge> fridges, List <StorageCell> storageCells, List <Item> items)
        {
            foreach (Fridge fridge in fridges)
            {
                ContentManager.FridgeMetaBase.Add(fridge.Name, fridge);
                // Set the cabinet's grid
                Grid fridgeMainGrid = new Grid()
                {
                    RowSpacing = 0, ColumnSpacing = 0
                };
                Grid fridgeLeftGrid = new Grid()
                {
                    RowSpacing = 0, ColumnSpacing = 0
                };
                Grid fridgeRightGrid = new Grid()
                {
                    RowSpacing = 0, ColumnSpacing = 0
                };
                fridge.SetFridge(fridge.Name, fridgeMainGrid, fridgeLeftGrid, fridgeRightGrid, fridge.ID);

                // Record cabinet ID
                IDGenerator.SkipID(ContentManager.fridgeEditIdGenerator, fridge.ID);
                IDGenerator.InitializeIDGroup(fridge.Name);

                foreach (StorageCell cell in storageCells)
                {
                    // Record cell ID.
                    IDGenerator.SkipID(ContentManager.storageCellIdGenerator, cell.MetaID);
                    // Check if cell belongs to the given cabinet
                    if (cell.StorageName == fridge.Name)
                    {
                        IDGenerator.SkipID(fridge.Name, cell.MetaID);
                        Grid cellParentGrid = cell.GridType == "Left" ? fridgeLeftGrid : cell.GridType == "Right" ? fridgeRightGrid : fridgeMainGrid;
                        cell.SetStorageCell(new Vector2D <int>(cell.X, cell.Y), cell.Index, cell.StorageName, cellParentGrid, cell.GridType, cell.ColumnSpan, cell.RowSpan);

                        // Add cell to storage children dictionary
                        fridge.AddGridCell(cell.Index, cell);

                        List <View> cellChildren = new List <View>();
                        // Add items to gridcells
                        foreach (Item item in items)
                        {
                            //  Console.WriteLine("ContentLoader 78 item storage: " + item.StorageName);
                            // Check if item belongs to both the storage and the cell
                            if (item.StorageName == fridge.Name && item.StorageCellIndex == cell.Index)
                            {
                                // Adds to the list of children, will be used to populate grid later.
                                ItemLayout itemLayout = new ItemLayout(100, ContentManager.item_layout_size, item).AddMainImage()
                                                        .AddExpirationMark()
                                                        .AddTitle()
                                                        .AddInfoIcon();
                                cellChildren.Add(itemLayout);
                            }
                        }
                        fridge.AddGridItems(cell.Index, cellChildren);

                        // set UI for each cell
                        Image background = new Image()
                        {
                            Source = ContentManager.fridgeIcon, Aspect = Aspect.Fill
                        };
                        ImageButton transparentButton = new ImageButton()
                        {
                            Source = ContentManager.transIcon, BackgroundColor = Color.Transparent, Aspect = Aspect.Fill
                        };
                        fridge.AddGridCellUI(cell.Index, background, transparentButton);

                        // Set row and column span of cell
                        cell.SetRowSpan(cell.RowSpan);
                        cell.SetColumnSpan(cell.ColumnSpan);
                    }
                }
            }
        }