From f55381d689f3702ae084f3813cc286a65fd79aeb Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 16 Sep 2020 19:03:15 +0530 Subject: [PATCH] Combine initNotificationChannel() and setUpUpdateNotificationChannel() into a single method. --- app/src/main/java/org/schabi/newpipe/App.java | 49 ++++++------------- checkstyle-suppressions.xml | 4 -- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index dd578d911..4b2a858c7 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -1,6 +1,5 @@ package org.schabi.newpipe; -import android.annotation.TargetApi; import android.app.Application; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -33,6 +32,7 @@ import org.schabi.newpipe.util.StateSaver; import java.io.IOException; import java.io.InterruptedIOException; import java.net.SocketException; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -90,7 +90,7 @@ public class App extends Application { Localization.init(getApplicationContext()); StateSaver.init(this); - initNotificationChannel(); + initNotificationChannels(); ServiceHelper.initServices(this); @@ -219,48 +219,31 @@ public class App extends Application { } } - public void initNotificationChannel() { + private void initNotificationChannels() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } - final String id = getString(R.string.notification_channel_id); - final CharSequence name = getString(R.string.notification_channel_name); - final String description = getString(R.string.notification_channel_description); + String id = getString(R.string.notification_channel_id); + String name = getString(R.string.notification_channel_name); + String description = getString(R.string.notification_channel_description); // Keep this below DEFAULT to avoid making noise on every notification update final int importance = NotificationManager.IMPORTANCE_LOW; - final NotificationChannel mChannel = new NotificationChannel(id, name, importance); - mChannel.setDescription(description); + final NotificationChannel mainChannel = new NotificationChannel(id, name, importance); + mainChannel.setDescription(description); - final NotificationManager mNotificationManager = getSystemService(NotificationManager.class); - mNotificationManager.createNotificationChannel(mChannel); + id = getString(R.string.app_update_notification_channel_id); + name = getString(R.string.app_update_notification_channel_name); + description = getString(R.string.app_update_notification_channel_description); - setUpUpdateNotificationChannel(importance); - } + final NotificationChannel appUpdateChannel = new NotificationChannel(id, name, importance); + appUpdateChannel.setDescription(description); - /** - * Set up notification channel for app update. - * - * @param importance - */ - @TargetApi(Build.VERSION_CODES.O) - private void setUpUpdateNotificationChannel(final int importance) { - final String appUpdateId - = getString(R.string.app_update_notification_channel_id); - final CharSequence appUpdateName - = getString(R.string.app_update_notification_channel_name); - final String appUpdateDescription - = getString(R.string.app_update_notification_channel_description); - - final NotificationChannel appUpdateChannel - = new NotificationChannel(appUpdateId, appUpdateName, importance); - appUpdateChannel.setDescription(appUpdateDescription); - - final NotificationManager appUpdateNotificationManager - = getSystemService(NotificationManager.class); - appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); + final NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannels(Arrays.asList(mainChannel, + appUpdateChannel)); } protected boolean isDisposedRxExceptionsReported() { diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index f83c5e598..70a2afe73 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -15,10 +15,6 @@ files="ListHelper.java" lines="282,314"/> - -