Merge "[Settings] Code refactor" am: f4d59078fb

Change-Id: I65a011ca26c574d53d7ae3c2551fe6aa44f9c861
This commit is contained in:
Zoey Chen
2020-05-19 10:15:33 +00:00
committed by Automerger Merge Worker
2 changed files with 50 additions and 48 deletions

View File

@@ -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);
});
}
}

View File

@@ -34,7 +34,6 @@ import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
@@ -56,7 +55,6 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -86,8 +84,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
private UserManager mUserManager;
private String mClickedPrefKey;
private List<AbstractPreferenceController> mHiddenControllerList;
public MobileNetworkSettings() {
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
}
@@ -210,50 +206,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) {