parent
e932983494
commit
1986042277
10 changed files with 38 additions and 30 deletions
|
@ -38,9 +38,9 @@ import eu.kanade.tachiyomi.network.NetworkPreferences
|
|||
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
||||
import eu.kanade.tachiyomi.util.system.animatorDurationScale
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
|
||||
import eu.kanade.tachiyomi.util.system.isReleaseBuildType
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
@ -116,7 +116,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||
}
|
||||
} else {
|
||||
disableIncognitoReceiver.unregister()
|
||||
notificationManager.cancel(Notifications.ID_INCOGNITO_MODE)
|
||||
cancelNotification(Notifications.ID_INCOGNITO_MODE)
|
||||
}
|
||||
}
|
||||
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
|
||||
|
|
|
@ -13,8 +13,8 @@ import androidx.work.WorkerParameters
|
|||
import androidx.work.workDataOf
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.isRunning
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.workManager
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.util.system.logcat
|
||||
|
@ -50,7 +50,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
|
|||
if (!isAutoBackup) notifier.showBackupError(e.message)
|
||||
Result.failure()
|
||||
} finally {
|
||||
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
|
@ -51,7 +51,7 @@ class BackupNotifier(private val context: Context) {
|
|||
}
|
||||
|
||||
fun showBackupError(error: String?) {
|
||||
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
|
||||
|
||||
with(completeNotificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.creating_backup_error))
|
||||
|
@ -62,7 +62,7 @@ class BackupNotifier(private val context: Context) {
|
|||
}
|
||||
|
||||
fun showBackupComplete(unifile: UniFile) {
|
||||
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_BACKUP_PROGRESS)
|
||||
|
||||
with(completeNotificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.backup_created))
|
||||
|
@ -104,7 +104,7 @@ class BackupNotifier(private val context: Context) {
|
|||
}
|
||||
|
||||
fun showRestoreError(error: String?) {
|
||||
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
|
||||
with(completeNotificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.restoring_backup_error))
|
||||
|
@ -115,7 +115,7 @@ class BackupNotifier(private val context: Context) {
|
|||
}
|
||||
|
||||
fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) {
|
||||
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
|
||||
val timeString = context.getString(
|
||||
R.string.restore_duration,
|
||||
|
|
|
@ -11,8 +11,8 @@ import androidx.work.WorkerParameters
|
|||
import androidx.work.workDataOf
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.isRunning
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.workManager
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import logcat.LogPriority
|
||||
|
@ -47,7 +47,7 @@ class BackupRestoreJob(private val context: Context, workerParams: WorkerParamet
|
|||
Result.failure()
|
||||
}
|
||||
} finally {
|
||||
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.lang.chop
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.regex.Pattern
|
||||
|
@ -59,7 +59,7 @@ internal class DownloadNotifier(private val context: Context) {
|
|||
* those can only be dismissed by the user.
|
||||
*/
|
||||
fun dismissProgress() {
|
||||
context.notificationManager.cancel(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,8 +21,8 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
|||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.util.lang.chop
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import tachiyomi.core.Constants
|
||||
import tachiyomi.core.util.lang.launchUI
|
||||
|
@ -265,7 +265,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
* Cancels the progress notification.
|
||||
*/
|
||||
fun cancelProgressNotification() {
|
||||
context.notificationManager.cancel(Notifications.ID_LIBRARY_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_LIBRARY_PROGRESS)
|
||||
}
|
||||
|
||||
private suspend fun getMangaIcon(manga: Manga): Bitmap? {
|
||||
|
|
|
@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity
|
|||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.toShareIntent
|
||||
|
@ -135,7 +136,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||
* @param notificationId the id of the notification
|
||||
*/
|
||||
private fun dismissNotification(context: Context, notificationId: Int) {
|
||||
context.notificationManager.cancel(notificationId)
|
||||
context.cancelNotification(notificationId)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,13 +381,13 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||
}
|
||||
|
||||
if (notifications.size == 2) {
|
||||
context.notificationManager.cancel(groupId)
|
||||
context.cancelNotification(groupId)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.notificationManager.cancel(notificationId)
|
||||
context.cancelNotification(notificationId)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,8 +12,8 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ class SaveImageNotifier(private val context: Context) {
|
|||
* Clears the notification message.
|
||||
*/
|
||||
fun onClear() {
|
||||
context.notificationManager.cancel(notificationId)
|
||||
context.cancelNotification(notificationId)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,8 +8,8 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.createFileInCacheDir
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.notify
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import tachiyomi.core.util.lang.withNonCancellableContext
|
||||
|
@ -43,7 +43,7 @@ class CrashLogUtil(private val context: Context) {
|
|||
}
|
||||
|
||||
private fun showNotification(uri: Uri) {
|
||||
context.notificationManager.cancel(Notifications.ID_CRASH_LOGS)
|
||||
context.cancelNotification(Notifications.ID_CRASH_LOGS)
|
||||
|
||||
context.notify(
|
||||
Notifications.ID_CRASH_LOGS,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.kanade.tachiyomi.util.system
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
|
@ -9,7 +9,6 @@ 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
|
||||
|
||||
|
@ -21,22 +20,30 @@ fun Context.notify(id: Int, channelId: String, block: (NotificationCompat.Builde
|
|||
this.notify(id, notification)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun Context.notify(id: Int, notification: Notification) {
|
||||
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
||||
return
|
||||
}
|
||||
// TODO: check for permission once targeting SDK 33+
|
||||
// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
||||
// return
|
||||
// }
|
||||
|
||||
NotificationManagerCompat.from(this).notify(id, notification)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun Context.notify(notificationWithIdAndTags: List<NotificationWithIdAndTag>) {
|
||||
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
||||
return
|
||||
}
|
||||
// TODO: check for permission once targeting SDK 33+
|
||||
// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
|
||||
// return
|
||||
// }
|
||||
|
||||
NotificationManagerCompat.from(this).notify(notificationWithIdAndTags)
|
||||
}
|
||||
|
||||
fun Context.cancelNotification(id: Int) {
|
||||
NotificationManagerCompat.from(this).cancel(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a notification builder.
|
||||
*
|
||||
|
|
Reference in a new issue