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 3 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 @@ -97,6 +97,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle

// Create Table view
mTableView = createTableView();
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.


if(paginationEnabled) {
mTableFilter = new Filter(mTableView); // Create an instance of a Filter and pass the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@

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;

/**
* Created by evrencoskun on 11/06/2017.
*/

public class Cell implements ISortableModel, IFilterableModel {
public class Cell implements ISortableModel, IFilterableModel, ISelectableModel {

private String mId;
private Object mData;
private String mFilterKeyword;
private AbstractViewHolder.SelectionState mSelectionState = AbstractViewHolder.SelectionState.UNSELECTED;

public Cell(String id) {
this.mId = id;
Expand Down Expand Up @@ -83,5 +86,15 @@ public void setFilterKeyword(String filterKeyword) {
public String getFilterableKeyword() {
return mFilterKeyword;
}

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

@Override
public void setSelectionState(AbstractViewHolder.SelectionState selectionState) {
mSelectionState = selectionState;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public interface ITableView {

boolean isSortable();

boolean isSelectable();

void setSelectable(boolean selectable);

CellRecyclerView getCellRecyclerView();

CellRecyclerView getColumnHeaderRecyclerView();
Expand Down
45 changes: 25 additions & 20 deletions tableview/src/main/java/com/evrencoskun/tableview/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -522,43 +533,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);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -304,4 +305,32 @@ public void addAdapterDataSetChangedListener(AdapterDataSetChangedListener liste

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) {
sonique6784 marked this conversation as resolved.
Show resolved Hide resolved
return mColumnHeaderItems.size();
}
return 0;
}

public int getRowHeaderItemCount() {
if( mRowHeaderItems != null) {
sonique6784 marked this conversation as resolved.
Show resolved Hide resolved
return mRowHeaderItems.size();
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void onBindRowHeaderViewHolder(AbstractViewHolder holder, Object rowHeaderItemMo

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 @@ -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());
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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;

import java.util.List;

Expand Down Expand Up @@ -62,6 +63,17 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, int xPosition
AbstractViewHolder viewHolder = (AbstractViewHolder) holder;
Object value = getItem(xPosition);

// 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.onBindCellViewHolder(viewHolder, value, xPosition, mYPosition);
}
}
Expand All @@ -81,7 +93,7 @@ public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
AbstractViewHolder viewHolder = (AbstractViewHolder) holder;

SelectionState selectionState = mTableAdapter.getTableView().getSelectionHandler()
.getCellSelectionState(holder.getAdapterPosition(), mYPosition);
.getSelectionStateCell(holder.getAdapterPosition(), mYPosition);

// Control to ignore selection color
if (!mTableAdapter.getTableView().isIgnoreSelectionColors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 @@ -56,6 +57,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());
final int color = mTableAdapter.getColorForSelection(((ISelectableModel) value).getSelectionState());
viewHolder.setBackgroundColor(color);
} else {
//TODO: trigger exception, if isSelectable, Cells MUST implements ISelectableModel
}
}

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

Expand All @@ -70,7 +82,7 @@ public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
AbstractViewHolder viewHolder = (AbstractViewHolder) holder;

SelectionState selectionState = mTableAdapter.getTableView().getSelectionHandler()
.getColumnSelectionState(viewHolder.getAdapterPosition());
.getSelectionStateColumnHeader(viewHolder.getAdapterPosition());

// Control to ignore selection color
if (!mTableAdapter.getTableView().isIgnoreSelectionColors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line

import java.util.List;

/**
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
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.
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line

public interface ISelectableModel {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 @NonNull/@Nullable, based on your needs.

AbstractViewHolder.SelectionState getSelectionState();
void setSelectionState(AbstractViewHolder.SelectionState selectionState);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add an empty line before the method

}
Loading