Merge "Notification channel group res id labels."
This commit is contained in:
committed by
Android (Google) Code Review
commit
e15ea49654
@@ -161,12 +161,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
} else {
|
} else {
|
||||||
for (NotificationChannelGroup group : mChannelGroupList) {
|
for (NotificationChannelGroup group : mChannelGroupList) {
|
||||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||||
if (group.getName() == null) {
|
if (group.getId() == null) {
|
||||||
groupCategory.setTitle(mChannelGroupList.size() > 1
|
groupCategory.setTitle(mChannelGroupList.size() > 1
|
||||||
? R.string.notification_channels_other
|
? R.string.notification_channels_other
|
||||||
: R.string.notification_channels);
|
: R.string.notification_channels);
|
||||||
} else {
|
} else {
|
||||||
groupCategory.setTitle(group.getName());
|
groupCategory.setTitle(getNotificationGroupLabel(group));
|
||||||
}
|
}
|
||||||
groupCategory.setKey(group.getId());
|
groupCategory.setKey(group.getId());
|
||||||
groupCategory.setOrderingAsAdded(true);
|
groupCategory.setOrderingAsAdded(true);
|
||||||
@@ -275,10 +275,10 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
if (left.isDeleted() != right.isDeleted()) {
|
if (left.isDeleted() != right.isDeleted()) {
|
||||||
return Boolean.compare(left.isDeleted(), right.isDeleted());
|
return Boolean.compare(left.isDeleted(), right.isDeleted());
|
||||||
}
|
}
|
||||||
if (!Objects.equals(getNotificationChannelLabel(left),
|
CharSequence leftName = getNotificationChannelLabel(left);
|
||||||
getNotificationChannelLabel(right))) {
|
CharSequence rightName = getNotificationChannelLabel(right);
|
||||||
return sCollator.compare(getNotificationChannelLabel(left).toString(),
|
if (!Objects.equals(leftName, rightName)) {
|
||||||
getNotificationChannelLabel(right).toString());
|
return sCollator.compare(leftName.toString(), rightName.toString());
|
||||||
}
|
}
|
||||||
return left.getId().compareTo(right.getId());
|
return left.getId().compareTo(right.getId());
|
||||||
}
|
}
|
||||||
@@ -296,10 +296,11 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
} else if (right.getId() == null && left.getId() != null) {
|
} else if (right.getId() == null && left.getId() != null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
CharSequence leftName = getNotificationGroupLabel(left);
|
||||||
|
CharSequence rightName = getNotificationGroupLabel(right);
|
||||||
// sort rest of the groups by name
|
// sort rest of the groups by name
|
||||||
if (!Objects.equals(left.getName(), right.getName())) {
|
if (!Objects.equals(leftName, rightName)) {
|
||||||
return sCollator.compare(left.getName().toString(),
|
return sCollator.compare(leftName.toString(), rightName.toString());
|
||||||
right.getName().toString());
|
|
||||||
}
|
}
|
||||||
return left.getId().compareTo(right.getId());
|
return left.getId().compareTo(right.getId());
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import com.android.settingslib.RestrictedSwitchPreference;
|
|||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationChannelGroup;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -249,13 +250,21 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CharSequence getNotificationGroupLabel(NotificationChannelGroup group) {
|
||||||
|
return getLabel(group.getName(), group.getNameResId());
|
||||||
|
}
|
||||||
|
|
||||||
protected CharSequence getNotificationChannelLabel(NotificationChannel channel) {
|
protected CharSequence getNotificationChannelLabel(NotificationChannel channel) {
|
||||||
if (channel.getName() != null) {
|
return getLabel(channel.getName(), channel.getNameResId());
|
||||||
return channel.getName();
|
}
|
||||||
|
|
||||||
|
private CharSequence getLabel(CharSequence name, int nameResId) {
|
||||||
|
if (!TextUtils.isEmpty(name)) {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ApplicationInfo info = mPm.getApplicationInfoAsUser(mAppRow.pkg, 0, mAppRow.userId);
|
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) {
|
} catch (NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user