Dismiss suggestion when close button is clicked.
- add handling to the suggestion card to dismiss the suggestion when
the close button is clicked.
Bug: 70573674
Test: make RunSettingsRoboTests
Change-Id: I8155efc326242abde753a633009e2579a9b3aa9b
diff --git a/src/com/android/settings/dashboard/DashboardAdapterV2.java b/src/com/android/settings/dashboard/DashboardAdapterV2.java
index 7cd4f38..f98b440 100644
--- a/src/com/android/settings/dashboard/DashboardAdapterV2.java
+++ b/src/com/android/settings/dashboard/DashboardAdapterV2.java
@@ -151,13 +151,10 @@
if (list.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 DashboardDataV2 prevData = mDashboardData;
- mDashboardData = new DashboardDataV2.Builder(prevData)
- .setSuggestions(null)
- .build();
- notifyDashboardDataChanged(prevData);
+ setSuggestions(null);
} else {
mSuggestionAdapter.removeSuggestion(suggestion);
+ notifyItemChanged(0, null);
}
}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2.java
index 483af92..06b7c3a 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2.java
@@ -55,6 +55,7 @@
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final IconCache mCache;
private final ArrayList<String> mSuggestionsShownLogged;
+ private final SuggestionFeatureProvider mSuggestionFeatureProvider;
private final SuggestionControllerMixin mSuggestionControllerMixin;
private final Callback mCallback;
private final CardConfig mConfig;
@@ -75,6 +76,7 @@
mCache = new IconCache(context);
final FeatureFactory factory = FeatureFactory.getFactory(context);
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
+ mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
mCallback = callback;
if (savedInstanceState != null) {
mSuggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
@@ -129,13 +131,13 @@
final ImageView closeButton = holder.itemView.findViewById(R.id.close_button);
if (closeButton != null) {
- if (mCallback != null) {
- closeButton.setOnClickListener(v -> {
+ closeButton.setOnClickListener(v -> {
+ mSuggestionFeatureProvider.dismissSuggestion(
+ mContext, mSuggestionControllerMixin, suggestion);
+ if (mCallback != null) {
mCallback.onSuggestionClosed(suggestion);
- });
- } else {
- closeButton.setOnClickListener(null);
- }
+ }
+ });
}
View clickHandler = holder.itemView;
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2Test.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2Test.java
index 1e76e2d..dd9d0e4 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2Test.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterV2Test.java
@@ -200,7 +200,10 @@
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
mSuggestionHolder.itemView.findViewById(R.id.close_button).performClick();
- verify(callback).onSuggestionClosed(suggestions.get(0));
+ final Suggestion suggestion = suggestions.get(0);
+ verify(mFeatureFactory.suggestionsFeatureProvider).dismissSuggestion(
+ mActivity, mSuggestionControllerMixin, suggestion);
+ verify(callback).onSuggestionClosed(suggestion);
}
private void setupSuggestions(Context context, List<Suggestion> suggestions) {