Esempio n. 1
0
        void FillCache()
        {
            ITableModel model        = Controller.Model;
            int         sectionCount = model.GetSectionCount();

            var newCellCache         = new List <Cell>();
            var newIsHeaderCache     = new List <bool>();
            var newNextIsHeaderCache = new List <bool>();

            for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++)
            {
                var sectionTitle     = model.GetSectionTitle(sectionIndex);
                var sectionTextColor = model.GetSectionTextColor(sectionIndex);
                var sectionRowCount  = model.GetRowCount(sectionIndex);

                if (!string.IsNullOrEmpty(sectionTitle))
                {
                    Cell headerCell = model.GetHeaderCell(sectionIndex);
                    if (headerCell == null)
                    {
                        headerCell = new TextCell {
                            Text = sectionTitle, TextColor = sectionTextColor
                        }
                    }
                    ;
                    headerCell.Parent = _view;

                    newIsHeaderCache.Add(true);
                    newNextIsHeaderCache.Add(sectionRowCount == 0 && sectionIndex < sectionCount - 1);
                    newCellCache.Add(headerCell);
                }

                for (int i = 0; i < sectionRowCount; i++)
                {
                    newIsHeaderCache.Add(false);
                    newNextIsHeaderCache.Add(i == sectionRowCount - 1 && sectionIndex < sectionCount - 1);
                    newCellCache.Add((Cell)model.GetItem(sectionIndex, i));
                }
            }

            _cellCache         = newCellCache.ToArray();
            _isHeaderCache     = newIsHeaderCache.ToArray();
            _nextIsHeaderCache = newNextIsHeaderCache.ToArray();
        }

        void InvalidateCellCache()
        {
            _cellCache         = null;
            _isHeaderCache     = null;
            _nextIsHeaderCache = null;
        }

        void OnModelChanged(object sender, EventArgs e)
        {
            InvalidateCellCache();
            NotifyDataSetChanged();
        }
Esempio n. 2
0
        Cell GetCellForPosition(int position, out bool isHeader, out bool nextIsHeader)
        {
            isHeader     = false;
            nextIsHeader = false;

            ITableModel model        = Controller.Model;
            int         sectionCount = model.GetSectionCount();

            for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++)
            {
                int size = model.GetRowCount(sectionIndex) + 1;

                if (position == 0)
                {
                    isHeader     = true;
                    nextIsHeader = size == 0 && sectionIndex < sectionCount - 1;

                    Cell header = model.GetHeaderCell(sectionIndex);

                    Cell resultCell = null;
                    if (header != null)
                    {
                        resultCell = header;
                    }

                    if (resultCell == null)
                    {
                        resultCell = new TextCell {
                            Text = model.GetSectionTitle(sectionIndex)
                        }
                    }
                    ;

                    resultCell.Parent = _view;

                    return(resultCell);
                }

                if (position < size)
                {
                    nextIsHeader = position == size - 1;
                    return((Cell)model.GetItem(sectionIndex, position - 1));
                }

                position -= size;
            }

            return(null);
        }
    }