Move sticky cards to the bottom

Sticky cards have higher scores and were on the top of homepage.

Bug: 149274976
Test: visual
Change-Id: I5fc2303ac42fff5bc4d44e355112ea4529253acd
This commit is contained in:
Jason Chiu
2020-03-24 17:21:28 +08:00
parent e4b0989766
commit 4e6841e7b5

View File

@@ -170,9 +170,16 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
@VisibleForTesting @VisibleForTesting
List<ContextualCard> sortCards(List<ContextualCard> cards) { List<ContextualCard> sortCards(List<ContextualCard> cards) {
// take mContextualCards as the source and do the ranking based on the rule. // take mContextualCards as the source and do the ranking based on the rule.
return cards.stream() final List<ContextualCard> result = cards.stream()
.sorted((c1, c2) -> Double.compare(c2.getRankingScore(), c1.getRankingScore())) .sorted((c1, c2) -> Double.compare(c2.getRankingScore(), c1.getRankingScore()))
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<ContextualCard> stickyCards = result.stream()
.filter(c -> c.getCategory() == STICKY_VALUE)
.collect(Collectors.toList());
// make sticky cards be at the tail end.
result.removeAll(stickyCards);
result.addAll(stickyCards);
return result;
} }
@Override @Override