From cfa36dbaebc2b7aaff1206c64ee3461b000bffd4 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Wed, 5 Jun 2019 17:31:31 +0800 Subject: [PATCH] Fix double divider in Apps & notifications page - The second divider is shown after we set a background to the pinned header. - Fix it by simply hiding the pinned header instead of its inner views. Fixes: 133231218 Test: robotest, visual Change-Id: I53add6f01930299425ce96d23350f9f066e85145 --- .../settings/SettingsPreferenceFragment.java | 7 ++++++- .../AppAndNotificationDashboardFragment.java | 18 ++++-------------- .../SettingsPreferenceFragmentTest.java | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index 9a60876ca49..1104672d337 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -113,7 +113,8 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF } }; - private ViewGroup mPinnedHeaderFrameLayout; + @VisibleForTesting + ViewGroup mPinnedHeaderFrameLayout; private ViewGroup mButtonBar; private LayoutPreference mHeader; @@ -186,6 +187,10 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF mPinnedHeaderFrameLayout.setVisibility(View.VISIBLE); } + public void showPinnedHeader(boolean show) { + mPinnedHeaderFrameLayout.setVisibility(show ? View.VISIBLE : View.INVISIBLE); + } + @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java index 5e57908035f..876c99938f7 100644 --- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java +++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java @@ -44,8 +44,6 @@ public class AppAndNotificationDashboardFragment extends DashboardFragment private static final String TAG = "AppAndNotifDashboard"; - private View mProgressHeader; - private View mProgressAnimation; private RecentAppStatsMixin mRecentAppStatsMixin; private RecentAppsPreferenceController mRecentAppsPreferenceController; private AllAppsInfoPreferenceController mAllAppsInfoPreferenceController; @@ -92,20 +90,19 @@ public class AppAndNotificationDashboardFragment extends DashboardFragment @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - mProgressHeader = setPinnedHeaderView(R.layout.progress_header); - mProgressAnimation = mProgressHeader.findViewById(R.id.progress_bar_animation); - setLoadingEnabled(false); + setPinnedHeaderView(R.layout.progress_header); + showPinnedHeader(false); } @Override public void onStart() { super.onStart(); - setLoadingEnabled(true); + showPinnedHeader(true); } @Override public void onReloadDataCompleted(@NonNull List recentApps) { - setLoadingEnabled(false); + showPinnedHeader(false); if (!recentApps.isEmpty()) { Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(), getListView()); @@ -117,13 +114,6 @@ public class AppAndNotificationDashboardFragment extends DashboardFragment return buildPreferenceControllers(context); } - private void setLoadingEnabled(boolean enabled) { - if (mProgressHeader != null && mProgressAnimation != null) { - mProgressHeader.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); - mProgressAnimation.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); - } - } - private static List buildPreferenceControllers(Context context) { final List controllers = new ArrayList<>(); controllers.add(new EmergencyBroadcastPreferenceController(context, diff --git a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java index cce01550a78..5447d7b7119 100644 --- a/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/SettingsPreferenceFragmentTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.os.Bundle; import android.view.View; +import android.widget.FrameLayout; import androidx.fragment.app.FragmentActivity; import androidx.preference.Preference; @@ -187,6 +188,24 @@ public class SettingsPreferenceFragmentTest { verify(workOnlyCategory).setVisible(false); } + @Test + public void showPinnedHeader_shouldBeVisible() { + mFragment.mPinnedHeaderFrameLayout = new FrameLayout(mContext); + + mFragment.showPinnedHeader(true); + + assertThat(mFragment.mPinnedHeaderFrameLayout.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void hidePinnedHeader_shouldBeInvisible() { + mFragment.mPinnedHeaderFrameLayout = new FrameLayout(mContext); + + mFragment.showPinnedHeader(false); + + assertThat(mFragment.mPinnedHeaderFrameLayout.getVisibility()).isEqualTo(View.INVISIBLE); + } + public static class TestFragment extends SettingsPreferenceFragment { @Override