1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

Combine initNotificationChannel() and setUpUpdateNotificationChannel() into a single method.

This commit is contained in:
Isira Seneviratne 2020-09-16 19:03:15 +05:30
parent c4084c4f97
commit f55381d689
2 changed files with 16 additions and 37 deletions

View File

@ -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() {

View File

@ -15,10 +15,6 @@
files="ListHelper.java"
lines="282,314"/>
<suppress checks="LineLength"
files="App.java"
lines="237"/>
<!-- org.schabi.newpipe.streams -->
<suppress checks="LineLength"
files="WebMWriter.java"