Exemplo n.º 1
0
        private void SwapItems(IList <IRowHeader> oldRowHeader, IList <IRowHeader> newRowHeader,
                               IList <IList <ICell> > newColumnItems, SortState sortState)
        {
            // Set new items without calling notifyCellDataSetChanged method of CellRecyclerViewAdapter
            mRowHeaderRecyclerViewAdapter.SetItems(newRowHeader, !mEnableAnimation);
            mCellRecyclerViewAdapter.SetItems(newColumnItems, !mEnableAnimation);
            if (mEnableAnimation)
            {
                // Find the differences between old cell items and new items.
                RowHeaderSortCallback diffCallback = new RowHeaderSortCallback(oldRowHeader, newRowHeader);
                DiffUtil.DiffResult   diffResult   = DiffUtil.CalculateDiff(diffCallback);
                diffResult.DispatchUpdatesTo(mRowHeaderRecyclerViewAdapter);
                diffResult.DispatchUpdatesTo(mCellRecyclerViewAdapter);
            }

            foreach (ColumnSortStateChangedListener listener in columnSortStateChangedListeners)
            {
                listener.OnRowHeaderSortStatusChanged(sortState);
            }
        }
Exemplo n.º 2
0
        private void PaginateData()
        {
            int start;
            int end;

            currentPageCellData = new AList <IList <ICell> >();
            currentPageRowData  = new AList <IRowHeader>();
            // No pagination if itemsPerPage is 0, all data will be loaded into the TableView.
            if (itemsPerPage == 0)
            {
                foreach (var i in originalCellData)
                {
                    currentPageCellData.Add(i);
                }
                foreach (var i in originalRowData)
                {
                    currentPageRowData.Add(i);
                }
                pageCount = 1;
                start     = 0;
                end       = currentPageCellData.Count;
            }
            else
            {
                start = (currentPage * itemsPerPage) - itemsPerPage;
                end   = (currentPage * itemsPerPage) > originalCellData.Count
                    ? originalCellData.Count
                    : (currentPage * itemsPerPage);
                for (int x = start; x < end; x++)
                {
                    currentPageCellData.Add(originalCellData[x]);
                    currentPageRowData.Add(originalRowData[x]);
                }

                // Using ceiling to calculate number of pages, e.g. 103 items of 10 items per page
                // will result to 11 pages.
                pageCount = (int)Math.Ceiling((double)originalCellData.Count / itemsPerPage);
            }

            // Sets the paginated data to the TableView.
            mRowHeaderRecyclerViewAdapter.SetItems(currentPageRowData, true);
            mCellRecyclerViewAdapter.SetItems(currentPageCellData, true);
            // Dispatches TableView changes to Listener interface
            if (onTableViewPageTurnedListener != null)
            {
                onTableViewPageTurnedListener.OnPageTurned(currentPageCellData.Count, start, end - 1);
            }
        }
Exemplo n.º 3
0
        public virtual void Filter(Com.Evrencoskun.Tableview.Filter.Filter filter)
        {
            if (originalCellDataStore == null || originalRowDataStore == null)
            {
                return;
            }

            originalCellData = new AList <IList <ICell> >(originalCellDataStore);
            originalRowData  = new AList <IRowHeader>(originalRowDataStore);
            filteredCellList = new AList <IList <ICell> >();
            filteredRowList  = new AList <IRowHeader>();
            if (filter.GetFilterItems().Count == 0)
            {
                filteredCellList = new AList <IList <ICell> >(originalCellDataStore);
                filteredRowList  = new AList <IRowHeader>(originalRowDataStore);
                DispatchFilterClearedToListeners(originalCellDataStore, originalRowDataStore);
            }
            else
            {
                for (int x = 0; x < filter.GetFilterItems().Count;)
                {
                    FilterItem filterItem = filter.GetFilterItems()[x];
                    if (filterItem.GetFilterType().Equals(FilterType.All))
                    {
                        foreach (IList <ICell> itemsList in originalCellData)
                        {
                            foreach (ICell item in itemsList)
                            {
                                if (((IFilterableModel)item).GetFilterableKeyword().ToLower()
                                    .Contains(filterItem.GetFilter().ToLower()))
                                {
                                    filteredCellList.Add(itemsList);
                                    filteredRowList.Add(originalRowData[filteredCellList.IndexOf(itemsList)]);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (IList <ICell> itemsList in originalCellData)
                        {
                            if (((IFilterableModel)itemsList[filterItem.GetColumn()]).GetFilterableKeyword().ToLower()
                                .Contains(filterItem.GetFilter().ToLower()))
                            {
                                filteredCellList.Add(itemsList);
                                filteredRowList.Add(originalRowData[filteredCellList.IndexOf(itemsList)]);
                            }
                        }
                    }

                    // If this is the last filter to be processed, the filtered lists will not be cleared.
                    if (++x < filter.GetFilterItems().Count)
                    {
                        originalCellData = new AList <IList <ICell> >(filteredCellList);
                        originalRowData  = new AList <IRowHeader>(filteredRowList);
                        filteredCellList.Clear();
                        filteredRowList.Clear();
                    }
                }
            }

            // Sets the filtered data to the TableView.
            mRowHeaderRecyclerViewAdapter.SetItems(filteredRowList, true);
            mCellRecyclerViewAdapter.SetItems((IList <IList <ICell> >)filteredCellList, true);
            // Tells the listeners that the TableView is filtered.
            DispatchFilterChangedToListeners(filteredCellList, filteredRowList);
        }