Wifi slice improvement
- always show toggle Bug: 149666241 Test: robotest Change-Id: I602d26abf2dfa631a939ee79e9adc63bed44ade0
This commit is contained in:
@@ -52,7 +52,7 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
@VisibleForTesting
|
||||
static long sActiveUiSession = -1000;
|
||||
@VisibleForTesting
|
||||
static boolean sToggleNeeded = true;
|
||||
static boolean sApRowCollapsed;
|
||||
|
||||
public ContextualWifiSlice(Context context) {
|
||||
super(context);
|
||||
@@ -69,26 +69,26 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
.getSlicesFeatureProvider().getUiSessionToken();
|
||||
if (currentUiSession != sActiveUiSession) {
|
||||
sActiveUiSession = currentUiSession;
|
||||
sToggleNeeded = !hasWorkingNetwork();
|
||||
sApRowCollapsed = hasWorkingNetwork();
|
||||
} else if (!mWifiManager.isWifiEnabled()) {
|
||||
sToggleNeeded = true;
|
||||
sApRowCollapsed = false;
|
||||
}
|
||||
return super.getSlice();
|
||||
}
|
||||
|
||||
static int getApRowCount() {
|
||||
return sToggleNeeded ? DEFAULT_EXPANDED_ROW_COUNT : COLLAPSED_ROW_COUNT;
|
||||
return sApRowCollapsed ? COLLAPSED_ROW_COUNT : DEFAULT_EXPANDED_ROW_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isToggleNeeded() {
|
||||
return sToggleNeeded;
|
||||
protected boolean isApRowCollapsed() {
|
||||
return sApRowCollapsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListBuilder.RowBuilder getHeaderRow(AccessPoint accessPoint) {
|
||||
final ListBuilder.RowBuilder builder = super.getHeaderRow(accessPoint);
|
||||
if (!sToggleNeeded) {
|
||||
if (sApRowCollapsed) {
|
||||
builder.setTitleItem(getLevelIcon(accessPoint), ListBuilder.ICON_IMAGE)
|
||||
.setSubtitle(getSubtitle(accessPoint));
|
||||
}
|
||||
|
@@ -107,7 +107,7 @@ public class WifiSlice implements CustomSliceable {
|
||||
final boolean isFirstApActive = apCount > 0 && apList.get(0).isActive();
|
||||
handleNetworkCallback(worker, isFirstApActive);
|
||||
|
||||
if (!isToggleNeeded()) {
|
||||
if (isApRowCollapsed()) {
|
||||
if (isFirstApActive) {
|
||||
// refresh header subtext
|
||||
listBuilder = getListBuilder(true /* isWifiEnabled */, apList.get(0));
|
||||
@@ -142,8 +142,8 @@ public class WifiSlice implements CustomSliceable {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isToggleNeeded() {
|
||||
return true;
|
||||
protected boolean isApRowCollapsed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected ListBuilder.RowBuilder getHeaderRow(AccessPoint accessPoint) {
|
||||
@@ -160,15 +160,14 @@ public class WifiSlice implements CustomSliceable {
|
||||
}
|
||||
|
||||
private ListBuilder getListBuilder(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction,
|
||||
null /* actionTitle */, isWifiEnabled);
|
||||
final ListBuilder builder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED)
|
||||
.setKeywords(getKeywords())
|
||||
.addRow(getHeaderRow(accessPoint));
|
||||
if (isToggleNeeded()) {
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
builder.addAction(SliceAction.createToggle(toggleAction, null /* actionTitle */,
|
||||
isWifiEnabled));
|
||||
}
|
||||
.addRow(getHeaderRow(accessPoint))
|
||||
.addAction(toggleSliceAction);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@@ -87,8 +87,7 @@ public class ContextualWifiSliceTest {
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertNoToggle(wifiSlice);
|
||||
assertWifiHeader(wifiSlice);
|
||||
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(COLLAPSED_ROW_COUNT);
|
||||
}
|
||||
|
||||
@@ -98,61 +97,32 @@ public class ContextualWifiSliceTest {
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertToggle(wifiSlice);
|
||||
assertWifiHeader(wifiSlice);
|
||||
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_previousExpanded_hasActiveConnection_shouldExpandSlice() {
|
||||
mWifiSlice.sActiveUiSession = mFeatureFactory.slicesFeatureProvider.getUiSessionToken();
|
||||
mWifiSlice.sToggleNeeded = true;
|
||||
mWifiSlice.sApRowCollapsed = false;
|
||||
connectToWifi(makeValidatedNetworkCapabilities());
|
||||
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertToggle(wifiSlice);
|
||||
assertWifiHeader(wifiSlice);
|
||||
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_previousExpanded_disableWifi_shouldHaveToggle() {
|
||||
mWifiSlice.sActiveUiSession = mFeatureFactory.slicesFeatureProvider.getUiSessionToken();
|
||||
mWifiSlice.sToggleNeeded = true;
|
||||
connectToWifi(makeValidatedNetworkCapabilities());
|
||||
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertToggle(wifiSlice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_previousCollapsed_disableWifi_shouldHaveToggle() {
|
||||
mWifiSlice.sActiveUiSession = mFeatureFactory.slicesFeatureProvider.getUiSessionToken();
|
||||
mWifiSlice.sToggleNeeded = false;
|
||||
connectToWifi(makeValidatedNetworkCapabilities());
|
||||
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertToggle(wifiSlice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_previousCollapsed_connectionLoss_shouldCollapseSlice() {
|
||||
mWifiSlice.sActiveUiSession = mFeatureFactory.slicesFeatureProvider.getUiSessionToken();
|
||||
mWifiSlice.sToggleNeeded = false;
|
||||
mWifiSlice.sApRowCollapsed = true;
|
||||
connectToWifi(makeValidatedNetworkCapabilities());
|
||||
|
||||
mWifiManager.disconnect();
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
|
||||
assertTitleAndIcon(wifiSlice);
|
||||
assertNoToggle(wifiSlice);
|
||||
assertWifiHeader(wifiSlice);
|
||||
assertThat(ContextualWifiSlice.getApRowCount()).isEqualTo(COLLAPSED_ROW_COUNT);
|
||||
}
|
||||
|
||||
@@ -181,7 +151,7 @@ public class ContextualWifiSliceTest {
|
||||
return nc;
|
||||
}
|
||||
|
||||
private void assertTitleAndIcon(Slice slice) {
|
||||
private void assertWifiHeader(Slice slice) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
|
||||
|
||||
@@ -189,17 +159,8 @@ public class ContextualWifiSliceTest {
|
||||
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings_wireless);
|
||||
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
|
||||
}
|
||||
|
||||
private void assertToggle(Slice slice) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
assertThat(toggles).hasSize(1);
|
||||
}
|
||||
|
||||
private void assertNoToggle(Slice slice) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
assertThat(toggles).isEmpty();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user