Add setting to hide manga content from update/download notifications

This commit is contained in:
arkon 2020-03-04 18:55:19 -05:00
parent fc8f91baec
commit f3d69599aa
6 changed files with 47 additions and 14 deletions

View file

@ -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<PreferencesHelper>() }
/**
* 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)
}

View file

@ -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))
}
}
}
}

View file

@ -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"

View file

@ -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)

View file

@ -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
}
}
}
}

View file

@ -146,6 +146,7 @@
</plurals>
<string name="secure_screen">Secure screen</string>
<string name="secure_screen_summary">Hide app contents when switching apps and block screenshots</string>
<string name="hide_notification_content">Hide notification content</string>
<!-- Library section -->
<string name="pref_category_display">Display</string>
@ -505,6 +506,7 @@
<string name="download_queue_error">Could not download chapters. You can try again in the downloads section</string>
<!-- Library update service notifications -->
<string name="notification_check_updates">Checking for new chapters</string>
<string name="notification_update_progress">Update progress: %1$d/%2$d</string>
<string name="notification_new_chapters">New chapters found</string>
<plurals name="notification_new_chapters_text">