-
-
Notifications
You must be signed in to change notification settings - Fork 458
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 3 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 |
---|---|---|
|
@@ -97,6 +97,7 @@ public class TableView extends FrameLayout implements ITableView { | |
private boolean mShowHorizontalSeparators = true; | ||
private boolean mShowVerticalSeparators = true; | ||
private boolean mIsSortable; | ||
private boolean mIsSelectable; | ||
|
||
public TableView(@NonNull Context context) { | ||
super(context); | ||
|
@@ -345,6 +346,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; | ||
} | ||
|
@@ -522,43 +533,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); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,10 @@ | |
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; | ||
import com.evrencoskun.tableview.sort.RowHeaderSortHelper; | ||
|
||
|
||
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. Remove empty line |
||
import java.util.List; | ||
|
||
/** | ||
|
@@ -53,6 +55,17 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | |
AbstractViewHolder viewHolder = (AbstractViewHolder) holder; | ||
Object value = getItem(position); | ||
|
||
// Apply Selection Style | ||
if(mTableAdapter.getTableView().isSelectable()) { | ||
sonique6784 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (value instanceof ISelectableModel) { | ||
viewHolder.setSelected(((ISelectableModel) value).getSelectionState()); | ||
int color = mTableAdapter.getColorForSelection(((ISelectableModel) value).getSelectionState()); | ||
viewHolder.setBackgroundColor(color); | ||
} else { | ||
//TODO: trigger exception, if isSelectable, Cells MUST implements ISelectableModel | ||
} | ||
} | ||
|
||
mTableAdapter.onBindRowHeaderViewHolder(viewHolder, value, position); | ||
} | ||
|
||
|
@@ -67,7 +80,7 @@ public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { | |
AbstractViewHolder viewHolder = (AbstractViewHolder) holder; | ||
|
||
SelectionState selectionState = mTableAdapter.getTableView().getSelectionHandler() | ||
.getRowSelectionState(holder.getAdapterPosition()); | ||
.getSelectionStateRowHeader(holder.getAdapterPosition()); | ||
|
||
|
||
// Control to ignore selection color | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.evrencoskun.tableview.handler; | ||
|
||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder; | ||
|
||
/** | ||
* Created by cedricferry on 8/2/18. | ||
*/ | ||
|
||
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. Remove empty line |
||
public interface ISelectableModel { | ||
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. If you can, it'd be nice to have the method of this interface annotated with |
||
AbstractViewHolder.SelectionState getSelectionState(); | ||
void setSelectionState(AbstractViewHolder.SelectionState selectionState); | ||
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. Add an empty line before the method |
||
} |
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