Skip to content

Commit

Permalink
Use NotificationChannelCompat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Aug 1, 2021
1 parent d57bfde commit a4c207f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"

/** AndroidX **/
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.3.2'
Expand Down
56 changes: 24 additions & 32 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.schabi.newpipe;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.multidex.MultiDexApplication;
import androidx.preference.PreferenceManager;

Expand Down Expand Up @@ -233,38 +232,31 @@ protected void initACRA() {
}

private void initNotificationChannels() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

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 for the main
// and update channels
int importance = NotificationManager.IMPORTANCE_LOW;

final NotificationChannel mainChannel = new NotificationChannel(id, name, importance);
mainChannel.setDescription(description);

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);

final NotificationChannel appUpdateChannel = new NotificationChannel(id, name, importance);
appUpdateChannel.setDescription(description);
// Keep the importance below DEFAULT to avoid making noise on every notification update for
// the main and update channels
final NotificationChannelCompat mainChannel = new NotificationChannelCompat
.Builder(getString(R.string.notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.notification_channel_name))
.setDescription(getString(R.string.notification_channel_description))
.build();

id = getString(R.string.hash_channel_id);
name = getString(R.string.hash_channel_name);
description = getString(R.string.hash_channel_description);
importance = NotificationManager.IMPORTANCE_HIGH;
final NotificationChannelCompat appUpdateChannel = new NotificationChannelCompat
.Builder(getString(R.string.app_update_notification_channel_id),
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getString(R.string.app_update_notification_channel_name))
.setDescription(getString(R.string.app_update_notification_channel_description))
.build();

final NotificationChannel hashChannel = new NotificationChannel(id, name, importance);
hashChannel.setDescription(description);
final NotificationChannelCompat hashChannel = new NotificationChannelCompat
.Builder(getString(R.string.hash_channel_id),
NotificationManagerCompat.IMPORTANCE_HIGH)
.setName(getString(R.string.hash_channel_name))
.setDescription(getString(R.string.hash_channel_description))
.build();

final NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannels(Arrays.asList(mainChannel,
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.createNotificationChannelsCompat(Arrays.asList(mainChannel,
appUpdateChannel, hashChannel));
}

Expand Down

0 comments on commit a4c207f

Please sign in to comment.