Merge "Notification channel group res id labels."
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index eecc77c..34745a7 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -161,12 +161,12 @@
} else {
for (NotificationChannelGroup group : mChannelGroupList) {
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
- if (group.getName() == null) {
+ if (group.getId() == null) {
groupCategory.setTitle(mChannelGroupList.size() > 1
? R.string.notification_channels_other
: R.string.notification_channels);
} else {
- groupCategory.setTitle(group.getName());
+ groupCategory.setTitle(getNotificationGroupLabel(group));
}
groupCategory.setKey(group.getId());
groupCategory.setOrderingAsAdded(true);
@@ -275,10 +275,10 @@
if (left.isDeleted() != right.isDeleted()) {
return Boolean.compare(left.isDeleted(), right.isDeleted());
}
- if (!Objects.equals(getNotificationChannelLabel(left),
- getNotificationChannelLabel(right))) {
- return sCollator.compare(getNotificationChannelLabel(left).toString(),
- getNotificationChannelLabel(right).toString());
+ CharSequence leftName = getNotificationChannelLabel(left);
+ CharSequence rightName = getNotificationChannelLabel(right);
+ if (!Objects.equals(leftName, rightName)) {
+ return sCollator.compare(leftName.toString(), rightName.toString());
}
return left.getId().compareTo(right.getId());
}
@@ -296,10 +296,11 @@
} else if (right.getId() == null && left.getId() != null) {
return -1;
}
+ CharSequence leftName = getNotificationGroupLabel(left);
+ CharSequence rightName = getNotificationGroupLabel(right);
// sort rest of the groups by name
- if (!Objects.equals(left.getName(), right.getName())) {
- return sCollator.compare(left.getName().toString(),
- right.getName().toString());
+ if (!Objects.equals(leftName, rightName)) {
+ return sCollator.compare(leftName.toString(), rightName.toString());
}
return left.getId().compareTo(right.getId());
}
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 099b4f4..38de27e 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -25,6 +25,7 @@
import android.app.Notification;
import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
@@ -249,13 +250,21 @@
}
}
+ protected CharSequence getNotificationGroupLabel(NotificationChannelGroup group) {
+ return getLabel(group.getName(), group.getNameResId());
+ }
+
protected CharSequence getNotificationChannelLabel(NotificationChannel channel) {
- if (channel.getName() != null) {
- return channel.getName();
+ return getLabel(channel.getName(), channel.getNameResId());
+ }
+
+ private CharSequence getLabel(CharSequence name, int nameResId) {
+ if (!TextUtils.isEmpty(name)) {
+ return name;
}
try {
ApplicationInfo info = mPm.getApplicationInfoAsUser(mAppRow.pkg, 0, mAppRow.userId);
- return mPm.getText(mAppRow.pkg, channel.getNameResId(), info);
+ return mPm.getText(mAppRow.pkg, nameResId, info);
} catch (NameNotFoundException e) {
e.printStackTrace();
}