Add rtl support in ItemScreen webView

This commit is contained in:
Shinokuni 2024-08-14 14:42:32 +02:00
parent cd18ea3594
commit eca565ca07
2 changed files with 13 additions and 2 deletions

View File

@ -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)
)

View File

@ -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 @@
</style>
</head>
<body>
%4$s
<body dir=\"%4$s\">
%5$s
</body>
</html>]]></string>
</resources>