Make UI refresh when there is only one contextual card left.

After having card dismissal mechanism implemented, it is possible that
the card list loaded from the card loader will be empty (users may
dismiss all cards). When there is only one card remaining on the screen
and user dismiss it, the card should go away.

Fixes: 119580732
Test: robotest
Change-Id: I7ae3b03f16a0b8b009d8aa77811b5a6d39c359e7
This commit is contained in:
Emily Chuang
2018-11-15 09:55:06 +08:00
parent d103f8eb81
commit 9c52951ba6
2 changed files with 48 additions and 7 deletions

View File

@@ -62,10 +62,12 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
private static final int[] SETTINGS_CARDS =
{ContextualCard.CardType.CONDITIONAL, ContextualCard.CardType.LEGACY_SUGGESTION};
@VisibleForTesting
final List<ContextualCard> mContextualCards;
private final Context mContext;
private final ControllerRendererPool mControllerRendererPool;
private final Lifecycle mLifecycle;
private final List<ContextualCard> mContextualCards;
private final List<LifecycleObserver> mLifecycleObservers;
private ContextualCardUpdateListener mListener;
@@ -122,10 +124,23 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> updateList) {
final Set<Integer> cardTypes = updateList.keySet();
//Remove the existing data that matches the certain cardType before inserting new data.
final List<ContextualCard> cardsToKeep = mContextualCards
.stream()
.filter(card -> !cardTypes.contains(card.getCardType()))
.collect(Collectors.toList());
List<ContextualCard> cardsToKeep;
// We are not sure how many card types will be in the database, so when the list coming
// from the database is empty (e.g. no eligible cards/cards are dismissed), we cannot
// assign a specific card type for its map which is sending here. Thus, we assume that
// except Conditional cards, all other cards are from the database. So when the map sent
// here is empty, we only keep Conditional cards.
if (cardTypes.isEmpty()) {
cardsToKeep = mContextualCards.stream()
.filter(card -> card.getCardType() == ContextualCard.CardType.CONDITIONAL)
.collect(Collectors.toList());
} else {
cardsToKeep = mContextualCards.stream()
.filter(card -> !cardTypes.contains(card.getCardType()))
.collect(Collectors.toList());
}
final List<ContextualCard> allCards = new ArrayList<>();
allCards.addAll(cardsToKeep);
allCards.addAll(