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
This commit is contained in:
Steven Ng 2021-02-26 18:36:35 +00:00
parent befaad269e
commit bcab2a808a
3 changed files with 37 additions and 11 deletions

View File

@ -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" />
</LinearLayout>

View File

@ -52,11 +52,22 @@
<string name="add_item_request_drag_hint">Touch &amp; hold to place manually</string>
<!-- Button label to automatically add icon on home screen [CHAR_LIMIT=50] -->
<string name="place_automatically">Add automatically</string>
<!-- Label for showing the number of widgets an app has in the full widgets picker. [CHAR_LIMIT=25] -->
<plurals name="widgets_tray_subtitle">
<item quantity="one"><xliff:g id="widget_count" example="1">%1$d</xliff:g> widget</item>
<item quantity="other"><xliff:g id="widget_count" example="2">%1$d</xliff:g> widgets</item>
<!-- Label for showing the number of widgets an app has in the full widgets picker.
[CHAR_LIMIT=25] -->
<plurals name="widgets_count">
<item quantity="one"><xliff:g id="widgets_count" example="1">%1$d</xliff:g> widget</item>
<item quantity="other"><xliff:g id="widgets_count" example="2">%1$d</xliff:g> widgets</item>
</plurals>
<!-- Label for showing the number of shortcut an app has in the full widgets picker.
[CHAR_LIMIT=25] -->
<plurals name="shortcuts_count">
<item quantity="one"><xliff:g id="shortcuts_count" example="1">%1$d</xliff:g> shortcut</item>
<item quantity="other"><xliff:g id="shortcuts_count" example="2">%1$d</xliff:g> shortcuts</item>
</plurals>
<!-- Label for showing both the number of widgets and shortcuts an app has in the full widgets
picker. [CHAR_LIMIT=50] -->
<string name="widgets_and_shortcuts_count"><xliff:g id="widgets_count" example="5 widgets">%1$s</xliff:g>, <xliff:g id="shortcuts_count" example="1 shortcut">%2$s</xliff:g></string>
<!-- Text for both the tile of a popup view, which shows all available widgets installed on
the device, and the text of a button, which opens this popup view. [CHAR LIMIT=30]-->
<string name="widget_button_text">Widgets</string>

View File

@ -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