Add dialog when restrict apps are more than 5

Bug: 73018395
Test: RunSettingsRoboTests
Change-Id: Iec24fc1ce8e5840207610b3155dffa7059f9aa49
This commit is contained in:
Lei Yu
2018-03-12 17:16:54 -07:00
parent 920548005b
commit 888ea9ef1f
4 changed files with 78 additions and 20 deletions

View File

@@ -107,21 +107,30 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
final RestrictAppTip restrictAppTip = (RestrictAppTip) mBatteryTip;
final List<AppInfo> restrictedAppList = restrictAppTip.getRestrictAppList();
final int num = restrictedAppList.size();
final CharSequence appLabel = Utils.getApplicationLabel(context,
restrictedAppList.get(0).packageName);
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle(context.getResources().getQuantityString(
R.plurals.battery_tip_restrict_app_dialog_title, num, num))
.setMessage(getString(R.string.battery_tip_restrict_app_dialog_message))
.setPositiveButton(R.string.battery_tip_restrict_app_dialog_ok, this)
.setNegativeButton(android.R.string.cancel, null);
// TODO(b/72385333): consider building dialog with 5+ apps when strings are done
if (num > 1) {
if (num == 1) {
builder.setMessage(
getString(R.string.battery_tip_restrict_app_dialog_message, appLabel));
} else if (num <= 5) {
builder.setMessage(
getString(
R.string.battery_tip_restrict_apps_less_than_5_dialog_message));
final RecyclerView restrictionView = (RecyclerView) LayoutInflater.from(
context).inflate(R.layout.recycler_view, null);
restrictionView.setLayoutManager(new LinearLayoutManager(context));
restrictionView.setAdapter(new HighUsageAdapter(context, restrictedAppList));
builder.setView(restrictionView);
} else {
builder.setMessage(context.getString(
R.string.battery_tip_restrict_apps_more_than_5_dialog_message,
restrictAppTip.getRestrictAppsString(context)));
}
return builder.create();