mirror of
https://github.com/pachli/pachli-android.git
synced 2025-02-07 23:48:49 +01:00
fix: Show content warning changes when viewing status edits (#1148)
Previous code only ran the status content through the diff engine, so changes to the content warning / spoiler text were ignored. Fixes #1144
This commit is contained in:
parent
442b855c4b
commit
cf461906df
@ -41,6 +41,7 @@ import com.google.android.material.color.MaterialColors
|
||||
import org.xml.sax.XMLReader
|
||||
|
||||
class ViewEditsAdapter(
|
||||
context: Context,
|
||||
private val edits: List<StatusEdit>,
|
||||
private val animateEmojis: Boolean,
|
||||
private val useBlurhash: Boolean,
|
||||
@ -55,6 +56,8 @@ class ViewEditsAdapter(
|
||||
/** Size of medium text in this theme, in px */
|
||||
private var mediumTextSizePx: Float = 0f
|
||||
|
||||
private val pachliTagHandler = PachliTagHandler(context)
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
parent: ViewGroup,
|
||||
viewType: Int,
|
||||
@ -108,7 +111,9 @@ class ViewEditsAdapter(
|
||||
} else {
|
||||
binding.statusEditContentWarningDescription.show()
|
||||
binding.statusEditContentWarningSeparator.show()
|
||||
binding.statusEditContentWarningDescription.text = edit.spoilerText.emojify(
|
||||
binding.statusEditContentWarningDescription.text = edit.spoilerText
|
||||
.parseAsMastodonHtml(pachliTagHandler)
|
||||
.emojify(
|
||||
edit.emojis,
|
||||
binding.statusEditContentWarningDescription,
|
||||
animateEmojis,
|
||||
@ -117,7 +122,7 @@ class ViewEditsAdapter(
|
||||
|
||||
val emojifiedText = edit
|
||||
.content
|
||||
.parseAsMastodonHtml(PachliTagHandler(context))
|
||||
.parseAsMastodonHtml(pachliTagHandler)
|
||||
.emojify(edit.emojis, binding.statusEditContent, animateEmojis)
|
||||
|
||||
setClickableText(binding.statusEditContent, emojifiedText, emptyList(), emptyList(), listener)
|
||||
|
@ -138,6 +138,7 @@ class ViewEditsFragment :
|
||||
binding.initialProgressBar.hide()
|
||||
|
||||
binding.recyclerView.adapter = ViewEditsAdapter(
|
||||
context = requireContext(),
|
||||
edits = uiState.edits,
|
||||
animateEmojis = animateEmojis,
|
||||
useBlurhash = useBlurhash,
|
||||
|
@ -105,9 +105,13 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
|
||||
)
|
||||
val processor = OptimisticXMLProcessor()
|
||||
processor.setCoalesce(true)
|
||||
val output = HtmlDiffOutput()
|
||||
val spoilerDiff = HtmlDiffOutput()
|
||||
val contentDiff = HtmlDiffOutput()
|
||||
|
||||
try {
|
||||
var currentSpoilerText = loader.load("<div>${sortedEdits[0].spoilerText}</div>")
|
||||
var previousSpoilerText = loader.load("<div>${sortedEdits[1].spoilerText}</div>")
|
||||
|
||||
// The XML processor expects `br` to be closed
|
||||
var currentContent =
|
||||
loader.load(sortedEdits[0].content.replace("<br>", "<br/>"))
|
||||
@ -115,12 +119,16 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
|
||||
loader.load(sortedEdits[1].content.replace("<br>", "<br/>"))
|
||||
|
||||
for (i in 1 until sortedEdits.size) {
|
||||
processor.diff(previousContent, currentContent, output)
|
||||
processor.diff(previousSpoilerText, currentSpoilerText, spoilerDiff)
|
||||
processor.diff(previousContent, currentContent, contentDiff)
|
||||
sortedEdits[i - 1] = sortedEdits[i - 1].copy(
|
||||
content = output.xml.toString(),
|
||||
spoilerText = spoilerDiff.xml.toString().removePrefix("<div/>"),
|
||||
content = contentDiff.xml.toString(),
|
||||
)
|
||||
|
||||
if (i < sortedEdits.size - 1) {
|
||||
currentSpoilerText = previousSpoilerText
|
||||
previousSpoilerText = loader.load(sortedEdits[i + 1].spoilerText)
|
||||
currentContent = previousContent
|
||||
previousContent = loader.load(
|
||||
sortedEdits[i + 1].content.replace("<br>", "<br/>"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user