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

Set UNSELECTED_POSITION from SelectionHandler.unselectedCellView() #325

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -45,6 +45,8 @@ public interface ITableAdapter<CH, RH, C> {

void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable C cellItemModel, int columnPosition, int rowPosition);

void onRecycleCellViewHolder(@NonNull AbstractViewHolder holder);

@NonNull
AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public boolean onFailedToRecycleView(@NonNull AbstractViewHolder holder) {
@Override
public void onViewRecycled(@NonNull AbstractViewHolder holder) {
super.onViewRecycled(holder);
mTableAdapter.onRecycleCellViewHolder(holder);
holder.onViewRecycled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ private void unselectedCellView() {
AbstractViewHolder rowHeader = (AbstractViewHolder) mRowHeaderRecyclerView
.findViewHolderForAdapterPosition(mSelectedRowPosition);

// Clear selected row and column
mSelectedRowPosition = UNSELECTED_POSITION;
mSelectedColumnPosition = UNSELECTED_POSITION;

// If view is null, that means the row view holder was already recycled.
if (rowHeader != null) {
// Change color
Expand Down Expand Up @@ -238,6 +242,11 @@ private void unselectedColumnHeader() {
mTableView.getUnSelectedColor());
}

public boolean isAnyCellSelected() {
return (getSelectedColumnPosition() != SelectionHandler.UNSELECTED_POSITION &&
getSelectedRowPosition() != SelectionHandler.UNSELECTED_POSITION);
}

public boolean isCellSelected(int column, int row) {
return (getSelectedColumnPosition() == column && getSelectedRowPosition() == row) ||
isColumnSelected(column) || isRowSelected(row);
Expand Down Expand Up @@ -342,15 +351,17 @@ private void changeVisibleCellViewsBackgroundForColumn(int column, boolean isSel
CellRecyclerView cellRowRecyclerView = (CellRecyclerView) mCellLayoutManager
.findViewByPosition(i);

AbstractViewHolder holder = (AbstractViewHolder) cellRowRecyclerView
.findViewHolderForAdapterPosition(column);
if(cellRowRecyclerView!= null){
AbstractViewHolder holder = (AbstractViewHolder) cellRowRecyclerView
.findViewHolderForAdapterPosition(column);

if (holder != null) {
// Get each view container of the cell view and set unselected color.
holder.setBackgroundColor(backgroundColor);
if (holder != null) {
// Get each view container of the cell view and set unselected color.
holder.setBackgroundColor(backgroundColor);

// Change selection status of the view holder
holder.setSelected(selectionState);
// Change selection status of the view holder
holder.setSelected(selectionState);
}
}
}
}
Expand Down Expand Up @@ -406,9 +417,11 @@ public void changeSelectionOfRecyclerView(CellRecyclerView recyclerView, @NonNul
}

public void clearSelection() {
unselectedRowHeader();
unselectedCellView();
unselectedColumnHeader();
if(isAnyCellSelected()){
unselectedRowHeader();
unselectedCellView();
unselectedColumnHeader();
}
}

public void setSelectedRowPosition(int row) {
Expand Down