Update summary of Modes entry in Settings
Instead of the number of automatic modes, simply list the first (up to 3) existing modes, according to the standard sort order, when none are active. As a consequence, the summary is never empty now. Fixes: 374179941 Test: atest ZenModeSummaryHelperTest + manual Flag: android.app.modes_ui Change-Id: I04f9d90a5e1e4ed13d66181b85d77fef8c6ff256
This commit is contained in:
@@ -8149,11 +8149,13 @@
|
||||
</string>
|
||||
|
||||
<!-- Modes: Summary for the modes segment, when no modes are active. [CHAR LIMIT=NONE]-->
|
||||
<string name="zen_modes_summary_none_active">
|
||||
<!-- Note: The "0" option should never actually occur. -->
|
||||
<string name="zen_modes_summary">
|
||||
{count, plural,
|
||||
=0 {}
|
||||
=1 {1 mode can turn on automatically}
|
||||
other {# modes can turn on automatically}
|
||||
=0 {Do Not Disturb}
|
||||
=1 {{mode_1}}
|
||||
=2 {{mode_1}, {mode_2}}
|
||||
other {{mode_1}, {mode_2}, {mode_3}}
|
||||
}
|
||||
</string>
|
||||
|
||||
|
@@ -498,29 +498,27 @@ class ZenModeSummaryHelper {
|
||||
MessageFormat msgFormat = new MessageFormat(
|
||||
mContext.getString(R.string.zen_modes_summary_some_active),
|
||||
Locale.getDefault());
|
||||
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("count", activeModes.size());
|
||||
args.put("mode_1", activeModes.get(0).getName());
|
||||
if (activeModes.size() >= 2) {
|
||||
args.put("mode_2", activeModes.get(1).getName());
|
||||
if (activeModes.size() == 3) {
|
||||
args.put("mode_3", activeModes.get(2).getName());
|
||||
}
|
||||
}
|
||||
|
||||
return msgFormat.format(args);
|
||||
return buildModesSummary(msgFormat, activeModes);
|
||||
} else {
|
||||
int automaticModeCount = (int) modes.stream()
|
||||
.filter(m -> m.isEnabled() && !m.isManualDnd() && !m.isCustomManual())
|
||||
.count();
|
||||
|
||||
MessageFormat msgFormat = new MessageFormat(
|
||||
mContext.getString(R.string.zen_modes_summary_none_active),
|
||||
mContext.getString(R.string.zen_modes_summary),
|
||||
Locale.getDefault());
|
||||
Map<String, Object> msgArgs = Map.of("count", automaticModeCount);
|
||||
return msgFormat.format(msgArgs);
|
||||
return buildModesSummary(msgFormat, modes);
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildModesSummary(MessageFormat msgFormat, List<ZenMode> modes) {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("count", modes.size());
|
||||
if (modes.size() >= 1) {
|
||||
args.put("mode_1", modes.get(0).getName());
|
||||
if (modes.size() >= 2) {
|
||||
args.put("mode_2", modes.get(1).getName());
|
||||
if (modes.size() >= 3) {
|
||||
args.put("mode_3", modes.get(2).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return msgFormat.format(args);
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -38,9 +37,7 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.SystemZenRules;
|
||||
import android.service.notification.ZenDeviceEffects;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
@@ -476,46 +473,61 @@ public class ZenModeSummaryHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_noRules_noSummary() {
|
||||
public void getModesSummary_noModesWtf_fallbackSummary() {
|
||||
String summary = mSummaryHelper.getModesSummary(ImmutableList.of());
|
||||
assertThat(summary).isEmpty();
|
||||
assertThat(summary).isEqualTo("Do Not Disturb");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_onlyDndAndNotActive_noSummary() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(TestModeBuilder.MANUAL_DND_INACTIVE);
|
||||
String summary = mSummaryHelper.getModesSummary(modes);
|
||||
assertThat(summary).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_noRulesActive_countsOnlyEnabledAutomaticModes() {
|
||||
public void getModesSummary_oneMode_listsMode() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
TestModeBuilder.MANUAL_DND_INACTIVE, // Not automatic
|
||||
new TestModeBuilder().setName("Auto 1").build(), // App provided automatic
|
||||
new TestModeBuilder()
|
||||
.setName("Custom manual 1")
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setType(AutomaticZenRule.TYPE_OTHER)
|
||||
.setConditionId(ZenModeConfig.toCustomManualConditionId())
|
||||
.build(), // Custom manual, not automatic
|
||||
new TestModeBuilder()
|
||||
.setName("Disabled 1")
|
||||
.setEnabled(false)
|
||||
.build(), // Would be automatic, but it's disabled.
|
||||
new TestModeBuilder()
|
||||
.setName("Sleep")
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setType(AutomaticZenRule.TYPE_SCHEDULE_TIME)
|
||||
.build() // Time based, automatic.
|
||||
new TestModeBuilder().setName("Surfing").build()
|
||||
);
|
||||
|
||||
String summary = mSummaryHelper.getModesSummary(modes);
|
||||
assertThat(summary).isEqualTo("2 modes can turn on automatically");
|
||||
assertThat(summary).isEqualTo("Surfing");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_oneModeActive_listsMode() {
|
||||
public void getModesSummary_twoModes_listsModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
new TestModeBuilder().setName("Cartwheeling").build(),
|
||||
new TestModeBuilder().setName("Hula-hooping").build()
|
||||
);
|
||||
|
||||
String summary = mSummaryHelper.getModesSummary(modes);
|
||||
assertThat(summary).isEqualTo("Cartwheeling, Hula-hooping");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_threeModes_listsModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
new TestModeBuilder().setName("Prancing").build(),
|
||||
new TestModeBuilder().setName("Hopping").build(),
|
||||
new TestModeBuilder().setName("Skipping").build()
|
||||
);
|
||||
|
||||
String summary = mSummaryHelper.getModesSummary(modes);
|
||||
assertThat(summary).isEqualTo("Prancing, Hopping, Skipping");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_manyModes_listsThreeModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
new TestModeBuilder().setName("Juggling").build(),
|
||||
new TestModeBuilder().setName("Rhyming").build(),
|
||||
new TestModeBuilder().setName("Meandering").build(),
|
||||
new TestModeBuilder().setName("Doodling").build(),
|
||||
new TestModeBuilder().setName("Whistling").build(),
|
||||
new TestModeBuilder().setName("Lounging").build()
|
||||
);
|
||||
|
||||
String summary = mSummaryHelper.getModesSummary(modes);
|
||||
assertThat(summary).isEqualTo("Juggling, Rhyming, Meandering");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_oneModeActive_listsActiveMode() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
TestModeBuilder.MANUAL_DND_ACTIVE,
|
||||
new TestModeBuilder().setName("Inactive").setActive(false).build());
|
||||
@@ -525,7 +537,7 @@ public class ZenModeSummaryHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_twoModesActive_listsModes() {
|
||||
public void getModesSummary_twoModesActive_listsActiveModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
TestModeBuilder.MANUAL_DND_ACTIVE,
|
||||
new TestModeBuilder().setName("Inactive").setActive(false).build(),
|
||||
@@ -536,7 +548,7 @@ public class ZenModeSummaryHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_threeModesActive_listsModes() {
|
||||
public void getModesSummary_threeModesActive_listsActiveModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
TestModeBuilder.MANUAL_DND_INACTIVE,
|
||||
new TestModeBuilder().setName("Inactive #1").setActive(false).build(),
|
||||
@@ -550,7 +562,7 @@ public class ZenModeSummaryHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModesSummary_manyModesActive_listsACouple() {
|
||||
public void getModesSummary_manyModesActive_listsSomeActiveModes() {
|
||||
ImmutableList<ZenMode> modes = ImmutableList.of(
|
||||
TestModeBuilder.MANUAL_DND_ACTIVE,
|
||||
new TestModeBuilder().setName("Inactive #1").setActive(false).build(),
|
||||
|
Reference in New Issue
Block a user