From 4e6841e7b5c300fc9dfb5c7a127f6eb326cf6a9b Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Tue, 24 Mar 2020 17:21:28 +0800 Subject: [PATCH] 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 --- .../contextualcards/ContextualCardManager.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java index 9beb624cb86..0931a8083d8 100644 --- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java @@ -169,16 +169,23 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo @VisibleForTesting List sortCards(List cards) { - //take mContextualCards as the source and do the ranking based on the rule. - return cards.stream() + // take mContextualCards as the source and do the ranking based on the rule. + final List result = cards.stream() .sorted((c1, c2) -> Double.compare(c2.getRankingScore(), c1.getRankingScore())) .collect(Collectors.toList()); + final List 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 public void onContextualCardUpdated(Map> updateList) { final Set cardTypes = updateList.keySet(); - //Remove the existing data that matches the certain cardType before inserting new data. + // Remove the existing data that matches the certain cardType before inserting new data. List cardsToKeep; // We are not sure how many card types will be in the database, so when the list coming