Skip to content
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

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3389d35
refactored SelectionHandler
Feb 12, 2018
3681353
Merge branch 'master' into feature/multiSelectionSupport
Feb 12, 2018
de59225
re-enabled enableShadow with new SelectionHandler implementation
Feb 12, 2018
543ccea
Merge branch 'master' into feature/multiSelectionSupport
Feb 12, 2018
4d1c793
check if table isSelectable before accessing SelectionState
Feb 12, 2018
b881d10
added Selecting section
Feb 13, 2018
ae904be
used the RecyclerViewAdapters instead of the main dataset so it preve…
Feb 13, 2018
34146fe
added exception when TableView isSelectable and ISelectable is not im…
Feb 13, 2018
8e44ed5
Merge branch 'master' into feature/multiSelectionSupport
sonique6784 Feb 13, 2018
3086446
Merge branch 'master' into feature/multiSelectionSupport
sonique6784 Mar 6, 2018
2b422f9
Merge pull request #10 from evrencoskun/master
sonique6784 Jul 16, 2018
3ac2e60
Update README.md
sonique6784 Apr 19, 2020
b8453f8
Update README.md
sonique6784 Apr 19, 2020
9819d32
Update README.md
sonique6784 Apr 19, 2020
0d3324d
Update README.md
sonique6784 Apr 19, 2020
fa50f50
Update Readme.md
sonique6784 Apr 19, 2020
d158ae0
Code formatting and minor copy updates
sonique6784 Apr 19, 2020
6c62048
moved the verticalScroll detection
sonique6784 Jul 17, 2018
c51b947
Handle case where item is null
andhie Sep 4, 2018
0167dc6
Invalidate layout managers cache when changing the table dataset
Sep 20, 2018
33d3390
Add documentation
Sep 20, 2018
2dc2536
Fix for issue #185
vicmns Nov 18, 2018
061a0b6
removed cached .idea
Jan 13, 2019
dee42fc
Create FUNDING.yml
evrencoskun Jun 2, 2019
444e818
Update dependencies
MGaetan89 Jun 5, 2019
af08feb
Migrate to AndroidX
MGaetan89 Jun 5, 2019
2aa6ccf
Annotate the 'tableview' module with `@NonNull` and `@Nullable` and f…
MGaetan89 Jun 9, 2019
5b2da94
Annotate the 'app' module with `@NonNull` and `@Nullable`
MGaetan89 Jun 9, 2019
17a979c
Remove unnecessary attributes in the manifest
swissquote-gmu Aug 29, 2019
953bcdb
Disable BuildConfig generation as they were not used
swissquote-gmu Aug 29, 2019
3b38b45
Update dependencies
swissquote-gmu Aug 29, 2019
52f82d3
Fix crash in sample app
swissquote-gmu Aug 29, 2019
7897321
Remove `Context` parameter from the `AbstractTableAdapter` constructor
swissquote-gmu Aug 29, 2019
144735d
Add a `ViewGroup parent` parameter to `ITableAdapter#onCreateCornerView`
swissquote-gmu Aug 29, 2019
2aa73c2
Use dp instead of px
swissquote-gmu Aug 29, 2019
d040d9e
Add a no-op implementation of `ITableViewListener`
swissquote-gmu Sep 2, 2019
bfa7bdd
Remove unused method in `TableViewUtils`
swissquote-gmu Sep 3, 2019
96891c7
Allow click inside cells. Configurable by xml attrs.
sgallego Sep 18, 2019
b4fdb2a
Update dependencies and minor improvements
MGaetan89 Oct 12, 2019
018adab
Fix Readme
MGaetan89 Oct 12, 2019
4d0f21c
Remove unused resources
MGaetan89 Oct 12, 2019
1418049
Fix width computation
swissquote-gmu Dec 5, 2019
0d09418
Update dependencies
swissquote-gmu Dec 5, 2019
2020576
Target Java 8
swissquote-gmu Dec 5, 2019
4b327cf
Remove unused exceptions
swissquote-gmu Dec 5, 2019
e11508d
Listener used to ignore click action and calling the long press actio…
evrencoskun Jan 6, 2020
004aab9
Use generics types in ITableAdapter contract
evrencoskun Jan 6, 2020
5c3b986
Updating Contributors
evrencoskun Jan 7, 2020
07d5a33
0.8.9 version has been released.
evrencoskun Jan 7, 2020
f17cfb0
0.8.9 version has been released.
evrencoskun Jan 7, 2020
fc4b497
Bug fix of #276
evrencoskun Jan 10, 2020
55c41d1
A sponsorship URL has been inserted.
evrencoskun Jan 15, 2020
03c0864
A sponsorship URL has been inserted.
evrencoskun Jan 15, 2020
52f89ae
Documentation has been moved to the wiki page.
evrencoskun Jan 15, 2020
21aa792
Documentation has been moved to the wiki page
evrencoskun Jan 15, 2020
19c494a
Patreon user name has been changed.
evrencoskun Jan 15, 2020
166f548
The DoubleClick events have been added.
evrencoskun Jan 15, 2020
c45f165
The DoubleClick events have been added.
evrencoskun Jan 22, 2020
6f4b3e8
getVisibilityHandler function has been added.
evrencoskun Jan 22, 2020
a68a02f
Xently-UI app has been added in the sample apps list.
evrencoskun Mar 29, 2020
6d0fd2a
Fix click listener setup in TableView
MGaetan89 Mar 29, 2020
b4f7bb0
Enable click events in sample app
MGaetan89 Mar 29, 2020
a5e94d4
Fix crash on double click on a cell
MGaetan89 Mar 29, 2020
52b02ee
Fix crash when calling hideColumn
MGaetan89 Mar 30, 2020
7b05330
#303 issue has been fixed.
evrencoskun Apr 4, 2020
35ef9dd
0.8.9.2 version has been released.
evrencoskun Apr 15, 2020
a76c444
0.8.9.2 version has been released.
evrencoskun Apr 15, 2020
1be6e29
License inconsistency, Update bintray-release info and Append license…
Apr 16, 2020
e81973a
Merge branch 'master' into feature/multiSelectionSupport
sonique6784 Apr 20, 2020
85cc3cb
Merge branch 'master' into feature/multiSelectionSupport
sonique6784 Apr 20, 2020
b62bf0a
Merge branch 'master' into feature/multiSelectionSupport
sonique6784 Apr 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

// Let's get TableView
mTableView = layout.findViewById(R.id.tableview);
mTableView.setSelectable(true);
mTableView.getSelectionHandler().setShadowEnabled(true);
mTableView.getSelectionHandler().setMultiSelectionEnabled(true);
mTableFilter = new Filter(mTableView); // Create an instance of a Filter and pass the
// created TableView.

initializeTableView();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package com.evrencoskun.tableviewsample.tableview.model;

import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
import com.evrencoskun.tableview.filter.IFilterableModel;
import com.evrencoskun.tableview.handler.ISelectableModel;
import com.evrencoskun.tableview.sort.ISortableModel;

import androidx.annotation.NonNull;
Expand All @@ -26,14 +28,14 @@
/**
* Created by evrencoskun on 11/06/2017.
*/

public class Cell implements ISortableModel, IFilterableModel {
public class Cell implements ISortableModel, IFilterableModel, ISelectableModel {
@NonNull
private String mId;
@Nullable
private Object mData;
@NonNull
private String mFilterKeyword;
private AbstractViewHolder.SelectionState mSelectionState = AbstractViewHolder.SelectionState.UNSELECTED;

public Cell(@NonNull String id, @Nullable Object data) {
this.mId = id;
Expand Down Expand Up @@ -75,4 +77,15 @@ public void setData(@Nullable Object data) {
public String getFilterableKeyword() {
return mFilterKeyword;
}

@Override
public AbstractViewHolder.SelectionState getSelectionState() {
return mSelectionState;
}

@NonNull
@Override
public void setSelectionState(AbstractViewHolder.SelectionState selectionState) {
mSelectionState = selectionState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public interface ITableView {

boolean isSortable();

boolean isSelectable();

void setSelectable(boolean selectable);

@NonNull
Context getContext();

Expand Down
44 changes: 25 additions & 19 deletions tableview/src/main/java/com/evrencoskun/tableview/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -583,42 +594,37 @@ public boolean isRowVisible(int row) {
return mVisibilityHandler.isRowVisible(row);
}


Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.evrencoskun.tableview.adapter.recyclerview.CellRecyclerViewAdapter;
import com.evrencoskun.tableview.adapter.recyclerview.ColumnHeaderRecyclerViewAdapter;
import com.evrencoskun.tableview.adapter.recyclerview.RowHeaderRecyclerViewAdapter;
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -346,4 +347,32 @@ public void addAdapterDataSetChangedListener(@NonNull AdapterDataSetChangedListe

dataSetChangedListeners.add(listener);
}

public boolean isSelectable(){
return mTableView.isSelectable();
}

public int getColorForSelection(AbstractViewHolder.SelectionState selectionState) {
switch (selectionState) {
case SELECTED:
return mTableView.getSelectedColor();
case SHADOWED:
return mTableView.getShadowColor();
}
return mTableView.getUnSelectedColor();
}

public int getColumnHeaderItemCount() {
if (mColumnHeaderItems != null) {
return mColumnHeaderItems.size();
}
return 0;
}

public int getRowHeaderItemCount() {
if (mRowHeaderItems != null) {
return mRowHeaderItems.size();
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public interface ITableAdapter<CH, RH, C> {

ITableView getTableView();

int getColorForSelection(AbstractViewHolder.SelectionState selectionState);

/**
* Sets the listener for changes of data set on the TableView.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?

}

Expand Down Expand Up @@ -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<>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() {
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but shouldn't you explicitly handle the UNSELECTED and SHADOWED state here?

viewHolder.setBackgroundColor(mTableView.getUnSelectedColor());
}
}
// Change selection status
viewHolder.setSelected(selectionState);
}

// Change selection status
viewHolder.setSelected(selectionState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.evrencoskun.tableview.adapter.ITableAdapter;
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
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.ColumnSortHelper;
import com.evrencoskun.tableview.sort.SortState;

Expand Down Expand Up @@ -57,8 +57,22 @@ public AbstractViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int view
}

@Override
public void onBindViewHolder(@NonNull AbstractViewHolder holder, int position) {
mTableAdapter.onBindColumnHeaderViewHolder(holder, getItem(position), position);
public void onBindViewHolder(@NonNull AbstractViewHolder viewHolder, int position) {
Object value = getItem(position);

// Apply Selection Style
if (mTableAdapter.getTableView().isSelectable()) {
if (value instanceof ISelectableModel) {
viewHolder.setSelected(((ISelectableModel) value).getSelectionState());
final 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 " + position + " must implement ISelectableModel to be selectable.");
}
}

mTableAdapter.onBindColumnHeaderViewHolder(viewHolder, value, position);
}

@Override
Expand All @@ -70,20 +84,19 @@ public int getItemViewType(int position) {
public void onViewAttachedToWindow(@NonNull AbstractViewHolder viewHolder) {
super.onViewAttachedToWindow(viewHolder);

SelectionState selectionState = mTableView.getSelectionHandler().getColumnSelectionState
(viewHolder.getAdapterPosition());
if (mTableAdapter.getTableView().isSelectable()) {
// Control to ignore selection color
if (!mTableView.isIgnoreSelectionColors()) {

// Control to ignore selection color
if (!mTableView.isIgnoreSelectionColors()) {
// Change background color of the view considering it's selected state
mTableView.getSelectionHandler()
.changeColumnBackgroundColorBySelectionStatus(viewHolder, viewHolder.getSelected());
}

// Change background color of the view considering it's selected state
mTableView.getSelectionHandler().changeColumnBackgroundColorBySelectionStatus
(viewHolder, selectionState);
// Change selection status
viewHolder.setSelected(viewHolder.getSelected());
}

// Change selection status
viewHolder.setSelected(selectionState);

// Control whether the TableView is sortable or not.
if (mTableView.isSortable()) {
if (viewHolder instanceof AbstractSorterViewHolder) {
Expand Down
Loading