Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee8c81ee authored by Geoffrey Pitsch's avatar Geoffrey Pitsch
Browse files

Notification Inline strings for non-upgraded apps

Also fix string typo - "1 of n notification categories"

Test: runtest systemui
Change-Id: I6f48f2ffde4896341ee0a435b9b1dc6a1255ea48
parent 1e81b7f1
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -1347,11 +1347,15 @@
        of notifications.  Replaces the channel name and only appears when there is more than one channel. -->
    <string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string>

    <!-- Notification: Control panel: Label that shows when an app has not upgraded to use channels.
        Hints that the user's only option is to block all of the app's notifications. -->
    <string name="notification_default_channel_desc">This app doesn\'t have notification categories</string>

    <!-- Notification: Control panel: Label that shows how many channels this application has
        defined, describing the current notification channel as "1 out of n categories from this app". -->
        defined, describing the current notification channel as "1 out of n notification categories from this app". -->
    <plurals name="notification_num_channels_desc">
        <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> category from this app</item>
        <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> categories from this app</item>
        <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> notification category from this app</item>
        <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> notification categories from this app</item>
    </plurals>

    <!-- Notification: Control panel: For bundles of notifications, this label that lists the
+30 −28
Original line number Diff line number Diff line
@@ -99,11 +99,14 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
        mINotificationManager = iNotificationManager;
        mPkg = pkg;
        mNotificationChannels = notificationChannels;
        boolean isSingleDefaultChannel = false;
        if (mNotificationChannels.isEmpty()) {
            throw new IllegalArgumentException("bindNotification requires at least one channel");
        } else if (mNotificationChannels.size() == 1) {
            mSingleNotificationChannel = mNotificationChannels.get(0);
            mStartingUserImportance = mSingleNotificationChannel.getImportance();
            isSingleDefaultChannel = mSingleNotificationChannel.getId()
                    .equals(NotificationChannel.DEFAULT_CHANNEL_ID);
        } else {
            mSingleNotificationChannel = null;
        }
@@ -135,13 +138,17 @@ public class NotificationInfo extends LinearLayout implements GutsContent {

        String channelsDescText;
        mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc));
        if (isSingleDefaultChannel) {
            channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
        } else {
            switch (mNotificationChannels.size()) {
                case 1:
                    channelsDescText = String.format(mContext.getResources().getQuantityString(
                            R.plurals.notification_num_channels_desc, numChannels), numChannels);
                    break;
                case 2:
                channelsDescText = mContext.getString(R.string.notification_channels_list_desc_2,
                    channelsDescText = mContext.getString(
                            R.string.notification_channels_list_desc_2,
                            mNotificationChannels.get(0).getName(),
                            mNotificationChannels.get(1).getName());
                    break;
@@ -149,20 +156,21 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
                    final int numOthers = mNotificationChannels.size() - 2;
                    channelsDescText = String.format(
                            mContext.getResources().getQuantityString(
                                R.plurals.notification_channels_list_desc_2_and_others, numOthers),
                                    R.plurals.notification_channels_list_desc_2_and_others,
                                    numOthers),
                            mNotificationChannels.get(0).getName(),
                            mNotificationChannels.get(1).getName(),
                            numOthers);
            }
        }
        mNumChannelsView.setText(channelsDescText);

        if (mSingleNotificationChannel == null) {
            // Multiple channels don't use a channel name for the title.
            channelNameText = mContext.getString(R.string.notification_num_channels,
                    mNotificationChannels.size());
        } else if (mSingleNotificationChannel.getId()
                .equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            // If this is the placeholder channel, don't use our channel-specific text.
        } else if (isSingleDefaultChannel) {
            // If this is the default channel, don't use our channel-specific text.
            channelNameText = mContext.getString(R.string.notification_header_default_channel);
        } else {
            channelNameText = mSingleNotificationChannel.getName();
@@ -282,15 +290,9 @@ public class NotificationInfo extends LinearLayout implements GutsContent {
    }

    private void updateSecondaryText() {
        final boolean defaultChannel = mSingleNotificationChannel != null &&
                mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID);
        final boolean disabled = mSingleNotificationChannel != null &&
                getSelectedImportance() == NotificationManager.IMPORTANCE_NONE;
        if (defaultChannel) {
            // Don't show any secondary text if this is from the default channel.
            mChannelDisabledView.setVisibility(View.GONE);
            mNumChannelsView.setVisibility(View.GONE);
        } else if (disabled) {
        if (disabled) {
            mChannelDisabledView.setVisibility(View.VISIBLE);
            mNumChannelsView.setVisibility(View.GONE);
        } else {
+7 −4
Original line number Diff line number Diff line
@@ -260,12 +260,14 @@ public class NotificationInfoTest extends SysuiTestCase {
    }

    @Test
    public void testBindNotification_NumChannelsTextHiddenWhenDefaultChannel() throws Exception {
    public void testBindNotification_NumChannelsTextUniqueWhenDefaultChannel() throws Exception {
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null);
        final TextView numChannelsView =
                (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
        assertTrue(numChannelsView.getVisibility() != View.VISIBLE);
        assertEquals(View.VISIBLE, numChannelsView.getVisibility());
        assertEquals(mContext.getString(R.string.notification_default_channel_desc),
                numChannelsView.getText());
    }

    @Test
@@ -390,13 +392,14 @@ public class NotificationInfoTest extends SysuiTestCase {

    @Test
    @UiThreadTest
    public void testBindNotification_ChannelDisabledTextHiddenWhenDefaultChannel()
    public void testBindNotification_ChannelDisabledTextShowsForDefaultChannel()
            throws Exception {
        mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
        mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
                TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null);
        final TextView channelDisabledView =
                (TextView) mNotificationInfo.findViewById(R.id.channel_disabled);
        assertTrue(channelDisabledView.getVisibility() != View.VISIBLE);
        assertEquals(View.VISIBLE, channelDisabledView.getVisibility());
    }

    @Test