Force the adapter to rebind cards with a toggle.

A card dismissal and scheduled card collection trigger a reload. During
card reloading, we perform slices pre check. The pre check goes through
the whole slice binding process, which means slices will be pinned and unpinned.
Hence, the on screen slices will gets unpinned resulting to the
unresponsive toggling.

As we have DiffCallbck implmented, if the card list are the same, then
bindView in the renderer will be ignored, which means the unpinned slice
will have no chance to re-register slice callback. So here we force it
to rebind the views.

Fixes: 123174237
Test: robotests
Change-Id: Id98bc16632bf024cbb611b40890e4d2629f08d7b
This commit is contained in:
Yi-Ling Chuang
2019-04-18 16:29:45 +08:00
parent 37db031aa1
commit acb50f2c6a
5 changed files with 236 additions and 2 deletions

View File

@@ -20,7 +20,6 @@ import androidx.recyclerview.widget.DiffUtil;
import java.util.List;
//TODO(b/117816826): add test cases for DiffUtil.
/**
* A DiffCallback to calculate the difference between old and new {@link ContextualCard} List.
*/
@@ -53,6 +52,11 @@ public class ContextualCardsDiffCallback extends DiffUtil.Callback {
@Override
public boolean areContentsTheSame(int oldCardPosition, int newCardPosition) {
// Slices with toggles needs to be updated continuously, which means their contents may
// change. So here we assume the content will always be different to force view rebinding.
if (mNewCards.get(newCardPosition).hasInlineAction()) {
return false;
}
return mOldCards.get(oldCardPosition).equals(mNewCards.get(newCardPosition));
}
}