Merge "Fix 'Advanced' collapse point on Network & internet page" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5c28e42538
@@ -18,7 +18,8 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="network_and_internet_screen"
|
||||
android:title="@string/network_dashboard_title">
|
||||
android:title="@string/network_dashboard_title"
|
||||
settings:initialExpandedChildrenCount="6">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="multi_network_header"
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSubscriptionsListener.isAirplaneModeOn()) {
|
||||
if (!isAvailable()) {
|
||||
for (Preference pref : mSubscriptionPreferences.values()) {
|
||||
mPreferenceGroup.removePreference(pref);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.network;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -50,6 +51,7 @@ import androidx.preference.PreferenceScreen;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MultiNetworkHeaderControllerTest {
|
||||
private static final String KEY_HEADER = "multi_network_header";
|
||||
private static final int EXPANDED_CHILDREN_COUNT = 5;
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@@ -75,6 +77,9 @@ public class MultiNetworkHeaderControllerTest {
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mPreferenceScreen.findPreference(eq(KEY_HEADER))).thenReturn(mPreferenceCategory);
|
||||
when(mPreferenceCategory.getPreferenceCount()).thenReturn(3);
|
||||
when(mPreferenceScreen.getInitialExpandedChildrenCount()).thenReturn(
|
||||
EXPANDED_CHILDREN_COUNT);
|
||||
|
||||
mHeaderController = spy(new MultiNetworkHeaderController(mContext, KEY_HEADER));
|
||||
doReturn(mWifiController).when(mHeaderController).createWifiController(mLifecycle);
|
||||
@@ -133,6 +138,11 @@ public class MultiNetworkHeaderControllerTest {
|
||||
verify(mPreferenceCategory, atLeastOnce()).setVisible(captor.capture());
|
||||
List<Boolean> values = captor.getAllValues();
|
||||
assertThat(values.get(values.size()-1)).isEqualTo(Boolean.TRUE);
|
||||
|
||||
ArgumentCaptor<Integer> expandedCountCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture());
|
||||
assertThat(expandedCountCaptor.getValue()).isEqualTo(
|
||||
EXPANDED_CHILDREN_COUNT + mPreferenceCategory.getPreferenceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,5 +158,23 @@ public class MultiNetworkHeaderControllerTest {
|
||||
verify(mPreferenceCategory, atLeastOnce()).setVisible(captor.capture());
|
||||
List<Boolean> values = captor.getAllValues();
|
||||
assertThat(values.get(values.size()-1)).isEqualTo(Boolean.FALSE);
|
||||
|
||||
ArgumentCaptor<Integer> expandedCountCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture());
|
||||
assertThat(expandedCountCaptor.getValue()).isEqualTo(EXPANDED_CHILDREN_COUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onChildUpdated_noExpandedChildCountAndAvailable_doesNotSetExpandedCount() {
|
||||
when(mPreferenceScreen.getInitialExpandedChildrenCount()).thenReturn(Integer.MAX_VALUE);
|
||||
|
||||
when(mSubscriptionsController.isAvailable()).thenReturn(false);
|
||||
mHeaderController.init(mLifecycle);
|
||||
mHeaderController.displayPreference(mPreferenceScreen);
|
||||
|
||||
when(mSubscriptionsController.isAvailable()).thenReturn(true);
|
||||
mHeaderController.onChildrenUpdated();
|
||||
|
||||
verify(mPreferenceScreen, never()).setInitialExpandedChildrenCount(anyInt());
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -186,19 +187,24 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSubscriptionsChanged_countBecameOne_eventFired() {
|
||||
public void onSubscriptionsChanged_countBecameOne_eventFiredAndPrefsRemoved() {
|
||||
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
|
||||
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
|
||||
when(sub1.getSubscriptionId()).thenReturn(1);
|
||||
when(sub2.getSubscriptionId()).thenReturn(2);
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
mController.onResume();
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
verify(mPreferenceCategory, times(2)).addPreference(any(Preference.class));
|
||||
|
||||
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
|
||||
mController.onSubscriptionsChanged();
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
|
||||
|
||||
verify(mPreferenceCategory, times(2)).removePreference(any(Preference.class));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user