diff options
author | Bonian Chen <bonianchen@google.com> | 2020-05-05 14:01:33 +0800 |
---|---|---|
committer | Bonian Chen <bonianchen@google.com> | 2020-05-05 10:01:09 +0000 |
commit | 0065f2e460aa58ace31473e4dcbb14907d35c52a (patch) | |
tree | 5ed57ac82d61dec2b488fdea332608774ec638e1 /src/com/android/settings/network | |
parent | 18490b2dc89f4da1edabd2abd42738b7ea001e2c (diff) | |
download | packages_apps_Settings-0065f2e460aa58ace31473e4dcbb14907d35c52a.tar.gz packages_apps_Settings-0065f2e460aa58ace31473e4dcbb14907d35c52a.tar.bz2 packages_apps_Settings-0065f2e460aa58ace31473e4dcbb14907d35c52a.zip |
[Settings] Code refactor
Code refactor.
Bug: 141833767
Test: manual
Change-Id: I3fa9dcc630b7612c1af3300024dee4f8deb6b308
Diffstat (limited to 'src/com/android/settings/network')
-rw-r--r-- | src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java | 50 | ||||
-rw-r--r-- | src/com/android/settings/network/telephony/MobileNetworkSettings.java | 49 |
2 files changed, 50 insertions, 49 deletions
diff --git a/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java b/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java index 889fbaec4e..e92cdfcd9d 100644 --- a/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java @@ -16,6 +16,11 @@ package com.android.settings.network.telephony; +import android.text.TextUtils; + +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settingslib.core.AbstractPreferenceController; @@ -27,6 +32,9 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment private static final String LOG_TAG = "AbsNetworkSettings"; + private List<AbstractPreferenceController> mHiddenControllerList = + new ArrayList<AbstractPreferenceController>(); + /** * @param restrictionKey The restriction key to check before pin protecting * this settings page. Pass in {@link RESTRICT_IF_OVERRIDABLE} if it should @@ -50,4 +58,46 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment .build(); } + @Override + public void onExpandButtonClick() { + final PreferenceScreen screen = getPreferenceScreen(); + mHiddenControllerList.stream() + .filter(controller -> controller.isAvailable()) + .forEach(controller -> { + final String key = controller.getPreferenceKey(); + final Preference preference = screen.findPreference(key); + controller.updateState(preference); + }); + super.onExpandButtonClick(); + } + + /* + * Replace design within {@link DashboardFragment#updatePreferenceStates()} + */ + @Override + protected void updatePreferenceStates() { + mHiddenControllerList.clear(); + + final PreferenceScreen screen = getPreferenceScreen(); + getPreferenceControllersAsList().forEach(controller -> { + final String key = controller.getPreferenceKey(); + if (TextUtils.isEmpty(key)) { + return; + } + final Preference preference = screen.findPreference(key); + if (preference == null) { + return; + } + if (!isPreferenceExpanded(preference)) { + mHiddenControllerList.add(controller); + return; + } + if (!controller.isAvailable()) { + return; + } + controller.updateState(preference); + }); + } + + } diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java index 754dd058c7..d84d15409f 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java @@ -33,7 +33,6 @@ import android.view.MenuItem; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; -import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.datausage.BillingCyclePreferenceController; @@ -46,9 +45,7 @@ import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.search.SearchIndexable; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) @@ -73,8 +70,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { private UserManager mUserManager; private String mClickedPrefKey; - private List<AbstractPreferenceController> mHiddenControllerList; - public MobileNetworkSettings() { super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS); } @@ -202,50 +197,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings { onRestoreInstance(icicle); } - @Override - public void onExpandButtonClick() { - final PreferenceScreen screen = getPreferenceScreen(); - mHiddenControllerList.stream() - .filter(controller -> controller.isAvailable()) - .forEach(controller -> { - final String key = controller.getPreferenceKey(); - final Preference preference = screen.findPreference(key); - controller.updateState(preference); - }); - super.onExpandButtonClick(); - } - - /* - * Replace design within {@link DashboardFragment#updatePreferenceStates()} - */ - @Override - protected void updatePreferenceStates() { - mHiddenControllerList = new ArrayList<AbstractPreferenceController>(); - - final PreferenceScreen screen = getPreferenceScreen(); - final Collection<List<AbstractPreferenceController>> controllerLists = - getPreferenceControllers(); - controllerLists.stream().flatMap(Collection::stream) - .forEach(controller -> { - final String key = controller.getPreferenceKey(); - if (TextUtils.isEmpty(key)) { - return; - } - final Preference preference = screen.findPreference(key); - if (preference == null) { - return; - } - if (!isPreferenceExpanded(preference)) { - mHiddenControllerList.add(controller); - return; - } - if (!controller.isAvailable()) { - return; - } - controller.updateState(preference); - }); - } - @VisibleForTesting void onRestoreInstance(Bundle icicle) { if (icicle != null) { |