Skip to content

Commit

Permalink
Combine initNotificationChannel() and setUpUpdateNotificationChannel(…
Browse files Browse the repository at this point in the history
…) into a single method.
  • Loading branch information
Isira-Seneviratne committed Sep 21, 2020
1 parent 20f1297 commit 811c790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
48 changes: 15 additions & 33 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.schabi.newpipe;

import android.annotation.TargetApi;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand Down Expand Up @@ -33,6 +32,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -90,7 +90,7 @@ public void onCreate() {
Localization.init(getApplicationContext());

StateSaver.init(this);
initNotificationChannel();
initNotificationChannels();

ServiceHelper.initServices(this);

Expand Down Expand Up @@ -219,48 +219,30 @@ protected void initACRA() {
}
}

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() {
Expand Down
2 changes: 1 addition & 1 deletion checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<suppress checks="LineLength"
files="App.java"
lines="237"/>
lines="245"/>

<!-- org.schabi.newpipe.streams -->
<suppress checks="LineLength"
Expand Down

0 comments on commit 811c790

Please sign in to comment.