From dfd802da92b01e05ecba91f8ecc298585371d469 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Tue, 19 Dec 2023 15:58:33 +0800 Subject: [PATCH] Make the suggestion view dismissible The suggestion view could just be operated once to eliminate flicker. When the suggestion is completed, there was no way to dismiss it unless users kill Settings. This patch allows updating the view's visibility after the activity is stopped. When the activity restarts, the view can be updated. Fix: 294153594 Test: robotest Change-Id: Idc3aada3bff001d603bf2f7737f70f2880f6cc35 --- .../settings/homepage/SettingsHomepageActivity.java | 13 +++++++++---- .../homepage/SettingsHomepageActivityTest.java | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java index d96ec39507a..6688831248c 100644 --- a/src/com/android/settings/homepage/SettingsHomepageActivity.java +++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java @@ -119,6 +119,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements private SplitControllerCallbackAdapter mSplitControllerAdapter; private SplitInfoCallback mCallback; + private boolean mAllowUpdateSuggestion = true; /** A listener receiving homepage loaded events. */ public interface HomepageLoadedListener { @@ -155,15 +156,18 @@ public class SettingsHomepageActivity extends FragmentActivity implements * to avoid the flicker caused by the suggestion suddenly appearing/disappearing. */ public void showHomepageWithSuggestion(boolean showSuggestion) { + if (mAllowUpdateSuggestion) { + Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion); + mAllowUpdateSuggestion = false; + mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE); + mTwoPaneSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE); + } + if (mHomepageView == null) { return; } - Log.i(TAG, "showHomepageWithSuggestion: " + showSuggestion); final View homepageView = mHomepageView; - mSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE); - mTwoPaneSuggestionView.setVisibility(showSuggestion ? View.VISIBLE : View.GONE); mHomepageView = null; - mLoadedListeners.forEach(listener -> listener.onHomepageLoaded()); mLoadedListeners.clear(); homepageView.setVisibility(View.VISIBLE); @@ -278,6 +282,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements @Override protected void onStop() { super.onStop(); + mAllowUpdateSuggestion = true; if (mSplitControllerAdapter != null && mCallback != null) { mSplitControllerAdapter.removeSplitListener(mCallback); mCallback = null; diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java index c281dca8bc4..80d77c4900c 100644 --- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java +++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java @@ -167,6 +167,19 @@ public class SettingsHomepageActivityTest { assertThat(suggestionTile.getVisibility()).isEqualTo(View.GONE); } + @Test + public void showHomepageWithSuggestion_callAfterOnStop_shouldUpdateVisibility() { + final SettingsHomepageActivity activity = Robolectric.buildActivity( + SettingsHomepageActivity.class).create().get(); + final View suggestionTile = activity.findViewById(R.id.suggestion_content); + + activity.showHomepageWithSuggestion(true); + activity.onStop(); + activity.showHomepageWithSuggestion(false); + + assertThat(suggestionTile.getVisibility()).isEqualTo(View.GONE); + } + @Test public void onStart_isNotDebuggable_shouldHideSystemOverlay() { ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);