diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt index 314d537be7..f72c82dd83 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt @@ -84,9 +84,9 @@ class BackupNotifier(private val context: Context) { val builder = with(progressNotificationBuilder) { setContentTitle(context.getString(R.string.restoring_backup)) - // if (!preferences.hideNotificationContent()) { - setContentText(content) - // } + if (!preferences.hideNotificationContent()) { + setContentText(content) + } setProgress(maxAmount, progress, false) setOnlyAlertOnce(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt index f26b9c1e5f..63c93823be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt @@ -11,8 +11,10 @@ import eu.kanade.tachiyomi.data.download.model.Download 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.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.system.notificationManager +import uy.kohesive.injekt.injectLazy import java.util.regex.Pattern /** @@ -21,6 +23,9 @@ import java.util.regex.Pattern * @param context context of application */ internal class DownloadNotifier(private val context: Context) { + + private val preferences: PreferencesHelper by injectLazy() + /** * Notification builder. */ @@ -53,15 +58,6 @@ internal class DownloadNotifier(private val context: Context) { context.notificationManager.notify(id, build()) } - /** - * Clear old actions if they exist. - */ - private fun clearActions() = with(notification) { - if (!mActions.isEmpty()) { - mActions.clear() - } - } - /** * Dismiss the downloader's notification. Downloader error notifications use a different id, so * those can only be dismissed by the user. @@ -89,7 +85,7 @@ internal class DownloadNotifier(private val context: Context) { ) } - if (download != null) { + if (download != null && !preferences.hideNotificationContent()) { val title = download.manga.title.chop(15) val quotedTitle = Pattern.quote(title) val chapter = download.chapter.name.replaceFirst( @@ -141,17 +137,22 @@ internal class DownloadNotifier(private val context: Context) { ) } - val title = download.manga.title.chop(15) - val quotedTitle = Pattern.quote(title) - val chapter = download.chapter.name.replaceFirst( - "$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), - "" - ) - setContentTitle("$title - $chapter".chop(30)) - setContentText( + val downloadingProgressText = context.getString(R.string.downloading_progress) .format(download.downloadedImages, download.pages!!.size) - ) + + if (preferences.hideNotificationContent()) { + setContentTitle(downloadingProgressText) + } else { + val title = download.manga.title.chop(15) + val quotedTitle = Pattern.quote(title) + val chapter = download.chapter.name.replaceFirst( + "$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), + "" + ) + setContentTitle("$title - $chapter".chop(30)) + setContentText(downloadingProgressText) + } setStyle(null) setProgress(download.pages!!.size, download.downloadedImages, false) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index ec1982f976..6df0679430 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -75,7 +75,11 @@ class LibraryUpdateNotifier(private val context: Context) { * @param total the total progress. */ fun showProgressNotification(manga: Manga, current: Int, total: Int) { - val title = manga.title + val title = if (preferences.hideNotificationContent()) { + context.getString(R.string.checking_for_new_chapters) + } else { + manga.title + } context.notificationManager.notify( Notifications.ID_LIBRARY_PROGRESS, @@ -129,72 +133,78 @@ class LibraryUpdateNotifier(private val context: Context) { val updates = newUpdates.toImmutableMap() GlobalScope.launch { val notifications = ArrayList>() - updates.forEach { - val manga = it.key - val chapters = it.value - val chapterNames = chapters.map { chapter -> chapter.name } - notifications.add( - Pair( - context.notification(Notifications.CHANNEL_NEW_CHAPTERS) { - setSmallIcon(R.drawable.ic_tachi) - try { - val request = ImageRequest.Builder(context).data(manga) - .parameters(Parameters.Builder().set(MangaFetcher.onlyCache, true).build()) - .networkCachePolicy(CachePolicy.READ_ONLY) - .transformations(CircleCropTransformation()) - .size(width = ICON_SIZE, height = ICON_SIZE).build() + if (!preferences.hideNotificationContent()) { + updates.forEach { + val manga = it.key + val chapters = it.value + val chapterNames = chapters.map { chapter -> chapter.name } + notifications.add( + Pair( + context.notification(Notifications.CHANNEL_NEW_CHAPTERS) { + setSmallIcon(R.drawable.ic_tachi) + try { + val request = ImageRequest.Builder(context).data(manga) + .parameters( + Parameters.Builder().set(MangaFetcher.onlyCache, true) + .build() + ) + .networkCachePolicy(CachePolicy.READ_ONLY) + .transformations(CircleCropTransformation()) + .size(width = ICON_SIZE, height = ICON_SIZE).build() - Coil.imageLoader(context).execute(request).drawable?.let { drawable -> - setLargeIcon((drawable as BitmapDrawable).bitmap) + Coil.imageLoader(context) + .execute(request).drawable?.let { drawable -> + setLargeIcon((drawable as BitmapDrawable).bitmap) + } + } catch (e: Exception) { } - } catch (e: Exception) { - } - setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) - setContentTitle(manga.title) - color = ContextCompat.getColor(context, R.color.colorAccent) - val chaptersNames = if (chapterNames.size > MAX_CHAPTERS) { - "${chapterNames.take(MAX_CHAPTERS - 1).joinToString(", ")}, " + - context.resources.getQuantityString( - R.plurals.notification_and_n_more, - (chapterNames.size - (MAX_CHAPTERS - 1)), - (chapterNames.size - (MAX_CHAPTERS - 1)) + setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) + setContentTitle(manga.title) + color = ContextCompat.getColor(context, R.color.colorAccent) + val chaptersNames = if (chapterNames.size > MAX_CHAPTERS) { + "${chapterNames.take(MAX_CHAPTERS - 1).joinToString(", ")}, " + + context.resources.getQuantityString( + R.plurals.notification_and_n_more, + (chapterNames.size - (MAX_CHAPTERS - 1)), + (chapterNames.size - (MAX_CHAPTERS - 1)) + ) + } else chapterNames.joinToString(", ") + setContentText(chaptersNames) + setStyle(NotificationCompat.BigTextStyle().bigText(chaptersNames)) + priority = NotificationCompat.PRIORITY_HIGH + setGroup(Notifications.GROUP_NEW_CHAPTERS) + setContentIntent( + NotificationReceiver.openChapterPendingActivity( + context, + manga, + chapters.first() ) - } else chapterNames.joinToString(", ") - setContentText(chaptersNames) - setStyle(NotificationCompat.BigTextStyle().bigText(chaptersNames)) - priority = NotificationCompat.PRIORITY_HIGH - setGroup(Notifications.GROUP_NEW_CHAPTERS) - setContentIntent( - NotificationReceiver.openChapterPendingActivity( - context, - manga, - chapters.first() ) - ) - addAction( - R.drawable.ic_eye_24dp, - context.getString(R.string.mark_as_read), - NotificationReceiver.markAsReadPendingBroadcast( - context, - manga, - chapters, - Notifications.ID_NEW_CHAPTERS + addAction( + R.drawable.ic_eye_24dp, + context.getString(R.string.mark_as_read), + NotificationReceiver.markAsReadPendingBroadcast( + context, + manga, + chapters, + Notifications.ID_NEW_CHAPTERS + ) ) - ) - addAction( - R.drawable.ic_book_24dp, - context.getString(R.string.view_chapters), - NotificationReceiver.openChapterPendingActivity( - context, - manga, - Notifications.ID_NEW_CHAPTERS + addAction( + R.drawable.ic_book_24dp, + context.getString(R.string.view_chapters), + NotificationReceiver.openChapterPendingActivity( + context, + manga, + Notifications.ID_NEW_CHAPTERS + ) ) - ) - setAutoCancel(true) - }, - manga.id.hashCode() + setAutoCancel(true) + }, + manga.id.hashCode() + ) ) - ) + } } NotificationManagerCompat.from(context).apply { @@ -213,15 +223,17 @@ class LibraryUpdateNotifier(private val context: Context) { updates.size ) ) - setStyle( - NotificationCompat.BigTextStyle() - .bigText( - updates.keys.joinToString("\n") { - it.title.chop(45) - } - ) - ) - } else { + if (!preferences.hideNotificationContent()) { + setStyle( + NotificationCompat.BigTextStyle() + .bigText( + updates.keys.joinToString("\n") { + it.title.chop(45) + } + ) + ) + } + } else if (!preferences.hideNotificationContent()) { setContentText(updates.keys.first().title.chop(45)) } priority = NotificationCompat.PRIORITY_HIGH diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index dd1e567b53..efed769540 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -185,6 +185,8 @@ object PreferenceKeys { const val secureScreen = "secure_screen" + const val hideNotificationContent = "hide_notification_content" + const val removeArticles = "remove_articles" const val skipPreMigration = "skip_pre_migration" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index a361abcbd8..e8a75d0f7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -320,6 +320,8 @@ class PreferencesHelper(val context: Context) { fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false) + fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false) + fun removeArticles() = rxPrefs.getBoolean(Keys.removeArticles, false) fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt index 190a77a833..d6a0950b3f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -58,5 +58,10 @@ class SettingsSecurityController : SettingsController() { true } } + switchPreference { + key = PreferenceKeys.hideNotificationContent + titleRes = R.string.hide_notification_content + defaultValue = false + } } }