From 2ba2e7a1448b7abada79cc5ba2086609c1548b1c Mon Sep 17 00:00:00 2001 From: evrencoskun Date: Sun, 11 Mar 2018 11:47:18 +0300 Subject: [PATCH] TableView has a new handler class to retain and restore TableView preferences like the scroll positions and the selected positions. --- .../com/evrencoskun/tableview/TableView.java | 71 +++---------------- .../AbstractRecyclerViewAdapter.java | 3 +- .../tableview/handler/VisibilityHandler.java | 16 +++++ 3 files changed, 27 insertions(+), 63 deletions(-) diff --git a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java index e7da7b81..4e7db3f2 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/TableView.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/TableView.java @@ -435,6 +435,7 @@ public void sortRowHeader(SortState sortState) { mColumnSortHandler.sortByRowHeader(sortState); } + @Override public void remeasureColumnWidth(int column) { // Remove calculated width value to be ready for recalculation. @@ -661,6 +662,7 @@ int getShadowColor() { /** * get row header width + * * @return size in pixel */ @Override @@ -670,12 +672,13 @@ public int getRowHeaderWidth() { /** * set RowHeaderWidth + * * @param rowHeaderWidth in pixel */ @Override public void setRowHeaderWidth(int rowHeaderWidth) { this.mRowHeaderWidth = rowHeaderWidth; - if(mRowHeaderRecyclerView != null) { + if (mRowHeaderRecyclerView != null) { // Update RowHeader layout width ViewGroup.LayoutParams layoutParams = mRowHeaderRecyclerView.getLayoutParams(); layoutParams.width = rowHeaderWidth; @@ -683,7 +686,7 @@ public void setRowHeaderWidth(int rowHeaderWidth) { mRowHeaderRecyclerView.requestLayout(); } - if(mColumnHeaderRecyclerView != null) { + if (mColumnHeaderRecyclerView != null) { // Update ColumnHeader left margin LayoutParams layoutParams = (LayoutParams) mColumnHeaderRecyclerView.getLayoutParams(); layoutParams.leftMargin = rowHeaderWidth; @@ -691,7 +694,7 @@ public void setRowHeaderWidth(int rowHeaderWidth) { mColumnHeaderRecyclerView.requestLayout(); } - if(mCellRecyclerView != null) { + if (mCellRecyclerView != null) { // Update Cells left margin LayoutParams layoutParams = (LayoutParams) mCellRecyclerView.getLayoutParams(); layoutParams.leftMargin = rowHeaderWidth; @@ -699,7 +702,7 @@ public void setRowHeaderWidth(int rowHeaderWidth) { mCellRecyclerView.requestLayout(); } - if(getAdapter() != null) { + if (getAdapter() != null) { // update CornerView size getAdapter().setRowHeaderWidth(rowHeaderWidth); } @@ -709,11 +712,8 @@ public void setRowHeaderWidth(int rowHeaderWidth) { @Override protected Parcelable onSaveInstanceState() { SavedState state = new SavedState(super.onSaveInstanceState()); + // Save all preferences of The TableView before the configuration changed. state.preferences = mPreferencesHandler.savePreferences(); - /*state.cell = getCellLayoutManager().onSaveInstanceState(); - state.row = getRowHeaderLayoutManager().onSaveInstanceState(); - state.column = getColumnHeaderLayoutManager().onSaveInstanceState(); - state.cellRow = getCellLayoutManager().onSaveInstanceStateForCellRow();*/ return state; } @@ -728,60 +728,7 @@ protected void onRestoreInstanceState(Parcelable state) { SavedState savedState = (SavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); + // Reload the preferences mPreferencesHandler.loadPreferences(savedState.preferences); - - /*getRowHeaderLayoutManager().onRestoreInstanceState(savedState.row); - getColumnHeaderLayoutManager().onRestoreInstanceState(savedState.column); - getCellLayoutManager().onRestoreInstanceState(savedState.cell); - getCellLayoutManager().onRestoreInstanceStateForCellRow(savedState.cellRow);*/ - - - //scrollTo(savedState.offsetX, savedState.offsetY); - //mScrollHandler.scrollToRowPosition(savedState.mRow); - //mScrollHandler.scrollToColumnPosition(savedState.mColumn); } - - /*static class SavedState extends View.BaseSavedState { - //public int mRow, mColumn; - public Parcelable cell; - public Parcelable column; - public Parcelable row; - public Parcelable[] cellRow; - //public SparseArray> mCellRowCachedWidthList; - //public SparseArray mColumnHeaderCachedWidthList; - - - public SavedState(Parcelable superState) { - super(superState); - } - - private SavedState(Parcel in) { - super(in); - cell = in.readParcelable(TableView.class.getClassLoader()); - column = in.readParcelable(TableView.class.getClassLoader()); - row = in.readParcelable(TableView.class.getClassLoader()); - //cellRow = in.readParcelableArray(TableView.class.getClassLoader()); - //mCellRowCachedWidthList = in.readSparseArray(TableView.class.getClassLoader()); - //mColumnHeaderCachedWidthList = in.readSparseArray(TableView.class.getClassLoader()); - } - - @Override - public void writeToParcel(Parcel out, int flags) { - super.writeToParcel(out, flags); - out.writeParcelable(cell, flags); - out.writeParcelable(column, flags); - out.writeParcelable(row, flags); - //out.writeParcelableArray(cellRow, flags); - //out.writeSparseArray(mCellRowCachedWidthList); - //out.writeSparseArray(mColumnHeaderCachedWidthList); - } - - public static final Parcelable.Creator CREATOR = new Parcelable - .Creator() { - public SavedState createFromParcel(Parcel in) { return new SavedState(in); } - - public SavedState[] newArray(int size) { return new SavedState[size]; } - }; - }*/ - } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java index b2165db2..0df0c60c 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/adapter/recyclerview/AbstractRecyclerViewAdapter.java @@ -88,11 +88,12 @@ public void deleteItem(int position) { } public void deleteItemRange(int positionStart, int itemCount) { - for (int i = positionStart; i < positionStart + itemCount + 1; i++) { + for (int i = positionStart + itemCount -1; i >= positionStart ; i--) { if (i != RecyclerView.NO_POSITION) { mItemList.remove(i); } } + notifyItemRangeRemoved(positionStart, itemCount); } diff --git a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java index 2ed3bb0e..bce5835b 100644 --- a/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java +++ b/tableview/src/main/java/com/evrencoskun/tableview/handler/VisibilityHandler.java @@ -199,4 +199,20 @@ private Column getColumnValueFromPosition(int column) { return new Column(column, columnHeaderModel, cellModelList); } + + public SparseArray getHideRowList() { + return mHideRowList; + } + + public SparseArray getHideColumnList() { + return mHideColumnList; + } + + public void setHideRowList(SparseArray rowList) { + this.mHideRowList = rowList; + } + + public void setHideColumnList(SparseArray columnList) { + this.mHideColumnList = columnList; + } }