mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-26 10:58:24 +01:00
Remove unnecessary usages of NotificationManagerCompat to actually create notifications
This commit is contained in:
parent
dd71c76a8f
commit
d400ac2a49
@ -11,7 +11,6 @@ import android.content.IntentFilter
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.core.app.NotificationManagerCompat
|
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
@ -43,6 +42,7 @@ import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
|||||||
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
|
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
|
||||||
import eu.kanade.tachiyomi.util.system.isReleaseBuildType
|
import eu.kanade.tachiyomi.util.system.isReleaseBuildType
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
@ -96,7 +96,6 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
// Show notification to disable Incognito Mode when it's enabled
|
// Show notification to disable Incognito Mode when it's enabled
|
||||||
basePreferences.incognitoMode().changes()
|
basePreferences.incognitoMode().changes()
|
||||||
.onEach { enabled ->
|
.onEach { enabled ->
|
||||||
val notificationManager = NotificationManagerCompat.from(this)
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
disableIncognitoReceiver.register()
|
disableIncognitoReceiver.register()
|
||||||
val notification = notification(Notifications.CHANNEL_INCOGNITO_MODE) {
|
val notification = notification(Notifications.CHANNEL_INCOGNITO_MODE) {
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.BitmapFactory
|
|||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
|
||||||
import coil.imageLoader
|
import coil.imageLoader
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import coil.transform.CircleCropTransformation
|
import coil.transform.CircleCropTransformation
|
||||||
@ -158,47 +157,45 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
* @param updates a list of manga with new updates.
|
* @param updates a list of manga with new updates.
|
||||||
*/
|
*/
|
||||||
fun showUpdateNotifications(updates: List<Pair<Manga, Array<Chapter>>>) {
|
fun showUpdateNotifications(updates: List<Pair<Manga, Array<Chapter>>>) {
|
||||||
NotificationManagerCompat.from(context).apply {
|
// Parent group notification
|
||||||
// Parent group notification
|
context.notificationManager.notify(
|
||||||
notify(
|
Notifications.ID_NEW_CHAPTERS,
|
||||||
Notifications.ID_NEW_CHAPTERS,
|
context.notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
context.notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
setContentTitle(context.getString(R.string.notification_new_chapters))
|
||||||
setContentTitle(context.getString(R.string.notification_new_chapters))
|
if (updates.size == 1 && !preferences.hideNotificationContent().get()) {
|
||||||
if (updates.size == 1 && !preferences.hideNotificationContent().get()) {
|
setContentText(updates.first().first.title.chop(NOTIF_TITLE_MAX_LEN))
|
||||||
setContentText(updates.first().first.title.chop(NOTIF_TITLE_MAX_LEN))
|
} else {
|
||||||
} else {
|
setContentText(context.resources.getQuantityString(R.plurals.notification_new_chapters_summary, updates.size, updates.size))
|
||||||
setContentText(context.resources.getQuantityString(R.plurals.notification_new_chapters_summary, updates.size, updates.size))
|
|
||||||
|
|
||||||
if (!preferences.hideNotificationContent().get()) {
|
if (!preferences.hideNotificationContent().get()) {
|
||||||
setStyle(
|
setStyle(
|
||||||
NotificationCompat.BigTextStyle().bigText(
|
NotificationCompat.BigTextStyle().bigText(
|
||||||
updates.joinToString("\n") {
|
updates.joinToString("\n") {
|
||||||
it.first.title.chop(NOTIF_TITLE_MAX_LEN)
|
it.first.title.chop(NOTIF_TITLE_MAX_LEN)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
setLargeIcon(notificationBitmap)
|
setLargeIcon(notificationBitmap)
|
||||||
|
|
||||||
setGroup(Notifications.GROUP_NEW_CHAPTERS)
|
setGroup(Notifications.GROUP_NEW_CHAPTERS)
|
||||||
setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
|
setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
|
||||||
setGroupSummary(true)
|
setGroupSummary(true)
|
||||||
priority = NotificationCompat.PRIORITY_HIGH
|
priority = NotificationCompat.PRIORITY_HIGH
|
||||||
|
|
||||||
setContentIntent(getNotificationIntent())
|
setContentIntent(getNotificationIntent())
|
||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// Per-manga notification
|
// Per-manga notification
|
||||||
if (!preferences.hideNotificationContent().get()) {
|
if (!preferences.hideNotificationContent().get()) {
|
||||||
launchUI {
|
launchUI {
|
||||||
updates.forEach { (manga, chapters) ->
|
updates.forEach { (manga, chapters) ->
|
||||||
notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters))
|
context.notificationManager.notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,33 @@
|
|||||||
package eu.kanade.tachiyomi.extension.api
|
package eu.kanade.tachiyomi.extension.api
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationManagerCompat
|
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
|
|
||||||
class ExtensionUpdateNotifier(private val context: Context) {
|
class ExtensionUpdateNotifier(private val context: Context) {
|
||||||
|
|
||||||
fun promptUpdates(names: List<String>) {
|
fun promptUpdates(names: List<String>) {
|
||||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
context.notificationManager.notify(
|
||||||
return
|
Notifications.ID_UPDATES_TO_EXTS,
|
||||||
}
|
context.notification(Notifications.CHANNEL_EXTENSIONS_UPDATE) {
|
||||||
|
setContentTitle(
|
||||||
NotificationManagerCompat.from(context).apply {
|
context.resources.getQuantityString(
|
||||||
notify(
|
R.plurals.update_check_notification_ext_updates,
|
||||||
Notifications.ID_UPDATES_TO_EXTS,
|
names.size,
|
||||||
context.notification(Notifications.CHANNEL_EXTENSIONS_UPDATE) {
|
names.size,
|
||||||
setContentTitle(
|
),
|
||||||
context.resources.getQuantityString(
|
)
|
||||||
R.plurals.update_check_notification_ext_updates,
|
val extNames = names.joinToString(", ")
|
||||||
names.size,
|
setContentText(extNames)
|
||||||
names.size,
|
setStyle(NotificationCompat.BigTextStyle().bigText(extNames))
|
||||||
),
|
setSmallIcon(R.drawable.ic_extension_24dp)
|
||||||
)
|
setContentIntent(NotificationReceiver.openExtensionsPendingActivity(context))
|
||||||
val extNames = names.joinToString(", ")
|
setAutoCancel(true)
|
||||||
setContentText(extNames)
|
},
|
||||||
setStyle(NotificationCompat.BigTextStyle().bigText(extNames))
|
)
|
||||||
setSmallIcon(R.drawable.ic_extension_24dp)
|
|
||||||
setContentIntent(NotificationReceiver.openExtensionsPendingActivity(context))
|
|
||||||
setAutoCancel(true)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user