Update private notifications visibility

master
Koitharu 1 year ago
parent 4449996a91
commit 0983885fa2
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -19,8 +19,8 @@ android {
applicationId 'org.koitharu.kotatsu' applicationId 'org.koitharu.kotatsu'
minSdk = 21 minSdk = 21
targetSdk = 35 targetSdk = 35
versionCode = 1009 versionCode = 1010
versionName = '8.1.3' versionName = '8.1.4'
generatedDensities = [] generatedDensities = []
testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner' testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner'
ksp { ksp {

@ -149,6 +149,8 @@ fun Manga.chaptersCount(): Int {
return max return max
} }
fun Manga.isNsfw(): Boolean = contentRating == ContentRating.ADULT || source.isNsfw()
fun MangaListFilter.getSummary() = buildSpannedString { fun MangaListFilter.getSummary() = buildSpannedString {
if (!query.isNullOrEmpty()) { if (!query.isNullOrEmpty()) {
append(query) append(query)

@ -25,6 +25,7 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ErrorReporterReceiver import org.koitharu.kotatsu.core.ErrorReporterReceiver
import org.koitharu.kotatsu.core.LocalizedAppContext import org.koitharu.kotatsu.core.LocalizedAppContext
import org.koitharu.kotatsu.core.model.LocalMangaSource 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.nav.AppRouter
import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow
import org.koitharu.kotatsu.core.util.ext.isReportable import org.koitharu.kotatsu.core.util.ext.isReportable
@ -140,10 +141,10 @@ class DownloadNotificationFactory @AssistedInject constructor(
builder.setSubText(null) builder.setSubText(null)
builder.setShowWhen(false) builder.setShowWhen(false)
builder.setVisibility( builder.setVisibility(
if (state != null && state.manga.isNsfw) { if (state != null && state.manga.isNsfw()) {
NotificationCompat.VISIBILITY_PRIVATE NotificationCompat.VISIBILITY_SECRET
} else { } else {
NotificationCompat.VISIBILITY_PUBLIC NotificationCompat.VISIBILITY_PRIVATE
}, },
) )
when { when {

@ -352,7 +352,7 @@ class SuggestionsWorker @AssistedInject constructor(
) )
setAutoCancel(true) setAutoCancel(true)
setCategory(NotificationCompat.CATEGORY_RECOMMENDATION) 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()) setShortcutId(manga.id.toString())
priority = NotificationCompat.PRIORITY_DEFAULT priority = NotificationCompat.PRIORITY_DEFAULT

@ -7,7 +7,7 @@ import android.content.Context
import android.os.Build import android.os.Build
import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat 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.NotificationCompat.VISIBILITY_SECRET
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.app.PendingIntentCompat import androidx.core.app.PendingIntentCompat
@ -17,12 +17,14 @@ import coil3.request.ImageRequest
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.LocalizedAppContext import org.koitharu.kotatsu.core.LocalizedAppContext
import org.koitharu.kotatsu.core.model.getLocalizedTitle 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.nav.AppRouter
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe
import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra
import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull 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.Manga
import org.koitharu.kotatsu.parsers.model.MangaChapter import org.koitharu.kotatsu.parsers.model.MangaChapter
import javax.inject.Inject import javax.inject.Inject
@ -51,7 +53,7 @@ class TrackerNotificationHelper @Inject constructor(
if (newChapters.isEmpty() || !applicationContext.checkNotificationPermission(CHANNEL_ID)) { if (newChapters.isEmpty() || !applicationContext.checkNotificationPermission(CHANNEL_ID)) {
return null return null
} }
if (manga.isNsfw && (settings.isTrackerNsfwDisabled || settings.isNsfwContentDisabled)) { if (manga.isNsfw() && (settings.isTrackerNsfwDisabled || settings.isNsfwContentDisabled)) {
return null return null
} }
val id = manga.url.hashCode() val id = manga.url.hashCode()
@ -92,7 +94,7 @@ class TrackerNotificationHelper @Inject constructor(
false, false,
), ),
) )
setVisibility(if (manga.isNsfw) VISIBILITY_SECRET else VISIBILITY_PUBLIC) setVisibility(if (manga.isNsfw()) VISIBILITY_SECRET else VISIBILITY_PRIVATE)
setShortcutId(manga.id.toString()) setShortcutId(manga.id.toString())
applyCommonSettings(this) applyCommonSettings(this)
} }
@ -127,6 +129,13 @@ class TrackerNotificationHelper @Inject constructor(
setNumber(newChaptersCount) setNumber(newChaptersCount)
setGroup(GROUP_NEW_CHAPTERS) setGroup(GROUP_NEW_CHAPTERS)
setGroupSummary(true) setGroupSummary(true)
setVisibility(
if (notifications.any { it.manga.isNsfw() }) {
VISIBILITY_SECRET
} else {
VISIBILITY_PRIVATE
},
)
val intent = AppRouter.mangaUpdatesIntent(applicationContext) val intent = AppRouter.mangaUpdatesIntent(applicationContext)
setContentIntent( setContentIntent(
PendingIntentCompat.getActivity( PendingIntentCompat.getActivity(

Loading…
Cancel
Save