diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index 27b45252683..000a2afdafe 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -146,15 +146,14 @@ public class DashboardAdapter extends RecyclerView.Adapter list = mDashboardData.getSuggestions(); - if (list == null || list.size() == 0) { + if (list == null || list.size() == 0 || !list.remove(suggestion)) { return; } - if (list.size() == 1) { + if (list.isEmpty()) { // The only suggestion is dismissed, and the the empty suggestion container will // remain as the dashboard item. Need to refresh the dashboard list. setSuggestions(null); } else { - list.remove(suggestion); setSuggestions(list); } } diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java index 1b2f72742d3..67a79fa7ee1 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java @@ -101,7 +101,7 @@ public class DashboardAdapterTest { } @Test - public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() { + public void onSuggestionClosed_notOnlySuggestion_updateSuggestionOnly() { final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /* savedInstanceState */, null /* conditions */, null /* suggestionControllerMixin */, @@ -134,8 +134,8 @@ public class DashboardAdapterTest { } @Test - public void testSuggestionDismissed_onlySuggestion_updateDashboardData() { - DashboardAdapter adapter = + public void onSuggestionClosed_onlySuggestion_updateDashboardData() { + final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /* savedInstanceState */, null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */)); @@ -151,7 +151,23 @@ public class DashboardAdapterTest { } @Test - public void testBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() { + public void onSuggestionClosed_notInSuggestionList_shouldNotUpdateSuggestionList() { + final DashboardAdapter adapter = + spy(new DashboardAdapter(mContext, null /* savedInstanceState */, + null /* conditions */, null /* suggestionControllerMixin */, + null /* lifecycle */)); + final List suggestions = makeSuggestionsV2("pkg1"); + adapter.setSuggestions(suggestions); + final DashboardData dashboardData = adapter.mDashboardData; + reset(adapter); // clear interactions tracking + + adapter.onSuggestionClosed(mock(Suggestion.class)); + + verify(adapter, never()).setSuggestions(any()); + } + + @Test + public void onBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() { mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */, null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */); final List suggestions = makeSuggestionsV2("pkg1");