Fix 'Advanced' collapse point on Network & internet page

On the Network & internet page, we want to collapse all the prefs into
'Advanced' that appear after 'Data Saver'. The mechanism for specifying
where the collapse point starts is just a static count, and it doesn't
really understand the concept of dynamically added preferences like the
ones we add at the top when the device is in DSDS mode. To fix this in
the short term, this CL makes the header that manages these prefs
manually adjust the count as needed. In the future we'd like to have a
better mechanism for this added in the support library.

Fixes: 128855968
Test: make RunSettingsRoboTests
Change-Id: I4509726ff29bc71e1f0b3d4a2f60dffe4b1dd7ac
This commit is contained in:
Antony Sargent
2019-04-04 10:10:31 -07:00
parent 44427259e8
commit 24aa3b3504
5 changed files with 55 additions and 4 deletions

View File

@@ -38,6 +38,8 @@ public class MultiNetworkHeaderController extends BasePreferenceController imple
private WifiConnectionPreferenceController mWifiController;
private SubscriptionsPreferenceController mSubscriptionsController;
private PreferenceCategory mPreferenceCategory;
private PreferenceScreen mPreferenceScreen;
private int mOriginalExpandedChildrenCount;
public MultiNetworkHeaderController(Context context, String key) {
super(context, key);
@@ -65,6 +67,8 @@ public class MultiNetworkHeaderController extends BasePreferenceController imple
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreferenceScreen = screen;
mOriginalExpandedChildrenCount = mPreferenceScreen.getInitialExpandedChildrenCount();
mPreferenceCategory = screen.findPreference(mPreferenceKey);
mPreferenceCategory.setVisible(isAvailable());
mWifiController.displayPreference(screen);
@@ -82,6 +86,18 @@ public class MultiNetworkHeaderController extends BasePreferenceController imple
@Override
public void onChildrenUpdated() {
mPreferenceCategory.setVisible(isAvailable());
final boolean available = isAvailable();
// TODO(b/129893781) we need a better way to express where the advanced collapsing starts
// for preference groups that have items dynamically added/removed in the top expanded
// section.
if (mOriginalExpandedChildrenCount != Integer.MAX_VALUE) {
if (available) {
mPreferenceScreen.setInitialExpandedChildrenCount(
mOriginalExpandedChildrenCount + mPreferenceCategory.getPreferenceCount());
} else {
mPreferenceScreen.setInitialExpandedChildrenCount(mOriginalExpandedChildrenCount);
}
}
mPreferenceCategory.setVisible(available);
}
}