Merge "[Settings] Code refactor" into rvc-dev am: 1de5f2e799
Change-Id: I0e5602e0ad69b980cde0de231d30bb77595637d6
diff --git a/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java b/src/com/android/settings/network/telephony/AbstractMobileNetworkSettings.java
index 889fbae..e92cdfc 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 @@
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 @@
.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 754dd05..d84d154 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -33,7 +33,6 @@
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.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 @@
private UserManager mUserManager;
private String mClickedPrefKey;
- private List<AbstractPreferenceController> mHiddenControllerList;
-
public MobileNetworkSettings() {
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
}
@@ -202,50 +197,6 @@
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) {