Skip to content

Commit

Permalink
Fixed crash when clearing board and no headers were added for columns
Browse files Browse the repository at this point in the history
  • Loading branch information
woxblom committed Jul 2, 2018
1 parent 9810292 commit c055605
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions library/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.6.1
VERSION_CODE=48
VERSION_NAME=1.6.2
VERSION_CODE=49
GROUP=com.github.woxthebox

POM_DESCRIPTION=Drag and drop to re-order items in a list, grid or board.
Expand Down
24 changes: 20 additions & 4 deletions library/src/main/java/com/woxthebox/draglistview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ public View getHeaderView(int column) {
return mHeaders.get(column);
}

/**
* @return The index of the column with a specific header. If the header can't be found -1 is returned.
*/
public int getColumnOfHeader(View header) {
for (int i = 0; i < mHeaders.size(); i++) {
if (mHeaders.get(i) == header) {
return i;
}
}
return -1;
}

public void removeItem(int column, int row) {
if (!isDragging() && mLists.size() > column && mLists.get(column).getAdapter().getItemCount() > row) {
DragItemAdapter adapter = (DragItemAdapter) mLists.get(column).getAdapter();
Expand Down Expand Up @@ -646,7 +658,7 @@ public int getFocusedColumn() {
}

/**
* @param width the width of columns in both portrait and landscape. This must be called before {@link #addColumnList} is
* @param width the width of columns in both portrait and landscape. This must be called before {@link #addColumn} is
* called for the width to take effect.
*/
public void setColumnWidth(int width) {
Expand Down Expand Up @@ -897,10 +909,14 @@ public boolean isDragging() {
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT));
if (header != null) {
layout.addView(header);
mHeaders.add(header);
View columnHeader = header;
if (header == null) {
columnHeader = new View(getContext());
columnHeader.setVisibility(View.GONE);
}
layout.addView(columnHeader);
mHeaders.add(columnHeader);

layout.addView(recyclerView);

mLists.add(index, recyclerView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void addColumn() {
public void onClick(View v) {
long id = sCreatedItems++;
Pair item = new Pair<>(id, "Test " + id);
mBoardView.addItem(column, 0, item, true);
mBoardView.addItem(mBoardView.getColumnOfHeader(v), 0, item, true);
//mBoardView.moveItem(4, 0, 0, true);
//mBoardView.removeItem(column, 0);
//mBoardView.moveItem(0, 0, 1, 3, false);
Expand Down

0 comments on commit c055605

Please sign in to comment.