-
-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/multi selection support + selection handler refacoring #50
base: master
Are you sure you want to change the base?
Changes from all commits
3389d35
3681353
de59225
543ccea
4d1c793
b881d10
ae904be
34146fe
8e44ed5
3086446
2b422f9
3ac2e60
b8453f8
9819d32
0d3324d
fa50f50
d158ae0
6c62048
c51b947
0167dc6
33d3390
2dc2536
061a0b6
dee42fc
444e818
af08feb
2aa6ccf
5b2da94
17a979c
953bcdb
3b38b45
52f82d3
7897321
144735d
2aa73c2
d040d9e
bfa7bdd
96891c7
b4fdb2a
018adab
4d0f21c
1418049
0d09418
2020576
4b327cf
e11508d
004aab9
5c3b986
07d5a33
f17cfb0
fc4b497
55c41d1
03c0864
52f89ae
21aa792
19c494a
166f548
c45f165
6f4b3e8
a68a02f
6d0fd2a
b4f7bb0
a5e94d4
52b02ee
7b05330
35ef9dd
a76c444
1be6e29
e81973a
85cc3cb
b62bf0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,7 @@ public class TableView extends FrameLayout implements ITableView { | |
private boolean mAllowClickInsideRowHeader = false; | ||
private boolean mAllowClickInsideColumnHeader = false; | ||
private boolean mIsSortable; | ||
private boolean mIsSelectable; | ||
|
||
public TableView(@NonNull Context context) { | ||
super(context); | ||
|
@@ -378,6 +379,16 @@ public boolean isSortable() { | |
return mIsSortable; | ||
} | ||
|
||
@Override | ||
public boolean isSelectable() { | ||
return mIsSelectable; | ||
} | ||
|
||
@Override | ||
public void setSelectable(boolean selectable) { | ||
mIsSelectable = selectable; | ||
} | ||
|
||
public void setShowHorizontalSeparators(boolean showSeparators) { | ||
this.mShowHorizontalSeparators = showSeparators; | ||
} | ||
|
@@ -583,42 +594,37 @@ public boolean isRowVisible(int row) { | |
return mVisibilityHandler.isRowVisible(row); | ||
} | ||
|
||
|
||
|
||
public void setSelectedRow(int row) { | ||
mSelectionHandler.setSelectedRowPosition(row); | ||
} | ||
|
||
/** | ||
* Returns the index of the selected row, -1 if no row is selected. | ||
*/ | ||
public int getSelectedRow() { | ||
return mSelectionHandler.getSelectedRowPosition(); | ||
} | ||
|
||
public void setSelectedRow(int row) { | ||
// Find the row header view holder which is located on row position. | ||
AbstractViewHolder rowViewHolder = (AbstractViewHolder) getRowHeaderRecyclerView() | ||
.findViewHolderForAdapterPosition(row); | ||
|
||
|
||
mSelectionHandler.setSelectedRowPosition(rowViewHolder, row); | ||
//TODO: reuse logic in mSelectionHandler.rowHasItemSelected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
||
// to return list of selected rows | ||
return -1;//mSelectionHandler.getSelectedRowPosition(); | ||
} | ||
|
||
/** | ||
* Returns the index of the selected column, -1 if no column is selected. | ||
*/ | ||
public int getSelectedColumn() { | ||
return mSelectionHandler.getSelectedColumnPosition(); | ||
//TODO: reuse logic in mSelectionHandler.columnHasItemSelected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO |
||
// to return list of selected columns | ||
return -1; //mSelectionHandler.getSelectedColumnPosition(); | ||
} | ||
|
||
public void setSelectedColumn(int column) { | ||
// Find the column view holder which is located on column position . | ||
AbstractViewHolder columnViewHolder = (AbstractViewHolder) getColumnHeaderRecyclerView() | ||
.findViewHolderForAdapterPosition(column); | ||
|
||
mSelectionHandler.setSelectedColumnPosition(columnViewHolder, column); | ||
mSelectionHandler.setSelectedColumnPosition(column); | ||
} | ||
|
||
public void setSelectedCell(int column, int row) { | ||
// Find the cell view holder which is located on x,y (column,row) position. | ||
AbstractViewHolder cellViewHolder = getCellLayoutManager().getCellViewHolder(column, row); | ||
|
||
mSelectionHandler.setSelectedCellPositions(cellViewHolder, column, row); | ||
mSelectionHandler.setSelectedCellPositions(row, column); | ||
} | ||
|
||
@NonNull | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,25 +133,7 @@ public void onViewAttachedToWindow(@NonNull AbstractViewHolder holder) { | |
.scrollToPositionWithOffset(scrollHandler.getColumnPosition(), scrollHandler | ||
.getColumnPositionOffset()); | ||
|
||
SelectionHandler selectionHandler = mTableView.getSelectionHandler(); | ||
|
||
if (selectionHandler.isAnyColumnSelected()) { | ||
|
||
AbstractViewHolder cellViewHolder = (AbstractViewHolder) viewHolder.recyclerView | ||
.findViewHolderForAdapterPosition(selectionHandler.getSelectedColumnPosition()); | ||
|
||
if (cellViewHolder != null) { | ||
// Control to ignore selection color | ||
if (!mTableView.isIgnoreSelectionColors()) { | ||
cellViewHolder.setBackgroundColor(mTableView.getSelectedColor()); | ||
} | ||
cellViewHolder.setSelected(SelectionState.SELECTED); | ||
|
||
} | ||
} else if (selectionHandler.isRowSelected(holder.getAdapterPosition())) { | ||
selectionHandler.changeSelectionOfRecyclerView(viewHolder.recyclerView, | ||
SelectionState.SELECTED, mTableView.getSelectedColor()); | ||
} | ||
// TODO? | ||
|
||
} | ||
|
||
|
@@ -202,6 +184,28 @@ public void notifyCellDataSetChanged() { | |
} | ||
} | ||
|
||
@Nullable | ||
public C getItem(int rowPosition, int columnPosition) { | ||
sonique6784 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (mItemList.size() > rowPosition) { | ||
List<C> row = (List<C>) mItemList.get(rowPosition); | ||
if(row.size() > columnPosition) { | ||
return row.get(columnPosition); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* This method helps to get cell item model that is located on given row position. | ||
* | ||
* @param rowPosition | ||
*/ | ||
public List<C> getRowItems(int rowPosition) { | ||
List<C> cellItems = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seem to be unused |
||
|
||
return (List<C>) mItemList.get(rowPosition); | ||
} | ||
|
||
/** | ||
* This method helps to get cell item model that is located on given column position. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.evrencoskun.tableview.adapter.ITableAdapter; | ||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; | ||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder.SelectionState; | ||
import com.evrencoskun.tableview.handler.ISelectableModel; | ||
|
||
/** | ||
* Created by evrencoskun on 10/06/2017. | ||
|
@@ -52,8 +53,24 @@ public AbstractViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int view | |
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull final AbstractViewHolder holder, final int xPosition) { | ||
mTableAdapter.onBindCellViewHolder(holder, getItem(xPosition), xPosition, mYPosition); | ||
public void onBindViewHolder(@NonNull final AbstractViewHolder viewHolder, final int xPosition) { | ||
if (mTableAdapter != null) { | ||
Object value = getItem(xPosition); | ||
|
||
// Apply Selection Style | ||
if (mTableAdapter.getTableView().isSelectable()) { | ||
if (value instanceof ISelectableModel) { | ||
viewHolder.setSelected(((ISelectableModel) value).getSelectionState()); | ||
int color = mTableAdapter.getColorForSelection(((ISelectableModel) value).getSelectionState()); | ||
viewHolder.setBackgroundColor(color); | ||
} else if (value != null) { | ||
// trigger exception, if isSelectable, Cells MUST implements ISelectableModel | ||
throw new ClassCastException("Item at position (" + mYPosition + ", " + xPosition + ") must implement ISelectableModel to be selectable."); | ||
} | ||
} | ||
|
||
mTableAdapter.onBindCellViewHolder(viewHolder, value, xPosition, mYPosition); | ||
} | ||
} | ||
|
||
public int getYPosition() { | ||
|
@@ -73,22 +90,23 @@ public int getItemViewType(int position) { | |
public void onViewAttachedToWindow(@NonNull AbstractViewHolder viewHolder) { | ||
super.onViewAttachedToWindow(viewHolder); | ||
|
||
SelectionState selectionState = mTableView.getSelectionHandler().getCellSelectionState | ||
(viewHolder.getAdapterPosition(), mYPosition); | ||
if (mTableAdapter.getTableView().isSelectable()) { | ||
SelectionState selectionState = mTableView.getSelectionHandler() | ||
.getCellSelectionState(viewHolder.getAdapterPosition(), mYPosition); | ||
|
||
// Control to ignore selection color | ||
if (!mTableView.isIgnoreSelectionColors()) { | ||
// Control to ignore selection color | ||
if (!mTableView.isIgnoreSelectionColors()) { | ||
|
||
// Change the background color of the view considering selected row/cell position. | ||
if (selectionState == SelectionState.SELECTED) { | ||
viewHolder.setBackgroundColor(mTableView.getSelectedColor()); | ||
} else { | ||
viewHolder.setBackgroundColor(mTableView.getUnSelectedColor()); | ||
// Change the background color of the view considering selected row/cell position. | ||
if (selectionState == SelectionState.SELECTED) { | ||
viewHolder.setBackgroundColor(mTableView.getSelectedColor()); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but shouldn't you explicitly handle the |
||
viewHolder.setBackgroundColor(mTableView.getUnSelectedColor()); | ||
} | ||
} | ||
// Change selection status | ||
viewHolder.setSelected(selectionState); | ||
} | ||
|
||
// Change selection status | ||
viewHolder.setSelected(selectionState); | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra lines