Limit the suggestions to be shown to 5.
- when creating the dashboard data, pass the sublist of suggestions to cap the total number of suggestions to be shown to 5. - if user swipe away the suggestion, it will only remove the suggestion from the suggestion adapater, and will not trigger rebuilding the whole UI. Bug: 64072051 Change-Id: I1efabeb2a805c670007c631d3ccb0fdfbde7b55a Fix: 63309218 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -67,6 +67,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
||||
@VisibleForTesting
|
||||
static final int SUGGESTION_CONDITION_HEADER_POSITION = 0;
|
||||
@VisibleForTesting
|
||||
static final int MAX_SUGGESTION_TO_SHOW = 5;
|
||||
|
||||
private final IconCache mCache;
|
||||
private final Context mContext;
|
||||
@@ -152,7 +154,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestions(suggestions.subList(0,
|
||||
Math.min(suggestions.size(), MAX_SUGGESTION_TO_SHOW)))
|
||||
.setCategory(category)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
@@ -194,9 +197,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
public void onSuggestionDismissed() {
|
||||
public void onSuggestionDismissed(Tile suggestion) {
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
if (suggestions != null && suggestions.size() == 1) {
|
||||
if (suggestions == null || suggestions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (suggestions.size() == 1) {
|
||||
// The only suggestion is dismissed, and the the empty suggestion container will
|
||||
// remain as the dashboard item. Need to refresh the dashboard list.
|
||||
final DashboardData prevData = mDashboardData;
|
||||
@@ -204,6 +210,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
} else {
|
||||
suggestions.remove(suggestion);
|
||||
mSuggestionAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user