Skip to content

Commit

Permalink
Fixed #594 - Updating sticky header checks same item view type and in…
Browse files Browse the repository at this point in the history
…creased delay to 100ms, giving more time to the LayoutManager computation.
  • Loading branch information
davideas committed Apr 29, 2018
1 parent cdc9f78 commit 70c88d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ public int expand(T item) {

/**
* Convenience method to initially expand a single item. Parent won't be notified.
* <p><b>Note:</b> Must be used in combination with adding new items that require to be
* <p><b>Note:</b> Must be used in combination when adding new items, those require to be
* initially expanded.</p>
* <b>WARNING!</b>
* <br>Expanded status is ignored if {@code init = true}: it will always attempt to expand
Expand Down Expand Up @@ -2550,7 +2550,7 @@ private int expand(int position, boolean expandAll, boolean init, boolean notify

IExpandable expandable = (IExpandable) item;
if (!hasSubItems(expandable)) {
expandable.setExpanded(false);//clear the expanded flag
expandable.setExpanded(false); // Clear the expanded flag
log.w("No subItems to Expand on position %s expanded %s", position, expandable.isExpanded());
return 0;
}
Expand Down Expand Up @@ -4452,7 +4452,7 @@ public long getTime() {
private void initializeItemTouchHelper() {
if (mItemTouchHelper == null) {
if (mRecyclerView == null) {
throw new IllegalStateException("RecyclerView cannot be null. Enabling LongPressDrag or Swipe must be done after the Adapter is added to the RecyclerView.");
throw new IllegalStateException("RecyclerView cannot be null. Enabling LongPressDrag or Swipe must be done after the Adapter has been attached to the RecyclerView.");
}
if (mItemTouchHelperCallback == null) {
mItemTouchHelperCallback = new ItemTouchHelperCallback(this);
Expand Down Expand Up @@ -4520,10 +4520,11 @@ public final boolean isLongPressDragEnabled() {
}

/**
* Enable / Disable the Drag on LongPress on the entire ViewHolder.
* Enables / Disables the drag of the item when long-press the entire itemView.
* <p><b>Note:</b> This will skip LongClick on the view in order to handle the LongPress,
* however the LongClick listener will be called if necessary in the new
* {@link FlexibleViewHolder#onActionStateChanged(int, int)}.</p>
* Requires the Adapter being attached to the RecyclerView.
* Default value is {@code false}.
*
* @param longPressDragEnabled true to activate, false otherwise
Expand Down Expand Up @@ -4553,7 +4554,8 @@ public final boolean isHandleDragEnabled() {
}

/**
* Enable / Disable the drag of the itemView with a handle view.
* Enables / Disables the drag of the item with a handle view.
* Requires the Adapter being attached to the RecyclerView.
* <p>Default value is {@code false}.</p>
*
* @param handleDragEnabled true to activate, false otherwise
Expand Down Expand Up @@ -4582,8 +4584,12 @@ public final boolean isSwipeEnabled() {
}

/**
* Enable the Full Swipe of the items.
* <p>Default value is {@code false}.</p>
* Enables full the swipe of the items.
* <p><b>Note:</b></p>
* <ul><li>Requires the Adapter being attached to the RecyclerView.</li>
* <li>Must override {@code getFrontView} and at least a rear View: {@code getRearLeftView} and/or
* {@code getRearRightView} in the {@code FlexibleViewHolder}.</li></ul>
* Default value is {@code false}.
*
* @param swipeEnabled true to activate, false otherwise
* @return this Adapter, so the call can be chained
Expand Down Expand Up @@ -5285,7 +5291,7 @@ private void updateStickyHeader(int positionStart) {
public void run() {
if (areHeadersSticky()) mStickyHeaderHelper.updateOrClearHeader(true);
}
}, 50L);
}, 100L);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import eu.davidea.flexibleadapter.utils.Log;
import eu.davidea.viewholders.FlexibleViewHolder;

import static eu.davidea.flexibleadapter.utils.LayoutUtils.getClassName;

/**
* A sticky header helper, to use only with {@link FlexibleAdapter}.
* <p>Header ViewHolders must be of type {@link FlexibleViewHolder}.</p>
Expand Down Expand Up @@ -159,13 +161,18 @@ private void updateHeader(int headerPosition, boolean updateHeaderContent) {
int oldHeaderPosition = mHeaderPosition;
mHeaderPosition = headerPosition;
FlexibleViewHolder holder = getHeaderViewHolder(headerPosition);
Log.d("swapHeader newHeaderPosition=%s", mHeaderPosition);
// Swapping header
swapHeader(holder, oldHeaderPosition);
} else if (updateHeaderContent) {
// #299 - ClassCastException after click on expanded sticky header when AutoCollapse is enabled
// mStickyHeaderViewHolder = getHeaderViewHolder(headerPosition);
// mStickyHeaderViewHolder.setBackupPosition(headerPosition);
mAdapter.onBindViewHolder(mStickyHeaderViewHolder, headerPosition);
// #299 - ClassCastException after click on expanded sticky header when auto-collapse is enabled.
// #594 - Checking same item view type and increased delay to 100ms.
if (mStickyHeaderViewHolder.getItemViewType() == mAdapter.getItemViewType(headerPosition)) {
mAdapter.onBindViewHolder(mStickyHeaderViewHolder, headerPosition);
} else {
Log.e("updateHeader Wrong itemViewType for StickyViewHolder=%s, PositionViewHolder=%s",
getClassName(mStickyHeaderViewHolder),
getClassName(getHeaderViewHolder(headerPosition)));
}
ensureHeaderParent();
}
translateHeader();
Expand Down Expand Up @@ -233,6 +240,7 @@ private void translateHeader() {
}

private void swapHeader(FlexibleViewHolder newHeader, int oldHeaderPosition) {
Log.d("swapHeader newHeaderPosition=%s", mHeaderPosition);
if (mStickyHeaderViewHolder != null) {
resetHeader(mStickyHeaderViewHolder);
// #568, #575 - Header ViewHolder out of the top screen must be recycled manually
Expand Down

0 comments on commit 70c88d6

Please sign in to comment.