|
@@ -1,12 +1,14 @@
|
|
|
package eu.kanade.tachiyomi.util.system
|
|
|
|
|
|
import android.Manifest
|
|
|
+import android.app.Notification
|
|
|
import android.app.NotificationManager
|
|
|
import android.content.Context
|
|
|
import androidx.core.app.NotificationChannelCompat
|
|
|
import androidx.core.app.NotificationChannelGroupCompat
|
|
|
import androidx.core.app.NotificationCompat
|
|
|
import androidx.core.app.NotificationManagerCompat
|
|
|
+import androidx.core.app.NotificationManagerCompat.NotificationWithIdAndTag
|
|
|
import androidx.core.content.PermissionChecker
|
|
|
import androidx.core.content.getSystemService
|
|
|
import eu.kanade.tachiyomi.R
|
|
@@ -15,14 +17,26 @@ val Context.notificationManager: NotificationManager
|
|
|
get() = getSystemService()!!
|
|
|
|
|
|
fun Context.notify(id: Int, channelId: String, block: (NotificationCompat.Builder.() -> Unit)? = null) {
|
|
|
+ val notification = notificationBuilder(channelId, block).build()
|
|
|
+ this.notify(id, notification)
|
|
|
+}
|
|
|
+
|
|
|
+fun Context.notify(id: Int, notification: Notification) {
|
|
|
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- val notification = notificationBuilder(channelId, block).build()
|
|
|
NotificationManagerCompat.from(this).notify(id, notification)
|
|
|
}
|
|
|
|
|
|
+fun Context.notify(notificationWithIdAndTags: List<NotificationWithIdAndTag>) {
|
|
|
+ if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ NotificationManagerCompat.from(this).notify(notificationWithIdAndTags)
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Helper method to create a notification builder.
|
|
|
*
|