Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2356)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java

Issue 2859233002: [Android] Refactor our notification channel definitions (Closed)
Patch Set: Nits, and made ChannelsUpdaterTest more powerful again by mocking resources Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java
index d7a9d36a08829efb209da65e37543e5a96063d23..e88a699c318ff7eedd4853d03085eeacd2377679 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/channels/ChannelsInitializer.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.notifications.channels;
+import android.content.res.Resources;
+
import org.chromium.chrome.browser.notifications.NotificationManagerProxy;
/**
@@ -11,20 +13,20 @@ import org.chromium.chrome.browser.notifications.NotificationManagerProxy;
*/
public class ChannelsInitializer {
private final NotificationManagerProxy mNotificationManager;
- private final ChannelDefinitions mChannelDefinitions;
+ private final Resources mResources;
- public ChannelsInitializer(NotificationManagerProxy notificationManagerProxy,
- ChannelDefinitions channelDefinitions) {
+ public ChannelsInitializer(
+ NotificationManagerProxy notificationManagerProxy, Resources resources) {
mNotificationManager = notificationManagerProxy;
- mChannelDefinitions = channelDefinitions;
+ mResources = resources;
}
/**
* Creates all the channels on the notification manager that we want to appear in our
* channel settings from first launch onwards.
*/
- public void initializeStartupChannels() {
- for (String channelId : mChannelDefinitions.getStartupChannelIds()) {
+ void initializeStartupChannels() {
+ for (String channelId : ChannelDefinitions.getStartupChannelIds()) {
ensureInitialized(channelId);
}
}
@@ -34,7 +36,7 @@ public class ChannelsInitializer {
* It's safe to call this multiple times since deleting an already-deleted channel is a no-op.
*/
void deleteLegacyChannels() {
- for (String channelId : mChannelDefinitions.getLegacyChannelIds()) {
+ for (String channelId : ChannelDefinitions.getLegacyChannelIds()) {
mNotificationManager.deleteNotificationChannel(channelId);
}
}
@@ -49,13 +51,14 @@ public class ChannelsInitializer {
* @param channelId The ID of the channel to be initialized.
*/
public void ensureInitialized(@ChannelDefinitions.ChannelId String channelId) {
- ChannelDefinitions.Channel channel = mChannelDefinitions.getChannelFromId(channelId);
- if (channel == null) {
+ ChannelDefinitions.PredefinedChannel predefinedChannel =
+ ChannelDefinitions.getChannelFromId(channelId);
+ if (predefinedChannel == null) {
throw new IllegalStateException("Could not initialize channel: " + channelId);
}
// Channel group must be created before the channel.
mNotificationManager.createNotificationChannelGroup(
- mChannelDefinitions.getChannelGroupFromId(channel));
- mNotificationManager.createNotificationChannel(channel);
+ ChannelDefinitions.getChannelGroupFromId(predefinedChannel));
+ mNotificationManager.createNotificationChannel(predefinedChannel.toChannel(mResources));
}
}

Powered by Google App Engine
This is Rietveld 408576698