-
-
Notifications
You must be signed in to change notification settings - Fork 458
Feature/multi selection support + selection handler refacoring #50
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
base: master
Are you sure you want to change the base?
Changes from 10 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 |
|---|---|---|
|
|
@@ -45,6 +45,11 @@ You can check new implementations of TableView on the [release page](https://git | |
| - [1. ISortableModel to your Cell Model](#1-isortablemodel-to-your-cell-model) | ||
| - [2. AbstractSorterViewHolder to your Column Header ViewHolder](#2-abstractsorterviewholder-to-your-column-header-viewholder) | ||
| - [3. Helper methods for sorting process](#3-helper-methods-for-sorting-process) | ||
| - [Selecting](#selecting) | ||
| - [1. Implements ISelectable to your Cell Model](#1-implements-iselectable-to-your-cell-model) | ||
| - [2. Enable selection on the TableView](#2-enable-selection-on-the-tableview) | ||
| - [3. Multi-selection and Shadows](#3-multi-selection-and-shadows) | ||
| - [4. Customize selection colors](#4-customize-selection-colors) | ||
| - [Filtering](#filtering) | ||
| - [Steps to implement filtering functionality into TableView](#steps-to-implement-filtering-functionality-into-tableview) | ||
| - [Filtering notes](#filtering-notes) | ||
|
|
@@ -833,7 +838,6 @@ As of version **0.8.5.1**, TableView has some helper functions to change desired | |
| ```java | ||
| changeRowHeaderItemRange(int rowPositionStart, List<YourRowHeaderModel> rowHeaderModelList) | ||
| ``` | ||
|
|
||
| - To **update a cell item**: | ||
| ```java | ||
| changeCellItem(int columnPosition, int rowPosition, YourCellItemModel cellModel) | ||
|
|
@@ -851,6 +855,78 @@ As of version **0.8.5.1**, TableView has some helper functions to change desired | |
|
|
||
| *Note:*[TableViewSample 2 app](https://github.com/evrencoskun/TableViewSample2) also shows usage of these helper methods. | ||
|
|
||
|
|
||
| ## Selecting | ||
|
|
||
| ### 1. Implements ISelectable to your Cell Model | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To be able use this feature on your TableView. You have to implement ISelectableModel to your Cell Model. This interface | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wants two methods from your cell model. These are ; | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - ```java SelectionState getSelectionState()``` : To get current selection state for this Cell | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - ```java SelectionState setSelectionState()``` : To set current selection state for this Cell | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Note: Make sure you return a default SelectionState value (UNSELECTED) when calling ```getSelectionState()``` | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| As you seen getSelectionState value returns SelectionState. TableView controls the style regarding this state. | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Their are three states; | ||
|
|
||
| ```java | ||
| /** | ||
| * Enumeration value indicating the item is selected. | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * <code>SELECTED</code>. | ||
| */ | ||
| SELECTED, | ||
|
|
||
| /** | ||
| * Enumeration value indicating the item is selected. | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * <code>UNSELECTED</code>. | ||
| */ | ||
| UNSELECTED, | ||
|
|
||
| /** | ||
| * Enumeration value indicating the item is shadowed. | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * <code>SHADOWED</code>. | ||
| */ | ||
| SHADOWED | ||
| ``` | ||
|
|
||
| ### 2. Enable selection on the TableView | ||
|
|
||
| To enable selection, you have to enable selection for the TableView | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```java | ||
| mTableView.setSelectable(true); | ||
| ``` | ||
|
|
||
| ### 3. Multi-selection and Shadows | ||
|
|
||
| You can enable multi-selection thanks to the SelectionHandler: | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```java | ||
| mTableView.getSelectionHandler().setMultiSelectionEnabled(true); | ||
| ``` | ||
|
|
||
| You can also enable/disable Shadows thanks to the SelectionHandler: | ||
|
|
||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```java | ||
| mTableView.getSelectionHandler().setShadowEnabled(true); | ||
| ``` | ||
|
|
||
| ### 4. Customize selection colors | ||
|
|
||
| You can customize selection colors easily in your layout: | ||
| ```xml | ||
|
|
||
|
||
| <com.evrencoskun.tableview.TableView | ||
| android:id="@+id/table_view" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
|
|
||
|
||
| app:selected_color="@color/tableview_selected_background_color" | ||
| app:shadow_color="@color/tableview_shadow_background_color" | ||
| app:unselected_color="@color/tableview_unselected_background_color" | ||
| /> | ||
| ``` | ||
|
|
||
| ## Hiding & Showing the Row | ||
|
|
||
| With 0.8.5.1 version, hiding and showing any of row is pretty easy for TableView. For that several helper methods have been inserted on TableView. | ||
|
|
@@ -928,6 +1004,11 @@ With 0.8.5.5 version, hiding and showing any of column is pretty easy for TableV | |
| tableView.setIgnoreSelectionColors(false); | ||
| ``` | ||
|
|
||
| - To enable selection, the below line can be used. You will need to implement ISelectable in your Cell | ||
| ```java | ||
| tableView.setSelectable(true); | ||
| ``` | ||
|
|
||
| - To show or hide separators of the TableView, you can simply use these helper methods. | ||
|
|
||
| ```java | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,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); | ||
|
|
@@ -350,6 +351,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; | ||
| } | ||
|
|
@@ -541,42 +552,37 @@ public boolean isRowVisible(int row) { | |
| return mVisibilityHandler.isRowVisible(row); | ||
| } | ||
|
|
||
|
|
||
|
Contributor
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 extra lines |
||
|
|
||
| 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 | ||
|
Contributor
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 | ||
|
Contributor
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 |
|---|---|---|
|
|
@@ -124,29 +124,6 @@ public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { | |
| .scrollToPositionWithOffset(mHorizontalListener.getScrollPosition(), | ||
| mHorizontalListener.getScrollPositionOffset()); | ||
|
|
||
| SelectionHandler selectionHandler = mTableAdapter.getTableView().getSelectionHandler(); | ||
|
|
||
| if (selectionHandler.isAnyColumnSelected()) { | ||
|
|
||
| AbstractViewHolder cellViewHolder = (AbstractViewHolder) ((CellRowViewHolder) holder) | ||
| .m_jRecyclerView.findViewHolderForAdapterPosition(selectionHandler | ||
| .getSelectedColumnPosition()); | ||
|
|
||
| if (cellViewHolder != null) { | ||
| // Control to ignore selection color | ||
| if (!mTableAdapter.getTableView().isIgnoreSelectionColors()) { | ||
| cellViewHolder.setBackgroundColor(mTableAdapter.getTableView() | ||
| .getSelectedColor()); | ||
| } | ||
| cellViewHolder.setSelected(SelectionState.SELECTED); | ||
|
|
||
| } | ||
| } else if (selectionHandler.isRowSelected(holder.getAdapterPosition())) { | ||
|
|
||
| viewHolder.m_jRecyclerView.setSelected(SelectionState.SELECTED, mTableAdapter | ||
| .getTableView().getSelectedColor(), mTableAdapter.getTableView() | ||
| .isIgnoreSelectionColors()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -195,6 +172,27 @@ public void notifyCellDataSetChanged() { | |
| } | ||
|
|
||
|
|
||
| public C getItem(int rowPosition, int columnPosition) { | ||
sonique6784 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(mItemList.size() > rowPosition) { | ||
sonique6784 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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<>(); | ||
|
Contributor
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. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.