Skip to content

Commit

Permalink
TableView has a new handler class to retain and restore TableView pre…
Browse files Browse the repository at this point in the history
…ferences like the scroll positions and the selected positions.
  • Loading branch information
evrencoskun committed Mar 11, 2018
1 parent a602b14 commit 2ba2e7a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 63 deletions.
71 changes: 9 additions & 62 deletions tableview/src/main/java/com/evrencoskun/tableview/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -661,6 +662,7 @@ int getShadowColor() {

/**
* get row header width
*
* @return size in pixel
*/
@Override
Expand All @@ -670,36 +672,37 @@ 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;
mRowHeaderRecyclerView.setLayoutParams(layoutParams);
mRowHeaderRecyclerView.requestLayout();
}

if(mColumnHeaderRecyclerView != null) {
if (mColumnHeaderRecyclerView != null) {
// Update ColumnHeader left margin
LayoutParams layoutParams = (LayoutParams) mColumnHeaderRecyclerView.getLayoutParams();
layoutParams.leftMargin = rowHeaderWidth;
mColumnHeaderRecyclerView.setLayoutParams(layoutParams);
mColumnHeaderRecyclerView.requestLayout();
}

if(mCellRecyclerView != null) {
if (mCellRecyclerView != null) {
// Update Cells left margin
LayoutParams layoutParams = (LayoutParams) mCellRecyclerView.getLayoutParams();
layoutParams.leftMargin = rowHeaderWidth;
mCellRecyclerView.setLayoutParams(layoutParams);
mCellRecyclerView.requestLayout();
}

if(getAdapter() != null) {
if (getAdapter() != null) {
// update CornerView size
getAdapter().setRowHeaderWidth(rowHeaderWidth);
}
Expand All @@ -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;
}

Expand All @@ -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<SparseArray<Object>> mCellRowCachedWidthList;
//public SparseArray<Object> 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<SavedState> CREATOR = new Parcelable
.Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) { return new SavedState(in); }
public SavedState[] newArray(int size) { return new SavedState[size]; }
};
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,20 @@ private Column getColumnValueFromPosition(int column) {

return new Column(column, columnHeaderModel, cellModelList);
}

public SparseArray<Row> getHideRowList() {
return mHideRowList;
}

public SparseArray<Column> getHideColumnList() {
return mHideColumnList;
}

public void setHideRowList(SparseArray<Row> rowList) {
this.mHideRowList = rowList;
}

public void setHideColumnList(SparseArray<Column> columnList) {
this.mHideColumnList = columnList;
}
}

0 comments on commit 2ba2e7a

Please sign in to comment.