From f3d69599aa09917b2261207f1d0b3ab25412d86b Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 4 Mar 2020 18:55:19 -0500 Subject: [PATCH] Add setting to hide manga content from update/download notifications --- .../data/download/DownloadNotifier.kt | 24 ++++++++++++----- .../data/library/LibraryUpdateService.kt | 26 +++++++++++++------ .../data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferencesHelper.kt | 2 ++ .../ui/setting/SettingsGeneralController.kt | 5 ++++ app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 47 insertions(+), 14 deletions(-) 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 9c22626f2b..7000f79e30 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 @@ -8,10 +8,13 @@ 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.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationManager import java.util.regex.Pattern +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get /** * DownloadNotifier is used to show notifications when downloading one or multiple chapters. @@ -24,6 +27,8 @@ internal class DownloadNotifier(private val context: Context) { setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher)) } + private val preferences by lazy { Injekt.get() } + /** * Status of download. Used for correct notification icon. */ @@ -87,12 +92,19 @@ internal class DownloadNotifier(private val context: Context) { NotificationReceiver.pauseDownloadsPendingBroadcast(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(context.getString(R.string.chapter_downloading_progress) - .format(download.downloadedImages, download.pages!!.size)) + val downloadingProgressText = context.getString(R.string.chapter_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) + } + setProgress(download.pages!!.size, download.downloadedImages, false) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 5b14921bc4..7c1b94d2da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -448,8 +448,13 @@ class LibraryUpdateService( * @param total the total progress. */ private fun showProgressNotification(manga: Manga, current: Int, total: Int) { + val title = if (preferences.hideNotificationContent()) + getString(R.string.notification_check_updates) + else + manga.title + notificationManager.notify(Notifications.ID_LIBRARY_PROGRESS, progressNotificationBuilder - .setContentTitle(manga.title) + .setContentTitle(title) .setProgress(total, current, false) .build()) } @@ -468,13 +473,16 @@ class LibraryUpdateService( // Parent group notification notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) { setContentTitle(getString(R.string.notification_new_chapters)) - if (updates.size == 1) { + if (updates.size == 1 && !preferences.hideNotificationContent()) { setContentText(updates.first().first.title.chop(NOTIF_TITLE_MAX_LEN)) } else { setContentText(resources.getQuantityString(R.plurals.notification_new_chapters_text, updates.size, updates.size)) - setStyle(NotificationCompat.BigTextStyle().bigText(updates.joinToString("\n") { - it.first.title.chop(NOTIF_TITLE_MAX_LEN) - })) + + if (!preferences.hideNotificationContent()) { + setStyle(NotificationCompat.BigTextStyle().bigText(updates.joinToString("\n") { + it.first.title.chop(NOTIF_TITLE_MAX_LEN) + })) + } } setSmallIcon(R.drawable.ic_tachi) @@ -490,9 +498,11 @@ class LibraryUpdateService( }) // Per-manga notification - updates.forEach { - val (manga, chapters) = it - notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters)) + if (!preferences.hideNotificationContent()) { + updates.forEach { + val (manga, chapters) = it + notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters)) + } } } } 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 26bb85c76b..219bb847e2 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 @@ -115,6 +115,8 @@ object PreferenceKeys { const val secureScreen = "secure_screen" + const val hideNotificationContent = "hide_notification_content" + const val downloadNew = "download_new" const val downloadNewCategories = "download_new_categories" 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 97502ce66a..7d5b62b240 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 @@ -59,6 +59,8 @@ class PreferencesHelper(val context: Context) { fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false) + fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false) + fun clear() = prefs.edit().clear().apply() fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index a0bdd2c55c..1962ee2040 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -180,6 +180,11 @@ class SettingsGeneralController : SettingsController() { summaryRes = R.string.secure_screen_summary defaultValue = false } + switchPreference { + key = Keys.hideNotificationContent + titleRes = R.string.hide_notification_content + defaultValue = false + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1904d2c0ef..0560ad965a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,7 @@ Secure screen Hide app contents when switching apps and block screenshots + Hide notification content Display @@ -505,6 +506,7 @@ Could not download chapters. You can try again in the downloads section + Checking for new chapters Update progress: %1$d/%2$d New chapters found