OSDN Git Service

Update subTitle of NotificationChannelSlice
authorYanting Yang <yantingyang@google.com>
Thu, 21 Feb 2019 15:12:15 +0000 (23:12 +0800)
committerYanting Yang <yantingyang@google.com>
Thu, 21 Feb 2019 15:57:55 +0000 (23:57 +0800)
If there are <=3 channels, should not have the "Tap to manage all".

Fixes: 124461104
Test: visual, robotests
Change-Id: Iebb957c65b8ca53f4c5d482041837338b7b3bbf2

res/values/strings.xml
src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
tests/robotests/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSliceTest.java

index 1b260f8..148cd1d 100644 (file)
     <string name="manage_app_notification">Manage <xliff:g id="app_name" example="Settings">%1$s</xliff:g> Notifications</string>
     <!-- Title for no suggested app in notification channel slice. [CHAR LIMIT=NONE] -->
     <string name="no_suggested_app">No suggested application</string>
-    <!-- Summary for notification channel slice. [CHAR LIMIT=NONE] -->
-    <plurals name="notification_channel_count_summary">
-        <item quantity="one"><xliff:g id="notification_channel_count">%1$d</xliff:g> notification channel. Tap to manage all.</item>
-        <item quantity="other"><xliff:g id="notification_channel_count">%1$d</xliff:g> notification channels. Tap to manage all.</item>
+    <!-- Summary for the channels count is equal or less than 3 in notification channel slice. [CHAR LIMIT=NONE] -->
+    <plurals name="notification_few_channel_count_summary">
+        <item quantity="one"><xliff:g id="notification_channel_count" example="1">%1$d</xliff:g> notification channel.</item>
+        <item quantity="other"><xliff:g id="notification_channel_count" example="3">%1$d</xliff:g> notification channels.</item>
     </plurals>
+    <!-- Summary for the channels count is more than 3 in notification channel slice. [CHAR LIMIT=NONE] -->
+    <string name="notification_many_channel_count_summary"><xliff:g id="notification_channel_count" example="4">%1$d</xliff:g> notification channels. Tap to manage all.</string>
 
     <!-- Title for the Switch output dialog (settings panel) with media related devices [CHAR LIMIT=50] -->
     <string name="media_output_panel_title">Switch output</string>
index c2c2ece..0152614 100644 (file)
@@ -415,9 +415,13 @@ public class NotificationChannelSlice implements CustomSliceable {
     private CharSequence getSubTitle(String packageName, int uid) {
         final int channelCount = mNotificationBackend.getChannelCount(packageName, uid);
 
+        if (channelCount > DEFAULT_EXPANDED_ROW_COUNT) {
+            return mContext.getString(
+                    R.string.notification_many_channel_count_summary, channelCount);
+        }
+
         return mContext.getResources().getQuantityString(
-                R.plurals.notification_channel_count_summary,
-                channelCount, channelCount);
+                R.plurals.notification_few_channel_count_summary, channelCount, channelCount);
     }
 
     private Intent getAppAndNotificationPageIntent() {
index 7ec1316..a744e68 100644 (file)
@@ -229,6 +229,50 @@ public class NotificationChannelSliceTest {
         assertThat(rows).isEqualTo(NotificationChannelSlice.DEFAULT_EXPANDED_ROW_COUNT + 1);
     }
 
+    @Test
+    @Config(shadows = ShadowRestrictedLockUtilsInternal.class)
+    public void getSlice_channelCountIsLessThanDefaultRows_subTitleShouldNotHaveTapToManagerAll() {
+        addMockPackageToPackageManager(true /* isRecentlyInstalled */,
+                ApplicationInfo.FLAG_INSTALLED);
+        mockNotificationBackend(CHANNEL_COUNT - 1, NOTIFICATION_COUNT, false /* banned */);
+
+        final Slice slice = mNotificationChannelSlice.getSlice();
+
+        final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+        assertThat(metadata.getSubtitle()).isEqualTo(mContext.getResources().getQuantityString(
+                R.plurals.notification_few_channel_count_summary, CHANNEL_COUNT - 1,
+                CHANNEL_COUNT - 1));
+    }
+
+    @Test
+    @Config(shadows = ShadowRestrictedLockUtilsInternal.class)
+    public void getSlice_channelCountIsEqualToDefaultRows_subTitleShouldNotHaveTapToManagerAll() {
+        addMockPackageToPackageManager(true /* isRecentlyInstalled */,
+                ApplicationInfo.FLAG_INSTALLED);
+        mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
+
+        final Slice slice = mNotificationChannelSlice.getSlice();
+
+        final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+        assertThat(metadata.getSubtitle()).isEqualTo(mContext.getResources().getQuantityString(
+                R.plurals.notification_few_channel_count_summary, CHANNEL_COUNT, CHANNEL_COUNT));
+    }
+
+    @Test
+    @Config(shadows = ShadowRestrictedLockUtilsInternal.class)
+    public void getSlice_channelCountIsMoreThanDefaultRows_subTitleShouldHaveTapToManagerAll() {
+        addMockPackageToPackageManager(true /* isRecentlyInstalled */,
+                ApplicationInfo.FLAG_INSTALLED);
+        mockNotificationBackend(CHANNEL_COUNT + 1, NOTIFICATION_COUNT, false /* banned */);
+
+        final Slice slice = mNotificationChannelSlice.getSlice();
+
+        final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+        assertThat(metadata.getSubtitle()).isEqualTo(
+                mContext.getString(R.string.notification_many_channel_count_summary,
+                        CHANNEL_COUNT + 1));
+    }
+
     private void addMockPackageToPackageManager(boolean isRecentlyInstalled, int flags) {
         final ApplicationInfo applicationInfo = new ApplicationInfo();
         applicationInfo.name = APP_LABEL;