Adds summary helper for apps subtitle

The subtitle for the apps page says which apps (up to two/three) and how
many (if there are more than three) are allowed to bypass dnd under the
main "Apps" page.

Bug: 308819928
Test: atest ZenModesSummaryHelperTest
Flag: android.app.modes_ui
Change-Id: I15696384c392ba3f054948db50eea614f91d8c48
This commit is contained in:
Alexander Roederer
2024-06-04 19:18:08 +00:00
parent 484d129b35
commit a6b1d7cbbc
3 changed files with 110 additions and 7 deletions

View File

@@ -43,13 +43,18 @@ import android.icu.text.MessageFormat;
import android.service.notification.ZenDeviceEffects;
import android.service.notification.ZenPolicy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settings.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
class ZenModeSummaryHelper {
@@ -397,12 +402,13 @@ class ZenModeSummaryHelper {
}
/**
* Generates a summary to display under the top level "Apps" preference for a mode.
* Generates a summary to display under the top level "Apps" preference for a mode, based
* on the given mode and provided set of apps.
*/
public String getAppsSummary(ZenMode zenMode) {
// TODO: b/308819928 - Set summary using priority app list if Selected Apps Chosen.
public @NonNull String getAppsSummary(@NonNull ZenMode zenMode,
@Nullable Set<String> appsBypassing) {
if (zenMode.getPolicy().getAllowedChannels() == ZenPolicy.CHANNEL_POLICY_PRIORITY) {
return mContext.getResources().getString(R.string.zen_mode_apps_priority_apps);
return formatAppsList(appsBypassing);
} else if (zenMode.getPolicy().getAllowedChannels() == ZenPolicy.CHANNEL_POLICY_NONE) {
return mContext.getResources().getString(R.string.zen_mode_apps_none_apps);
} else if (zenMode.getPolicy().getAllowedChannels() == ZenMode.CHANNEL_POLICY_ALL) {
@@ -410,4 +416,35 @@ class ZenModeSummaryHelper {
}
return "";
}
/**
* Generates a formatted string declaring which apps can interrupt in the style of
* "App, App2, and 4 more can interrupt."
* Apps selected for explicit mention are selected in order from the provided set sorted
* alphabetically.
*/
public @NonNull String formatAppsList(@Nullable Set<String> appsBypassingDnd) {
if (appsBypassingDnd == null) {
return mContext.getResources().getString(R.string.zen_mode_apps_priority_apps);
}
final int numAppsBypassingDnd = appsBypassingDnd.size();
String[] appsBypassingDndArr = appsBypassingDnd.toArray(new String[numAppsBypassingDnd]);
// Sorts the provided apps alphabetically.
Arrays.sort(appsBypassingDndArr);
MessageFormat msgFormat = new MessageFormat(
mContext.getString(R.string.zen_mode_apps_subtext),
Locale.getDefault());
Map<String, Object> args = new HashMap<>();
args.put("count", numAppsBypassingDnd);
if (numAppsBypassingDnd >= 1) {
args.put("app_1", appsBypassingDndArr[0]);
if (numAppsBypassingDnd >= 2) {
args.put("app_2", appsBypassingDndArr[1]);
if (numAppsBypassingDnd == 3) {
args.put("app_3", appsBypassingDndArr[2]);
}
}
}
return msgFormat.format(args);
}
}