Fix suggestion notification text

feature/double_reader
Koitharu 3 years ago
parent c7a1312cd6
commit 717fe8748a
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -1,5 +1,6 @@
package org.koitharu.kotatsu.suggestions.ui package org.koitharu.kotatsu.suggestions.ui
import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.pm.ServiceInfo import android.content.pm.ServiceInfo
@ -10,6 +11,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.app.PendingIntentCompat import androidx.core.app.PendingIntentCompat
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import androidx.core.text.bold
import androidx.core.text.buildSpannedString import androidx.core.text.buildSpannedString
import androidx.core.text.parseAsHtml import androidx.core.text.parseAsHtml
import androidx.hilt.work.HiltWorker import androidx.hilt.work.HiltWorker
@ -48,6 +50,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.util.ext.almostEquals import org.koitharu.kotatsu.core.util.ext.almostEquals
import org.koitharu.kotatsu.core.util.ext.asArrayList import org.koitharu.kotatsu.core.util.ext.asArrayList
import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName
import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission
import org.koitharu.kotatsu.core.util.ext.flatten import org.koitharu.kotatsu.core.util.ext.flatten
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
import org.koitharu.kotatsu.core.util.ext.sanitize import org.koitharu.kotatsu.core.util.ext.sanitize
@ -163,7 +166,7 @@ class SuggestionsWorker @AssistedInject constructor(
.sortedBy { it.relevance } .sortedBy { it.relevance }
.take(MAX_RESULTS) .take(MAX_RESULTS)
suggestionRepository.replace(suggestions) suggestionRepository.replace(suggestions)
if (appSettings.isSuggestionsNotificationAvailable) { if (appSettings.isSuggestionsNotificationAvailable && applicationContext.checkNotificationPermission()) {
for (i in 0..3) { for (i in 0..3) {
try { try {
val manga = suggestions[Random.nextInt(0, suggestions.size / 3)] val manga = suggestions[Random.nextInt(0, suggestions.size / 3)]
@ -221,10 +224,8 @@ class SuggestionsWorker @AssistedInject constructor(
e.printStackTraceDebug() e.printStackTraceDebug()
}.getOrDefault(emptyList()) }.getOrDefault(emptyList())
@SuppressLint("MissingPermission")
private suspend fun showNotification(manga: Manga) { private suspend fun showNotification(manga: Manga) {
if (!notificationManager.areNotificationsEnabled()) {
return
}
val channel = NotificationChannelCompat.Builder(MANGA_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT) val channel = NotificationChannelCompat.Builder(MANGA_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(applicationContext.getString(R.string.suggestions)) .setName(applicationContext.getString(R.string.suggestions))
.setDescription(applicationContext.getString(R.string.suggestions_summary)) .setDescription(applicationContext.getString(R.string.suggestions_summary))
@ -255,17 +256,19 @@ class SuggestionsWorker @AssistedInject constructor(
style.bigText( style.bigText(
buildSpannedString { buildSpannedString {
append(tagsText) append(tagsText)
appendLine()
append(description)
val chaptersCount = manga.chapters?.size ?: 0 val chaptersCount = manga.chapters?.size ?: 0
appendLine() appendLine()
append( bold {
applicationContext.resources.getQuantityString( append(
R.plurals.chapters, applicationContext.resources.getQuantityString(
chaptersCount, R.plurals.chapters,
chaptersCount, chaptersCount,
), chaptersCount,
) ),
)
}
appendLine()
append(description)
}, },
) )
style.setBigContentTitle(title) style.setBigContentTitle(title)

Loading…
Cancel
Save