Esempio n. 1
0
        public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row)
        {
            var  sectionIndex       = 0;
            var  itemIndexInSection = (int)row;
            Cell cell;

            var isHeader = false;

            if (IsGroupingEnabled)
            {
                GetComputedIndexes(row, out sectionIndex, out itemIndexInSection, out isHeader);
            }

            var indexPath  = NSIndexPath.FromItemSection(itemIndexInSection, sectionIndex);
            var templateId = isHeader ? "headerCell" : TemplateIdForPath(indexPath).ToString();

            NSView nativeCell;

            var cachingStrategy = Controller.CachingStrategy;

            if (cachingStrategy == ListViewCachingStrategy.RetainElement)
            {
                cell       = GetCellForPath(indexPath, isHeader);
                nativeCell = CellNSView.GetNativeCell(tableView, cell, templateId, isHeader);
            }
            else if (cachingStrategy == ListViewCachingStrategy.RecycleElement)
            {
                nativeCell = tableView.MakeView(templateId, tableView);
                if (nativeCell == null)
                {
                    cell       = GetCellForPath(indexPath, isHeader);
                    nativeCell = CellNSView.GetNativeCell(tableView, cell, templateId, isHeader, true);
                }
                else
                {
                    var templatedList = TemplatedItemsView.TemplatedItems.GetGroup(sectionIndex);
                    cell = (Cell)((INativeElementView)nativeCell).Element;
                    ICellController controller = cell;
                    controller.SendDisappearing();
                    templatedList.UpdateContent(cell, itemIndexInSection);
                    controller.SendAppearing();
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(nativeCell);
        }
Esempio n. 2
0
            public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                UITableViewCell nativeCell = null;

                var cachingStrategy = Controller.CachingStrategy;

                if (cachingStrategy == ListViewCachingStrategy.RetainElement)
                {
                    var cell = GetCellForPath(indexPath);
                    nativeCell = CellTableViewCell.GetNativeCell(tableView, cell);
                }
                else if (cachingStrategy == ListViewCachingStrategy.RecycleElement)
                {
                    var id = TemplateIdForPath(indexPath);
                    nativeCell = tableView.DequeueReusableCell(ContextActionsCell.Key + id);
                    if (nativeCell == null)
                    {
                        var cell = GetCellForPath(indexPath);
                        nativeCell = CellTableViewCell.GetNativeCell(tableView, cell, true, id.ToString());
                    }
                    else
                    {
                        var             templatedList = TemplatedItemsView.TemplatedItems.GetGroup(indexPath.Section);
                        var             cell          = (Cell)((INativeElementView)nativeCell).Element;
                        ICellController controller    = cell;
                        controller.SendDisappearing();
                        templatedList.UpdateContent(cell, indexPath.Row);
                        controller.SendAppearing();
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }

                var bgColor = tableView.IndexPathForSelectedRow != null && tableView.IndexPathForSelectedRow.Equals(indexPath) ? UIColor.Clear : DefaultBackgroundColor;

                SetCellBackgroundColor(nativeCell, bgColor);

                return(nativeCell);
            }
Esempio n. 3
0
        public override AView GetView(int position, AView convertView, ViewGroup parent)
        {
            Cell cell = null;

            Performance.Start();

            ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy;
            var nextCellIsHeader = false;

            if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null)
            {
                if (_listView.IsGroupingEnabled)
                {
                    List <Cell> cells = GetCellsFromPosition(position, 2);
                    if (cells.Count > 0)
                    {
                        cell = cells[0];
                    }

                    if (cells.Count == 2)
                    {
                        nextCellIsHeader = cells[1].GetIsGroupHeader <ItemsView <Cell>, Cell>();
                    }
                }

                if (cell == null)
                {
                    cell = GetCellForPosition(position);
                    if (cell == null)
                    {
                        return(new AView(_context));
                    }
                }
            }

            var cellIsBeingReused = false;
            var layout            = convertView as ConditionalFocusLayout;

            if (layout != null)
            {
                cellIsBeingReused = true;
                convertView       = layout.GetChildAt(0);
            }
            else
            {
                layout = new ConditionalFocusLayout(_context)
                {
                    Orientation = Orientation.Vertical
                }
            };

            if (cachingStrategy == ListViewCachingStrategy.RecycleElement && convertView != null)
            {
                var boxedCell = convertView as INativeElementView;
                if (boxedCell == null)
                {
                    throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling.");
                }
                cell = (Cell)boxedCell.Element;

                // We are going to re-set the Platform here because in some cases (headers mostly) its possible this is unset and
                // when the binding context gets updated the measure passes will all fail. By applying this here the Update call
                // further down will result in correct layouts.
                cell.Platform = _listView.Platform;

                ICellController cellController = cell;
                cellController.SendDisappearing();

                int row            = position;
                var group          = 0;
                var templatedItems = TemplatedItemsView.TemplatedItems;
                if (_listView.IsGroupingEnabled)
                {
                    group = templatedItems.GetGroupIndexFromGlobal(position, out row);
                }

                var templatedList = templatedItems.GetGroup(group);

                if (_listView.IsGroupingEnabled)
                {
                    if (row == 0)
                    {
                        templatedList.UpdateHeader(cell, group);
                    }
                    else
                    {
                        templatedList.UpdateContent(cell, row - 1);
                    }
                }
                else
                {
                    templatedList.UpdateContent(cell, row);
                }

                cellController.SendAppearing();

                if (cell.BindingContext == ActionModeObject)
                {
                    ActionModeContext = cell;
                    ContextView       = layout;
                }

                if (ReferenceEquals(_listView.SelectedItem, cell.BindingContext))
                {
                    Select(_listView.IsGroupingEnabled ? row - 1 : row, layout);
                }
                else if (cell.BindingContext == ActionModeObject)
                {
                    SetSelectedBackground(layout, true);
                }
                else
                {
                    UnsetSelectedBackground(layout);
                }

                Performance.Stop();
                return(layout);
            }

            AView view = CellFactory.GetCell(cell, convertView, parent, _context, _listView);

            Performance.Start("AddView");

            if (cellIsBeingReused)
            {
                if (convertView != view)
                {
                    layout.RemoveViewAt(0);
                    layout.AddView(view, 0);
                }
            }
            else
            {
                layout.AddView(view, 0);
            }

            Performance.Stop("AddView");

            bool isHeader = cell.GetIsGroupHeader <ItemsView <Cell>, Cell>();

            AView bline;

            UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, layout, out bline);

            UpdateSeparatorColor(isHeader, bline);

            if ((bool)cell.GetValue(IsSelectedProperty))
            {
                Select(position, layout);
            }
            else
            {
                UnsetSelectedBackground(layout);
            }

            layout.ApplyTouchListenersToSpecialCells(cell);

            Performance.Stop();

            return(layout);
        }
Esempio n. 4
0
        public override AView GetView(int position, AView convertView, ViewGroup parent)
        {
            Cell cell = null;

            Performance.Start(out string reference);

            ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy;
            var nextCellIsHeader = false;

            if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null)
            {
                if (_listView.IsGroupingEnabled)
                {
                    List <Cell> cells = GetCellsFromPosition(position, 2);
                    if (cells.Count > 0)
                    {
                        cell = cells[0];
                    }

                    if (cells.Count == 2)
                    {
                        nextCellIsHeader = cells[1].GetIsGroupHeader <ItemsView <Cell>, Cell>();
                    }
                }

                if (cell == null)
                {
                    cell = GetCellForPosition(position);

                    if (cell == null)
                    {
                        Performance.Stop(reference);

                        return(new AView(_context));
                    }
                }
            }

            var cellIsBeingReused = false;
            var layout            = convertView as Handlers.Compatibility.ConditionalFocusLayout;

            if (layout != null)
            {
                cellIsBeingReused = true;
                convertView       = layout.GetChildAt(0);
            }
            else
            {
                layout = new Handlers.Compatibility.ConditionalFocusLayout(_context)
                {
                    Orientation = Orientation.Vertical
                };
                _layoutsCreated.Add(layout);
            }

            if (((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) && convertView != null)
            {
                var boxedCell = convertView as INativeElementView;
                if (boxedCell == null)
                {
                    throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling.");
                }
                cell = (Cell)boxedCell.Element;

                ICellController cellController = cell;
                cellController.SendDisappearing();

                int row            = position;
                var group          = 0;
                var templatedItems = TemplatedItemsView.TemplatedItems;
                if (_listView.IsGroupingEnabled)
                {
                    group = templatedItems.GetGroupIndexFromGlobal(position, out row);
                }

                var templatedList = templatedItems.GetGroup(group);

                if (_listView.IsGroupingEnabled)
                {
                    if (row == 0)
                    {
                        templatedList.UpdateHeader(cell, group);
                    }
                    else
                    {
                        templatedList.UpdateContent(cell, row - 1);
                    }
                }
                else
                {
                    templatedList.UpdateContent(cell, row);
                }

                cellController.SendAppearing();

                if (cell.BindingContext == ActionModeObject)
                {
                    ActionModeContext = cell;
                    ContextView       = layout;
                }

                if (ReferenceEquals(_listView.SelectedItem, cell.BindingContext))
                {
                    Select(_listView.IsGroupingEnabled ? row - 1 : row, layout);
                }
                else if (cell.BindingContext == ActionModeObject)
                {
                    SetSelectedBackground(layout, true);
                }
                else
                {
                    UnsetSelectedBackground(layout);
                }

                Performance.Stop(reference);
                return(layout);
            }

            AView view = CellFactory.GetCell(cell, convertView, parent, _context, _listView);

            Performance.Start(reference, "AddView");

            if (cellIsBeingReused)
            {
                if (convertView != view)
                {
                    layout.RemoveViewAt(0);
                    layout.AddView(view, 0);
                }
            }
            else
            {
                layout.AddView(view, 0);
            }

            Performance.Stop(reference, "AddView");

            bool isHeader = cell.GetIsGroupHeader <ItemsView <Cell>, Cell>();

            AView bline;

            bool isSeparatorVisible = _listView.SeparatorVisibility == SeparatorVisibility.Default;

            if (isSeparatorVisible)
            {
                UpdateSeparatorVisibility(cell, cellIsBeingReused, isHeader, nextCellIsHeader, isSeparatorVisible, layout, out bline);

                UpdateSeparatorColor(isHeader, bline);
            }
            else if (layout.ChildCount > 1)
            {
                layout.RemoveViewAt(1);
            }

            if ((bool)cell.GetValue(IsSelectedProperty))
            {
                Select(position, layout);
            }
            else
            {
                UnsetSelectedBackground(layout);
            }

            layout.ApplyTouchListenersToSpecialCells(cell);

            Performance.Stop(reference);

            return(layout);
        }
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            var         realPosition = GetRealPosition(position);
            ContentCell cell         = null;

            Performance.Start(out string reference);

            var container = holder.ItemView as ContentCellContainer;

            ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy;

            if (cachingStrategy == ListViewCachingStrategy.RetainElement || container.IsEmpty)
            {
                cell = (ContentCell)GetCellFromPosition(realPosition);
            }

            var cellIsBeingReused = false;

            if (container.ChildCount > 0)
            {
                cellIsBeingReused = true;
            }

            if (((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) && !container.IsEmpty)
            {
                var boxedCell = container as INativeElementView;
                if (boxedCell == null)
                {
                    throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling.");
                }
                cell = (ContentCell)boxedCell.Element;

                // We are going to re-set the Platform here because in some cases (headers mostly) its possible this is unset and
                // when the binding context gets updated the measure passes will all fail. By applying this here the Update call
                // further down will result in correct layouts.
                cell.Platform = _collectionView.Platform;

                ICellController cellController = cell;
                cellController.SendDisappearing();

                int row            = realPosition;
                var group          = 0;
                var templatedItems = TemplatedItemsView.TemplatedItems;
                if (_collectionView.IsGroupingEnabled)
                {
                    group = templatedItems.GetGroupIndexFromGlobal(realPosition, out row);
                    if (group < 0)
                    {
                        return;
                    }
                }
                var templatedList = templatedItems.GetGroup(group);

                if (_collectionView.IsGroupingEnabled)
                {
                    if (row == 0)
                    {
                        templatedList.UpdateHeader(cell, group);
                    }
                    else
                    {
                        templatedList.UpdateContent(cell, row - 1);
                    }
                }
                else
                {
                    templatedList.UpdateContent(cell, row);
                }

                cellController.SendAppearing();

                Performance.Stop(reference);

                _recyclerView.RequestLayout();
                _recyclerView.Invalidate();

                return;
            }

            if (cell == null)
            {
                return;
            }

            AView view = GetCell(cell, container, _recyclerView, _context, _collectionView);


            Performance.Start(reference, "AddView");

            if (cellIsBeingReused)
            {
                if (container != view)
                {
                    holder.ItemView = view;
                }
            }
            else
            {
                holder.ItemView = view;
            }


            Performance.Stop(reference, "AddView");


            Performance.Stop(reference);
        }