Animate contextual cards in after loading.

After initial loading, all cards slide down per material guideline.

Test: visual
Change-Id: I115e086a43fc9a2d4b4da3acad20be689fdee09d
This commit is contained in:
Fan Zhang
2018-10-26 11:34:00 -07:00
parent 19e640701e
commit 444b5107e3
4 changed files with 76 additions and 1 deletions

View File

@@ -43,6 +43,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private final List<ContextualCard> mContextualCards;
private final LifecycleOwner mLifecycleOwner;
private RecyclerView mRecyclerView;
public ContextualCardsAdapter(Context context, LifecycleOwner lifecycleOwner,
ContextualCardManager manager) {
mContext = context;
@@ -89,6 +91,7 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
@@ -109,6 +112,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
@Override
public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards) {
final List<ContextualCard> contextualCards = cards.get(ContextualCard.CardType.DEFAULT);
final boolean previouslyEmpty = mContextualCards.isEmpty();
final boolean nowEmpty = contextualCards == null || contextualCards.isEmpty();
if (contextualCards == null) {
mContextualCards.clear();
notifyDataSetChanged();
@@ -119,5 +124,10 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
mContextualCards.addAll(contextualCards);
diffResult.dispatchUpdatesTo(this);
}
if (mRecyclerView != null && previouslyEmpty && !nowEmpty) {
// Adding items to empty list, should animate.
mRecyclerView.scheduleLayoutAnimation();
}
}
}