Merge "Sort contextual cards based on their score."

This commit is contained in:
TreeHugger Robot
2018-11-14 04:33:23 +00:00
committed by Android (Google) Code Review
5 changed files with 91 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ import android.widget.BaseAdapter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
@@ -109,9 +110,12 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
}
}
//TODO(b/111822376): implement sorting mechanism.
private void sortCards(List<ContextualCard> cards) {
@VisibleForTesting
List<ContextualCard> sortCards(List<ContextualCard> cards) {
//take mContextualCards as the source and do the ranking based on the rule.
return cards.stream()
.sorted((c1, c2) -> Double.compare(c2.getRankingScore(), c1.getRankingScore()))
.collect(Collectors.toList());
}
@Override
@@ -127,10 +131,9 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
allCards.addAll(
updateList.values().stream().flatMap(List::stream).collect(Collectors.toList()));
sortCards(allCards);
//replace with the new data
mContextualCards.clear();
mContextualCards.addAll(allCards);
mContextualCards.addAll(sortCards(allCards));
loadCardControllers();