From 0983885fa201cee85695ab1d7639e1ad01b06a79 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 3 May 2025 08:30:36 +0300 Subject: [PATCH] Update private notifications visibility --- app/build.gradle | 4 ++-- .../org/koitharu/kotatsu/core/model/Manga.kt | 2 ++ .../ui/worker/DownloadNotificationFactory.kt | 7 ++++--- .../kotatsu/suggestions/ui/SuggestionsWorker.kt | 2 +- .../tracker/work/TrackerNotificationHelper.kt | 15 ++++++++++++--- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5c14ce619..9e6361cda 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { applicationId 'org.koitharu.kotatsu' minSdk = 21 targetSdk = 35 - versionCode = 1009 - versionName = '8.1.3' + versionCode = 1010 + versionName = '8.1.4' generatedDensities = [] testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner' ksp { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt index 10304ef2b..89723d8ba 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt @@ -149,6 +149,8 @@ fun Manga.chaptersCount(): Int { return max } +fun Manga.isNsfw(): Boolean = contentRating == ContentRating.ADULT || source.isNsfw() + fun MangaListFilter.getSummary() = buildSpannedString { if (!query.isNullOrEmpty()) { append(query) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt index 9b3d0b651..ecf6af769 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadNotificationFactory.kt @@ -25,6 +25,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ErrorReporterReceiver import org.koitharu.kotatsu.core.LocalizedAppContext import org.koitharu.kotatsu.core.model.LocalMangaSource +import org.koitharu.kotatsu.core.model.isNsfw import org.koitharu.kotatsu.core.nav.AppRouter import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow import org.koitharu.kotatsu.core.util.ext.isReportable @@ -140,10 +141,10 @@ class DownloadNotificationFactory @AssistedInject constructor( builder.setSubText(null) builder.setShowWhen(false) builder.setVisibility( - if (state != null && state.manga.isNsfw) { - NotificationCompat.VISIBILITY_PRIVATE + if (state != null && state.manga.isNsfw()) { + NotificationCompat.VISIBILITY_SECRET } else { - NotificationCompat.VISIBILITY_PUBLIC + NotificationCompat.VISIBILITY_PRIVATE }, ) when { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt index a2c4108b6..2d8142cf8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt @@ -352,7 +352,7 @@ class SuggestionsWorker @AssistedInject constructor( ) setAutoCancel(true) setCategory(NotificationCompat.CATEGORY_RECOMMENDATION) - setVisibility(if (manga.isNsfw) NotificationCompat.VISIBILITY_SECRET else NotificationCompat.VISIBILITY_PUBLIC) + setVisibility(if (manga.isNsfw()) NotificationCompat.VISIBILITY_SECRET else NotificationCompat.VISIBILITY_PRIVATE) setShortcutId(manga.id.toString()) priority = NotificationCompat.PRIORITY_DEFAULT diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt index 54bb294a9..6e097ecc6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt @@ -7,7 +7,7 @@ import android.content.Context import android.os.Build import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationCompat.VISIBILITY_PUBLIC +import androidx.core.app.NotificationCompat.VISIBILITY_PRIVATE import androidx.core.app.NotificationCompat.VISIBILITY_SECRET import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat @@ -17,12 +17,14 @@ import coil3.request.ImageRequest import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.LocalizedAppContext import org.koitharu.kotatsu.core.model.getLocalizedTitle +import org.koitharu.kotatsu.core.model.isNsfw import org.koitharu.kotatsu.core.nav.AppRouter import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull +import org.koitharu.kotatsu.parsers.model.ContentRating import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter import javax.inject.Inject @@ -51,7 +53,7 @@ class TrackerNotificationHelper @Inject constructor( if (newChapters.isEmpty() || !applicationContext.checkNotificationPermission(CHANNEL_ID)) { return null } - if (manga.isNsfw && (settings.isTrackerNsfwDisabled || settings.isNsfwContentDisabled)) { + if (manga.isNsfw() && (settings.isTrackerNsfwDisabled || settings.isNsfwContentDisabled)) { return null } val id = manga.url.hashCode() @@ -92,7 +94,7 @@ class TrackerNotificationHelper @Inject constructor( false, ), ) - setVisibility(if (manga.isNsfw) VISIBILITY_SECRET else VISIBILITY_PUBLIC) + setVisibility(if (manga.isNsfw()) VISIBILITY_SECRET else VISIBILITY_PRIVATE) setShortcutId(manga.id.toString()) applyCommonSettings(this) } @@ -127,6 +129,13 @@ class TrackerNotificationHelper @Inject constructor( setNumber(newChaptersCount) setGroup(GROUP_NEW_CHAPTERS) setGroupSummary(true) + setVisibility( + if (notifications.any { it.manga.isNsfw() }) { + VISIBILITY_SECRET + } else { + VISIBILITY_PRIVATE + }, + ) val intent = AppRouter.mangaUpdatesIntent(applicationContext) setContentIntent( PendingIntentCompat.getActivity(