From eca565ca0738065f7e38784a6f5de1447fd2b1b0 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 14 Aug 2024 14:42:32 +0200 Subject: [PATCH] Add rtl support in ItemScreen webView --- .../main/java/com/readrops/app/item/view/ItemWebView.kt | 9 +++++++++ app/src/main/res/values/html.xml | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/readrops/app/item/view/ItemWebView.kt b/app/src/main/java/com/readrops/app/item/view/ItemWebView.kt index 2c5e3319..edc5f733 100644 --- a/app/src/main/java/com/readrops/app/item/view/ItemWebView.kt +++ b/app/src/main/java/com/readrops/app/item/view/ItemWebView.kt @@ -7,11 +7,13 @@ import android.webkit.WebView import android.webkit.WebViewClient import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb +import androidx.core.text.layoutDirection import com.readrops.app.R import com.readrops.app.util.Utils import com.readrops.db.pojo.ItemWithFeed import org.jsoup.Jsoup import org.jsoup.parser.Parser +import java.util.Locale @SuppressLint("SetJavaScriptEnabled", "ViewConstructor") class ItemWebView( @@ -51,11 +53,18 @@ class ItemWebView( backgroundColor: Color, onBackgroundColor: Color ) { + val direction = if (Locale.getDefault().layoutDirection == LAYOUT_DIRECTION_LTR) { + "ltr" + } else { + "rtl" + } + val string = context.getString( R.string.webview_html_template, Utils.getCssColor(accentColor.toArgb()), Utils.getCssColor(onBackgroundColor.toArgb()), Utils.getCssColor(backgroundColor.toArgb()), + direction, formatText(itemWithFeed) ) diff --git a/app/src/main/res/values/html.xml b/app/src/main/res/values/html.xml index b63bcc27..e641e50f 100644 --- a/app/src/main/res/values/html.xml +++ b/app/src/main/res/values/html.xml @@ -13,6 +13,8 @@ %1$s: accent color %2$s: text color %3$s: background color + %4$s: text direction (ltr or rtl) + %5$s: content */ @font-face { @@ -113,8 +115,8 @@ - - %4$s + + %5$s ]]> \ No newline at end of file