Merge "[Settings] Code refactor" am: f4d59078fb
Change-Id: I65a011ca26c574d53d7ae3c2551fe6aa44f9c861
This commit is contained in:
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
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.settings.dashboard.RestrictedDashboardFragment;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
@@ -27,6 +32,9 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
private static final String LOG_TAG = "AbsNetworkSettings";
|
private static final String LOG_TAG = "AbsNetworkSettings";
|
||||||
|
|
||||||
|
private List<AbstractPreferenceController> mHiddenControllerList =
|
||||||
|
new ArrayList<AbstractPreferenceController>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param restrictionKey The restriction key to check before pin protecting
|
* @param restrictionKey The restriction key to check before pin protecting
|
||||||
* this settings page. Pass in {@link RESTRICT_IF_OVERRIDABLE} if it should
|
* this settings page. Pass in {@link RESTRICT_IF_OVERRIDABLE} if it should
|
||||||
@@ -50,4 +58,46 @@ abstract class AbstractMobileNetworkSettings extends RestrictedDashboardFragment
|
|||||||
.build();
|
.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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,6 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -56,7 +55,6 @@ import com.android.settingslib.utils.ThreadUtils;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@@ -86,8 +84,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private String mClickedPrefKey;
|
private String mClickedPrefKey;
|
||||||
|
|
||||||
private List<AbstractPreferenceController> mHiddenControllerList;
|
|
||||||
|
|
||||||
public MobileNetworkSettings() {
|
public MobileNetworkSettings() {
|
||||||
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
|
super(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);
|
||||||
}
|
}
|
||||||
@@ -210,50 +206,6 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
|
|||||||
onRestoreInstance(icicle);
|
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
|
@VisibleForTesting
|
||||||
void onRestoreInstance(Bundle icicle) {
|
void onRestoreInstance(Bundle icicle) {
|
||||||
if (icicle != null) {
|
if (icicle != null) {
|
||||||
|
Reference in New Issue
Block a user