Show the difference between edited statuses (#3314)
* Show the difference between edited statuses Diff each status against the previous version, comparing the different HTML as XML to produce a structured diff. Mark new content with `<ins>`, deleted content with `<del>`. Convert these to styled spans in `ViewEditsAdapter`. * Update diffx to 1.1.1 Fixes issue with diffs splitting on accented characters * Style edited strings with Android spans Don't use HTML spans and try and format them, create real Android spans. Do this with a custom tag handler that can add custom spans that set the text paint appropriately. * Lint * Move colors in to theme_colors.xml * Draw a roundrect for the backoround, add start/end padding Make the background slightlysofter by drawing it as a roundrect. Make the spans easier to understand by padding the start/end of each one with the width of a " " character. This is visual only, the underlying text is not changed. * Catch exceptions when parsing XML * Move sorting in to Dispatchers.Default coroutine * Scope the loader type * Remove alpha
This commit is contained in:
parent
43ea59ab2f
commit
b9be125c95
8 changed files with 349 additions and 9 deletions
|
|
@ -16,6 +16,7 @@
|
|||
@file:JvmName("StatusParsingHelper")
|
||||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.text.Html.TagHandler
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import androidx.core.text.parseAsHtml
|
||||
|
|
@ -23,12 +24,13 @@ import androidx.core.text.parseAsHtml
|
|||
/**
|
||||
* parse a String containing html from the Mastodon api to Spanned
|
||||
*/
|
||||
fun String.parseAsMastodonHtml(): Spanned {
|
||||
@JvmOverloads
|
||||
fun String.parseAsMastodonHtml(tagHandler: TagHandler? = null): Spanned {
|
||||
return this.replace("<br> ", "<br> ")
|
||||
.replace("<br /> ", "<br /> ")
|
||||
.replace("<br/> ", "<br/> ")
|
||||
.replace(" ", " ")
|
||||
.parseAsHtml()
|
||||
.parseAsHtml(tagHandler = tagHandler)
|
||||
/* Html.fromHtml returns trailing whitespace if the html ends in a </p> tag, which
|
||||
* most status contents do, so it should be trimmed. */
|
||||
.trimTrailingWhitespace()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue