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
This commit is contained in:
@@ -264,6 +264,19 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSuggestionDismissed() {
|
||||||
|
final List<Tile> 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
|
@Override
|
||||||
public void notifySummaryChanged(Tile tile) {
|
public void notifySummaryChanged(Tile tile) {
|
||||||
final int position = mDashboardData.getPositionByTile(tile);
|
final int position = mDashboardData.getPositionByTile(tile);
|
||||||
@@ -449,7 +462,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
return (Tile) getItem(getItemId(position));
|
return (Tile) getItem(getItemId(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDashboardDataChanged(DashboardData prevData) {
|
@VisibleForTesting
|
||||||
|
void notifyDashboardDataChanged(DashboardData prevData) {
|
||||||
if (mFirstFrameDrawn && prevData != null) {
|
if (mFirstFrameDrawn && prevData != null) {
|
||||||
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DashboardData
|
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DashboardData
|
||||||
.ItemsDataDiffCallback(prevData.getItemList(), mDashboardData.getItemList()));
|
.ItemsDataDiffCallback(prevData.getItemList(), mDashboardData.getItemList()));
|
||||||
|
@@ -249,6 +249,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuggestionDismissed(Tile suggestion) {
|
public void onSuggestionDismissed(Tile suggestion) {
|
||||||
|
mAdapter.onSuggestionDismissed();
|
||||||
// Refresh the UI to pick up suggestions that can now be shown because, say, a higher
|
// Refresh the UI to pick up suggestions that can now be shown because, say, a higher
|
||||||
// priority suggestion has been dismissed, or an exclusive suggestion category is emptied.
|
// priority suggestion has been dismissed, or an exclusive suggestion category is emptied.
|
||||||
rebuildUI();
|
rebuildUI();
|
||||||
|
@@ -21,6 +21,8 @@ import static org.mockito.Mockito.any;
|
|||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.reset;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -442,6 +444,33 @@ public class DashboardAdapterTest {
|
|||||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
assertThat(itemView.getChildCount()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuggestioDismissed_notOnlySuggestion_doNothing() {
|
||||||
|
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null));
|
||||||
|
adapter.setCategoriesAndSuggestions(
|
||||||
|
new ArrayList<>(), 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<Tile> makeSuggestions(String... pkgNames) {
|
private List<Tile> makeSuggestions(String... pkgNames) {
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
final List<Tile> suggestions = new ArrayList<>();
|
||||||
for (String pkgName : pkgNames) {
|
for (String pkgName : pkgNames) {
|
||||||
|
Reference in New Issue
Block a user