Add setting to hide manga content from update/download notifications
This commit is contained in:
parent
fc8f91baec
commit
f3d69599aa
@ -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.NotificationHandler
|
||||||
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.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.util.lang.chop
|
import eu.kanade.tachiyomi.util.lang.chop
|
||||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
import java.util.regex.Pattern
|
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.
|
* 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))
|
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.
|
* Status of download. Used for correct notification icon.
|
||||||
*/
|
*/
|
||||||
@ -87,12 +92,19 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
NotificationReceiver.pauseDownloadsPendingBroadcast(context))
|
NotificationReceiver.pauseDownloadsPendingBroadcast(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 title = download.manga.title.chop(15)
|
||||||
val quotedTitle = Pattern.quote(title)
|
val quotedTitle = Pattern.quote(title)
|
||||||
val chapter = download.chapter.name.replaceFirst("$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), "")
|
val chapter = download.chapter.name.replaceFirst("$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), "")
|
||||||
setContentTitle("$title - $chapter".chop(30))
|
setContentTitle("$title - $chapter".chop(30))
|
||||||
setContentText(context.getString(R.string.chapter_downloading_progress)
|
setContentText(downloadingProgressText)
|
||||||
.format(download.downloadedImages, download.pages!!.size))
|
}
|
||||||
|
|
||||||
setProgress(download.pages!!.size, download.downloadedImages, false)
|
setProgress(download.pages!!.size, download.downloadedImages, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,8 +448,13 @@ class LibraryUpdateService(
|
|||||||
* @param total the total progress.
|
* @param total the total progress.
|
||||||
*/
|
*/
|
||||||
private fun showProgressNotification(manga: Manga, current: Int, total: Int) {
|
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
|
notificationManager.notify(Notifications.ID_LIBRARY_PROGRESS, progressNotificationBuilder
|
||||||
.setContentTitle(manga.title)
|
.setContentTitle(title)
|
||||||
.setProgress(total, current, false)
|
.setProgress(total, current, false)
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
@ -468,14 +473,17 @@ class LibraryUpdateService(
|
|||||||
// Parent group notification
|
// Parent group notification
|
||||||
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
setContentTitle(getString(R.string.notification_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))
|
setContentText(updates.first().first.title.chop(NOTIF_TITLE_MAX_LEN))
|
||||||
} else {
|
} else {
|
||||||
setContentText(resources.getQuantityString(R.plurals.notification_new_chapters_text, updates.size, updates.size))
|
setContentText(resources.getQuantityString(R.plurals.notification_new_chapters_text, updates.size, updates.size))
|
||||||
|
|
||||||
|
if (!preferences.hideNotificationContent()) {
|
||||||
setStyle(NotificationCompat.BigTextStyle().bigText(updates.joinToString("\n") {
|
setStyle(NotificationCompat.BigTextStyle().bigText(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)
|
||||||
@ -490,12 +498,14 @@ class LibraryUpdateService(
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Per-manga notification
|
// Per-manga notification
|
||||||
|
if (!preferences.hideNotificationContent()) {
|
||||||
updates.forEach {
|
updates.forEach {
|
||||||
val (manga, chapters) = it
|
val (manga, chapters) = it
|
||||||
notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters))
|
notify(manga.id.hashCode(), createNewChaptersNotification(manga, chapters))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createNewChaptersNotification(manga: Manga, chapters: Array<Chapter>): Notification {
|
private fun createNewChaptersNotification(manga: Manga, chapters: Array<Chapter>): Notification {
|
||||||
return notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
return notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
|
@ -115,6 +115,8 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val secureScreen = "secure_screen"
|
const val secureScreen = "secure_screen"
|
||||||
|
|
||||||
|
const val hideNotificationContent = "hide_notification_content"
|
||||||
|
|
||||||
const val downloadNew = "download_new"
|
const val downloadNew = "download_new"
|
||||||
|
|
||||||
const val downloadNewCategories = "download_new_categories"
|
const val downloadNewCategories = "download_new_categories"
|
||||||
|
@ -59,6 +59,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false)
|
fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false)
|
||||||
|
|
||||||
|
fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false)
|
||||||
|
|
||||||
fun clear() = prefs.edit().clear().apply()
|
fun clear() = prefs.edit().clear().apply()
|
||||||
|
|
||||||
fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM)
|
fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM)
|
||||||
|
@ -180,6 +180,11 @@ class SettingsGeneralController : SettingsController() {
|
|||||||
summaryRes = R.string.secure_screen_summary
|
summaryRes = R.string.secure_screen_summary
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
|
switchPreference {
|
||||||
|
key = Keys.hideNotificationContent
|
||||||
|
titleRes = R.string.hide_notification_content
|
||||||
|
defaultValue = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<string name="secure_screen">Secure screen</string>
|
<string name="secure_screen">Secure screen</string>
|
||||||
<string name="secure_screen_summary">Hide app contents when switching apps and block screenshots</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 -->
|
<!-- Library section -->
|
||||||
<string name="pref_category_display">Display</string>
|
<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>
|
<string name="download_queue_error">Could not download chapters. You can try again in the downloads section</string>
|
||||||
|
|
||||||
<!-- Library update service notifications -->
|
<!-- 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_update_progress">Update progress: %1$d/%2$d</string>
|
||||||
<string name="notification_new_chapters">New chapters found</string>
|
<string name="notification_new_chapters">New chapters found</string>
|
||||||
<plurals name="notification_new_chapters_text">
|
<plurals name="notification_new_chapters_text">
|
||||||
|
Loading…
Reference in New Issue
Block a user