From fa58cfca6ef5e245b4e8d4cfe8cfd068938338e8 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Wed, 21 Jun 2017 11:40:37 -0700 Subject: [PATCH] Refresh the dashboard UI when swiping away the only suggestion. In the new suggestion UI, the suggestions are listed inside the suggestion container instead of individual dashboard items. When there is only a single suggestion shown, and that is being swiped away, the actual list for the suggestions will handle the swipe and remove that list item from the list. However, the top level container will remain until next time the dashboard list is being refreshed. Explicitly set the suggestions to null to force refreshing of the dashboard UI. Change-Id: I37f8c8f5a813a5c56f4f2f46103fdbb66ce97fcd Fix: 62639824 Test: make RunSettingsRoboTests --- .../settings/dashboard/DashboardAdapter.java | 16 +++++++++- .../settings/dashboard/DashboardSummary.java | 1 + .../dashboard/DashboardAdapterTest.java | 29 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index 3a768cc9384..a0841518c30 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -264,6 +264,19 @@ public class DashboardAdapter extends RecyclerView.Adapter suggestions = mDashboardData.getSuggestions(); + if (suggestions != null && 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; + mDashboardData = new DashboardData.Builder(prevData) + .setSuggestions(null) + .build(); + notifyDashboardDataChanged(prevData); + } + } + @Override public void notifySummaryChanged(Tile tile) { final int position = mDashboardData.getPositionByTile(tile); @@ -449,7 +462,8 @@ public class DashboardAdapter extends RecyclerView.Adapter(), makeSuggestions("pkg1", "pkg2", "pkg3")); + final DashboardData dashboardData = adapter.mDashboardData; + reset(adapter); // clear interactions tracking + + adapter.onSuggestionDismissed(); + + assertThat(adapter.mDashboardData).isEqualTo(dashboardData); + verify(adapter, never()).notifyDashboardDataChanged(any()); + } + + @Test + public void testSuggestioDismissed_onlySuggestion_updateDashboardData() { + DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null)); + adapter.setCategoriesAndSuggestions(new ArrayList<>(), makeSuggestions("pkg1")); + final DashboardData dashboardData = adapter.mDashboardData; + reset(adapter); // clear interactions tracking + + adapter.onSuggestionDismissed(); + + assertThat(adapter.mDashboardData).isNotEqualTo(dashboardData); + verify(adapter).notifyDashboardDataChanged(any()); + } + private List makeSuggestions(String... pkgNames) { final List suggestions = new ArrayList<>(); for (String pkgName : pkgNames) {