Remove replacement characters from manga description
This commit is contained in:
@@ -35,3 +35,9 @@ fun String.almostEquals(other: String, @FloatRange(from = 0.0) threshold: Float)
|
||||
val diff = lowercase().levenshteinDistance(other.lowercase()) / ((length + other.length) / 2f)
|
||||
return diff < threshold
|
||||
}
|
||||
|
||||
fun CharSequence.sanitize(): CharSequence {
|
||||
return filterNot { c -> c.isReplacement() }
|
||||
}
|
||||
|
||||
fun Char.isReplacement() = this in '\uFFF0'..'\uFFFF'
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.koitharu.kotatsu.core.util.ext.MutableEventFlow
|
||||
import org.koitharu.kotatsu.core.util.ext.call
|
||||
import org.koitharu.kotatsu.core.util.ext.computeSize
|
||||
import org.koitharu.kotatsu.core.util.ext.requireValue
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||
import org.koitharu.kotatsu.core.util.ext.toFileOrNull
|
||||
import org.koitharu.kotatsu.details.domain.BranchComparator
|
||||
import org.koitharu.kotatsu.details.domain.DetailsInteractor
|
||||
@@ -135,7 +136,7 @@ class DetailsViewModel @Inject constructor(
|
||||
if (description.isNullOrEmpty()) {
|
||||
emit(null)
|
||||
} else {
|
||||
emit(description.parseAsHtml().filterSpans())
|
||||
emit(description.parseAsHtml().filterSpans().sanitize())
|
||||
emit(description.parseAsHtml(imageGetter = imageGetter).filterSpans())
|
||||
}
|
||||
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.WhileSubscribed(5000), null)
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.core.util.ext.newImageRequest
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.observeEvent
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||
import org.koitharu.kotatsu.core.util.ext.scaleUpActivityOptionsOf
|
||||
import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||
import org.koitharu.kotatsu.databinding.SheetScrobblingBinding
|
||||
@@ -122,7 +123,7 @@ class ScrobblingInfoSheet :
|
||||
}
|
||||
requireViewBinding().textViewTitle.text = scrobbling.title
|
||||
requireViewBinding().ratingBar.rating = scrobbling.rating * requireViewBinding().ratingBar.numStars
|
||||
requireViewBinding().textViewDescription.text = scrobbling.description
|
||||
requireViewBinding().textViewDescription.text = scrobbling.description?.sanitize()
|
||||
requireViewBinding().spinnerStatus.setSelection(scrobbling.status?.ordinal ?: -1)
|
||||
requireViewBinding().imageViewLogo.contentDescription = getString(scrobbling.scrobbler.titleResId)
|
||||
requireViewBinding().imageViewLogo.setImageResource(scrobbling.scrobbler.iconResId)
|
||||
|
||||
@@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||
import org.koitharu.kotatsu.core.util.ext.findKeyByValue
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||
import org.koitharu.kotatsu.scrobbling.common.data.ScrobblingEntity
|
||||
@@ -123,7 +124,7 @@ abstract class Scrobbler(
|
||||
rating = rating,
|
||||
title = mangaInfo.name,
|
||||
coverUrl = mangaInfo.cover,
|
||||
description = mangaInfo.descriptionHtml.parseAsHtml(),
|
||||
description = mangaInfo.descriptionHtml.parseAsHtml().sanitize(),
|
||||
externalUrl = mangaInfo.url,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.ext.almostEquals
|
||||
import org.koitharu.kotatsu.core.util.ext.asArrayList
|
||||
import org.koitharu.kotatsu.core.util.ext.flatten
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitize
|
||||
import org.koitharu.kotatsu.core.util.ext.takeMostFrequent
|
||||
import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull
|
||||
import org.koitharu.kotatsu.core.util.ext.trySetForeground
|
||||
@@ -227,7 +228,7 @@ class SuggestionsWorker @AssistedInject constructor(
|
||||
).toBitmapOrNull(),
|
||||
)
|
||||
setSmallIcon(R.drawable.ic_stat_suggestion)
|
||||
val description = manga.description?.parseAsHtml(HtmlCompat.FROM_HTML_MODE_COMPACT)
|
||||
val description = manga.description?.parseAsHtml(HtmlCompat.FROM_HTML_MODE_COMPACT)?.sanitize()
|
||||
if (!description.isNullOrBlank()) {
|
||||
val style = NotificationCompat.BigTextStyle()
|
||||
style.bigText(
|
||||
|
||||
Reference in New Issue
Block a user