Show localized channel names

Test: manual
Change-Id: I85d60e564aeff8074cdb8138fe7ac1c078be986a
This commit is contained in:
Julia Reynolds
2017-03-01 16:59:10 -05:00
parent 6d3947e2c1
commit 3327eac198
4 changed files with 21 additions and 10 deletions

View File

@@ -182,13 +182,13 @@ public class AppNotificationSettings extends NotificationSettingsBase {
getPrefContext()); getPrefContext());
channelPref.setDisabledByAdmin(mSuspendedAppsAdmin); channelPref.setDisabledByAdmin(mSuspendedAppsAdmin);
channelPref.setKey(channel.getId()); channelPref.setKey(channel.getId());
channelPref.setTitle(channel.getName()); channelPref.setTitle(getNotificationChannelLabel(channel));
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE); channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
channelPref.setMultiLine(true); channelPref.setMultiLine(true);
if (channel.isDeleted()) { if (channel.isDeleted()) {
channelPref.setTitle( channelPref.setTitle(getString(R.string.deleted_channel_name,
getString(R.string.deleted_channel_name, channel.getName())); getNotificationChannelLabel(channel)));
channelPref.setEnabled(false); channelPref.setEnabled(false);
} else { } else {
channelPref.setSummary(getImportanceSummary(channel.getImportance())); channelPref.setSummary(getImportanceSummary(channel.getImportance()));
@@ -275,8 +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(left.getName(), right.getName())) { if (!Objects.equals(getNotificationChannelLabel(left),
return sCollator.compare(left.getName().toString(), right.getName().toString()); getNotificationChannelLabel(right))) {
return sCollator.compare(getNotificationChannelLabel(left).toString(),
getNotificationChannelLabel(right).toString());
} }
return left.getId().compareTo(right.getId()); return left.getId().compareTo(right.getId());
} }

View File

@@ -130,7 +130,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
.getApplicationFeatureProvider(activity) .getApplicationFeatureProvider(activity)
.newAppHeaderController(this /* fragment */, null /* appHeader */) .newAppHeaderController(this /* fragment */, null /* appHeader */)
.setIcon(mAppRow.icon) .setIcon(mAppRow.icon)
.setLabel(mChannel.getName()) .setLabel(getNotificationChannelLabel(mChannel))
.setSummary(mAppRow.label) .setSummary(mAppRow.label)
.setPackageName(mAppRow.pkg) .setPackageName(mAppRow.pkg)
.setUid(mAppRow.uid) .setUid(mAppRow.uid)

View File

@@ -155,8 +155,4 @@ public class NotificationBackend {
public boolean showBadge; public boolean showBadge;
public int userId; public int userId;
} }
public static class ChannelRow extends AppRow {
public NotificationChannel channel;
}
} }

View File

@@ -248,4 +248,17 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
return getContext().getString(R.string.notification_importance_high); return getContext().getString(R.string.notification_importance_high);
} }
} }
protected CharSequence getNotificationChannelLabel(NotificationChannel channel) {
if (channel.getName() != null) {
return channel.getName();
}
try {
ApplicationInfo info = mPm.getApplicationInfoAsUser(mAppRow.pkg, 0, mAppRow.userId);
return mPm.getText(mAppRow.pkg, channel.getNameResId(), info);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
} }