Merge "Build a way to decide card width"

This commit is contained in:
Mill Chen
2019-01-07 08:17:47 +00:00
committed by Android (Google) Code Review
4 changed files with 206 additions and 15 deletions

View File

@@ -107,12 +107,12 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>
}
}
}
return getFinalDisplayableCards(result);
return getDisplayableCards(result);
}
// Get final displayed cards and log what cards will be displayed/hidden
@VisibleForTesting
List<ContextualCard> getFinalDisplayableCards(List<ContextualCard> candidates) {
List<ContextualCard> getDisplayableCards(List<ContextualCard> candidates) {
final List<ContextualCard> eligibleCards = filterEligibleCards(candidates);
final List<ContextualCard> visibleCards = new ArrayList<>();
final List<ContextualCard> hiddenCards = new ArrayList<>();

View File

@@ -17,6 +17,7 @@
package com.android.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CARD_CONTENT_LOADER_ID;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.SUGGESTION_VALUE;
import static java.util.stream.Collectors.groupingBy;
@@ -172,7 +173,8 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
//replace with the new data
mContextualCards.clear();
mContextualCards.addAll(sortCards(allCards));
final List<ContextualCard> sortedCards = sortCards(allCards);
mContextualCards.addAll(assignCardWidth(sortedCards));
loadCardControllers();
@@ -224,6 +226,24 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
mListener = listener;
}
@VisibleForTesting
List<ContextualCard> assignCardWidth(List<ContextualCard> cards) {
final List<ContextualCard> result = new ArrayList<>(cards);
// Shows as half cards if 2 suggestion type of cards are next to each other.
// Shows as full card if 1 suggestion type of card lives alone.
for (int index = 1; index < result.size(); index++) {
final ContextualCard previous = result.get(index - 1);
final ContextualCard current = result.get(index);
if (current.getCategory() == SUGGESTION_VALUE
&& previous.getCategory() == SUGGESTION_VALUE) {
result.set(index - 1, previous.mutate().setIsHalfWidth(true).build());
result.set(index, current.mutate().setIsHalfWidth(true).build());
index++;
}
}
return result;
}
private List<ContextualCard> getCardsToKeep(List<ContextualCard> cards) {
if (mSavedCards != null) {
//screen rotate