From bcab2a808a4c517bc356dc284f6e18eaf8c28c72 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Fri, 26 Feb 2021 18:36:35 +0000 Subject: [PATCH] Add shortcuts count as a subtitle in the full widgets sheet Screenshot: https://screenshot.googleplex.com/9Ds55rsFSNajLWN.png Test: Open full widgets sheet and observe widgets and shortcuts counts are correctly displayed. Bug: 180725078 Change-Id: Ibf43c14cc06c0e9bf245c53f190095d0eaeace12 --- res/layout/widgets_list_row_header.xml | 2 +- res/values/strings.xml | 19 ++++++++++--- .../widget/picker/WidgetsListHeader.java | 27 ++++++++++++++----- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/res/layout/widgets_list_row_header.xml b/res/layout/widgets_list_row_header.xml index faff10c156..041e0073fd 100644 --- a/res/layout/widgets_list_row_header.xml +++ b/res/layout/widgets_list_row_header.xml @@ -52,7 +52,7 @@ android:id="@+id/app_subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" - tools:text="n widgets" /> + tools:text="m widgets, n shortcuts" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 73f9e533ca..44b5ee7739 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -52,11 +52,22 @@ Touch & hold to place manually Add automatically - - - %1$d widget - %1$d widgets + + + %1$d widget + %1$d widgets + + + %1$d shortcut + %1$d shortcuts + + + %1$s, %2$s + Widgets diff --git a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java index 823fb7bcd2..070a9aa2c7 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java +++ b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java @@ -157,14 +157,29 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd private void setTitles(WidgetsListHeaderEntry entry) { mTitle.setText(entry.mPkgItem.title); - if (entry.widgetsCount > 0) { - Resources resources = getContext().getResources(); - mSubtitle.setText(resources.getQuantityString(R.plurals.widgets_tray_subtitle, - entry.widgetsCount, entry.widgetsCount)); - mSubtitle.setVisibility(VISIBLE); - } else { + Resources resources = getContext().getResources(); + if (entry.widgetsCount == 0 && entry.shortcutsCount == 0) { mSubtitle.setVisibility(GONE); + return; } + + String subtitle; + if (entry.widgetsCount > 0 && entry.shortcutsCount > 0) { + String widgetsCount = resources.getQuantityString(R.plurals.widgets_count, + entry.widgetsCount, entry.widgetsCount); + String shortcutsCount = resources.getQuantityString(R.plurals.shortcuts_count, + entry.shortcutsCount, entry.shortcutsCount); + subtitle = resources.getString(R.string.widgets_and_shortcuts_count, widgetsCount, + shortcutsCount); + } else if (entry.widgetsCount > 0) { + subtitle = resources.getQuantityString(R.plurals.widgets_count, + entry.widgetsCount, entry.widgetsCount); + } else { + subtitle = resources.getQuantityString(R.plurals.shortcuts_count, + entry.shortcutsCount, entry.shortcutsCount); + } + mSubtitle.setText(subtitle); + mSubtitle.setVisibility(VISIBLE); } @Override