mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 04:59:17 +01:00
Hide notification content
Closes #843 Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
c4d9b66485
commit
3a6507101a
@ -84,9 +84,9 @@ class BackupNotifier(private val context: Context) {
|
|||||||
val builder = with(progressNotificationBuilder) {
|
val builder = with(progressNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.restoring_backup))
|
setContentTitle(context.getString(R.string.restoring_backup))
|
||||||
|
|
||||||
// if (!preferences.hideNotificationContent()) {
|
if (!preferences.hideNotificationContent()) {
|
||||||
setContentText(content)
|
setContentText(content)
|
||||||
// }
|
}
|
||||||
|
|
||||||
setProgress(maxAmount, progress, false)
|
setProgress(maxAmount, progress, false)
|
||||||
setOnlyAlertOnce(true)
|
setOnlyAlertOnce(true)
|
||||||
|
@ -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.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.notificationManager
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +23,9 @@ import java.util.regex.Pattern
|
|||||||
* @param context context of application
|
* @param context context of application
|
||||||
*/
|
*/
|
||||||
internal class DownloadNotifier(private val context: Context) {
|
internal class DownloadNotifier(private val context: Context) {
|
||||||
|
|
||||||
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification builder.
|
* Notification builder.
|
||||||
*/
|
*/
|
||||||
@ -53,15 +58,6 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
context.notificationManager.notify(id, build())
|
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
|
* Dismiss the downloader's notification. Downloader error notifications use a different id, so
|
||||||
* those can only be dismissed by the user.
|
* 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 title = download.manga.title.chop(15)
|
||||||
val quotedTitle = Pattern.quote(title)
|
val quotedTitle = Pattern.quote(title)
|
||||||
val chapter = download.chapter.name.replaceFirst(
|
val chapter = download.chapter.name.replaceFirst(
|
||||||
@ -141,6 +137,13 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 title = download.manga.title.chop(15)
|
||||||
val quotedTitle = Pattern.quote(title)
|
val quotedTitle = Pattern.quote(title)
|
||||||
val chapter = download.chapter.name.replaceFirst(
|
val chapter = download.chapter.name.replaceFirst(
|
||||||
@ -148,10 +151,8 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
""
|
""
|
||||||
)
|
)
|
||||||
setContentTitle("$title - $chapter".chop(30))
|
setContentTitle("$title - $chapter".chop(30))
|
||||||
setContentText(
|
setContentText(downloadingProgressText)
|
||||||
context.getString(R.string.downloading_progress)
|
}
|
||||||
.format(download.downloadedImages, download.pages!!.size)
|
|
||||||
)
|
|
||||||
setStyle(null)
|
setStyle(null)
|
||||||
setProgress(download.pages!!.size, download.downloadedImages, false)
|
setProgress(download.pages!!.size, download.downloadedImages, false)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,11 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
* @param total the total progress.
|
* @param total the total progress.
|
||||||
*/
|
*/
|
||||||
fun showProgressNotification(manga: Manga, current: Int, total: Int) {
|
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(
|
context.notificationManager.notify(
|
||||||
Notifications.ID_LIBRARY_PROGRESS,
|
Notifications.ID_LIBRARY_PROGRESS,
|
||||||
@ -129,6 +133,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
val updates = newUpdates.toImmutableMap()
|
val updates = newUpdates.toImmutableMap()
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
val notifications = ArrayList<Pair<Notification, Int>>()
|
val notifications = ArrayList<Pair<Notification, Int>>()
|
||||||
|
if (!preferences.hideNotificationContent()) {
|
||||||
updates.forEach {
|
updates.forEach {
|
||||||
val manga = it.key
|
val manga = it.key
|
||||||
val chapters = it.value
|
val chapters = it.value
|
||||||
@ -139,12 +144,16 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
try {
|
try {
|
||||||
val request = ImageRequest.Builder(context).data(manga)
|
val request = ImageRequest.Builder(context).data(manga)
|
||||||
.parameters(Parameters.Builder().set(MangaFetcher.onlyCache, true).build())
|
.parameters(
|
||||||
|
Parameters.Builder().set(MangaFetcher.onlyCache, true)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
.networkCachePolicy(CachePolicy.READ_ONLY)
|
.networkCachePolicy(CachePolicy.READ_ONLY)
|
||||||
.transformations(CircleCropTransformation())
|
.transformations(CircleCropTransformation())
|
||||||
.size(width = ICON_SIZE, height = ICON_SIZE).build()
|
.size(width = ICON_SIZE, height = ICON_SIZE).build()
|
||||||
|
|
||||||
Coil.imageLoader(context).execute(request).drawable?.let { drawable ->
|
Coil.imageLoader(context)
|
||||||
|
.execute(request).drawable?.let { drawable ->
|
||||||
setLargeIcon((drawable as BitmapDrawable).bitmap)
|
setLargeIcon((drawable as BitmapDrawable).bitmap)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -196,6 +205,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NotificationManagerCompat.from(context).apply {
|
NotificationManagerCompat.from(context).apply {
|
||||||
notify(
|
notify(
|
||||||
@ -213,6 +223,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
updates.size
|
updates.size
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if (!preferences.hideNotificationContent()) {
|
||||||
setStyle(
|
setStyle(
|
||||||
NotificationCompat.BigTextStyle()
|
NotificationCompat.BigTextStyle()
|
||||||
.bigText(
|
.bigText(
|
||||||
@ -221,7 +232,8 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
}
|
||||||
|
} else if (!preferences.hideNotificationContent()) {
|
||||||
setContentText(updates.keys.first().title.chop(45))
|
setContentText(updates.keys.first().title.chop(45))
|
||||||
}
|
}
|
||||||
priority = NotificationCompat.PRIORITY_HIGH
|
priority = NotificationCompat.PRIORITY_HIGH
|
||||||
|
@ -185,6 +185,8 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val secureScreen = "secure_screen"
|
const val secureScreen = "secure_screen"
|
||||||
|
|
||||||
|
const val hideNotificationContent = "hide_notification_content"
|
||||||
|
|
||||||
const val removeArticles = "remove_articles"
|
const val removeArticles = "remove_articles"
|
||||||
|
|
||||||
const val skipPreMigration = "skip_pre_migration"
|
const val skipPreMigration = "skip_pre_migration"
|
||||||
|
@ -320,6 +320,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 removeArticles() = rxPrefs.getBoolean(Keys.removeArticles, false)
|
fun removeArticles() = rxPrefs.getBoolean(Keys.removeArticles, false)
|
||||||
|
|
||||||
fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE)
|
fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE)
|
||||||
|
@ -58,5 +58,10 @@ class SettingsSecurityController : SettingsController() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switchPreference {
|
||||||
|
key = PreferenceKeys.hideNotificationContent
|
||||||
|
titleRes = R.string.hide_notification_content
|
||||||
|
defaultValue = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user