From 4edabbb18663cdaba8c068dad9657860b5c917b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 24 Mar 2020 16:31:46 +0100 Subject: [PATCH] [Messages/Compose] Enable HTML messages for Idziennik. --- .../messages/MessagesComposeFragment.kt | 2 +- .../edziennik/utils/html/BetterHtml.kt | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesComposeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesComposeFragment.kt index b0181278..7326a653 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesComposeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesComposeFragment.kt @@ -438,7 +438,7 @@ class MessagesComposeFragment : Fragment(), CoroutineScope { if (b.textLayout.counterMaxLength != -1 && b.text.length() > b.textLayout.counterMaxLength) return - var textHtml = if (app.profile.loginStoreType != LoginStore.LOGIN_TYPE_VULCAN && app.profile.loginStoreType != LoginStore.LOGIN_TYPE_IDZIENNIK) { + var textHtml = if (app.profile.loginStoreType != LoginStore.LOGIN_TYPE_VULCAN) { HtmlCompat.toHtml(SpannableString(text), HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL) .replace("\n", "") .replace(" dir=\"ltr\"", "") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/html/BetterHtml.kt b/app/src/main/java/pl/szczodrzynski/edziennik/utils/html/BetterHtml.kt index cca59802..4119369e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/html/BetterHtml.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/html/BetterHtml.kt @@ -6,12 +6,11 @@ package pl.szczodrzynski.edziennik.utils.html import android.content.Context import android.graphics.Color -import android.os.Build -import android.text.Html import android.text.SpannableStringBuilder import android.text.Spanned import android.text.style.BulletSpan import androidx.core.graphics.ColorUtils +import androidx.core.text.HtmlCompat import pl.szczodrzynski.edziennik.dp import pl.szczodrzynski.edziennik.resolveAttr import pl.szczodrzynski.navlib.blendColors @@ -59,16 +58,12 @@ object BetterHtml { }*/ @Suppress("DEPRECATION") - val htmlSpannable = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Html.fromHtml( - text, - Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM or Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST or Html.FROM_HTML_SEPARATOR_LINE_BREAK_DIV, - null, - LiTagHandler() - ) - } else { - Html.fromHtml(text, null, LiTagHandler()) - } + val htmlSpannable = HtmlCompat.fromHtml( + text, + HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM or HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_LIST or HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_DIV, + null, + LiTagHandler() + ) val spannableBuilder = SpannableStringBuilder(htmlSpannable) val bulletSpans = spannableBuilder.getSpans(0, spannableBuilder.length, BulletSpan::class.java)