diff --git a/app/src/main/java/me/ash/reader/infrastructure/preference/ReadingSubheadAlignPreference.kt b/app/src/main/java/me/ash/reader/infrastructure/preference/ReadingSubheadAlignPreference.kt index f368934d3..e4e6592a1 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/preference/ReadingSubheadAlignPreference.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/preference/ReadingSubheadAlignPreference.kt @@ -41,6 +41,14 @@ sealed class ReadingSubheadAlignPreference(val value: Int) : Preference() { Justify -> TextAlign.Justify } + fun toTextAlignCSS(): String = + when (this) { + Left -> "left" + Right -> "right" + Center -> "center" + Justify -> "justify" + } + companion object { val default = Left diff --git a/app/src/main/java/me/ash/reader/ui/component/base/RYWebView.kt b/app/src/main/java/me/ash/reader/ui/component/base/RYWebView.kt index 032b88b5e..46583cc0a 100644 --- a/app/src/main/java/me/ash/reader/ui/component/base/RYWebView.kt +++ b/app/src/main/java/me/ash/reader/ui/component/base/RYWebView.kt @@ -1,5 +1,6 @@ package me.ash.reader.ui.component.base +import android.content.Context import android.net.http.SslError import android.util.Log import android.webkit.SslErrorHandler @@ -17,10 +18,13 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import me.ash.reader.infrastructure.preference.LocalOpenLink import me.ash.reader.infrastructure.preference.LocalOpenLinkSpecificBrowser +import me.ash.reader.infrastructure.preference.LocalReadingPageTonalElevation import me.ash.reader.ui.ext.openURL +import me.ash.reader.ui.ext.surfaceColorAtElevation const val INJECTION_TOKEN = "/android_asset_font/" @@ -33,8 +37,9 @@ fun RYWebView( val context = LocalContext.current val openLink = LocalOpenLink.current val openLinkSpecificBrowser = LocalOpenLinkSpecificBrowser.current + val tonalElevation = LocalReadingPageTonalElevation.current val color = MaterialTheme.colorScheme.onSurfaceVariant.toArgb() - val backgroundColor = MaterialTheme.colorScheme.surface.toArgb() + val backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(tonalElevation.value.dp).toArgb() val webViewClient by remember { mutableStateOf(object : WebViewClient() { @@ -107,33 +112,20 @@ fun RYWebView( this.webViewClient = webViewClient setBackgroundColor(backgroundColor) isHorizontalScrollBarEnabled = false - isVerticalScrollBarEnabled = false + isVerticalScrollBarEnabled = true }) } -// Column( -// modifier = modifier -// .height(if (viewState.isLoading) 100.dp else 0.dp), -// ) { -// Icon( -// modifier = modifier -// .size(50.dp), -// imageVector = Icons.Rounded.HourglassBottom, -// contentDescription = "Loading", -// tint = MaterialTheme.colorScheme.primary, -// ) -// Spacer(modifier = modifier.height(50.dp)) -// } - AndroidView( - modifier = modifier,//.padding(horizontal = if (content.contains("class=\"page\"")) 0.dp else 24.dp), + modifier = modifier, factory = { webView }, update = { it.apply { + Log.i("RLog", "CustomWebView: ${content}") settings.javaScriptEnabled = true loadDataWithBaseURL( null, - getStyle(color) + content, + getStyle(context, color) + content, "text/HTML", "UTF-8", null ) @@ -145,27 +137,21 @@ fun RYWebView( @Stable fun argbToCssColor(argb: Int): String = String.format("#%06X", 0xFFFFFF and argb) -// TODO: Google sans is deprecated @Stable -fun getStyle(argb: Int): String = """ +fun getStyle(context: Context, argb: Int): String = """
""" diff --git a/app/src/main/java/me/ash/reader/ui/page/home/reading/Content.kt b/app/src/main/java/me/ash/reader/ui/page/home/reading/Content.kt index db1bd522f..2392840ce 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/reading/Content.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/reading/Content.kt @@ -100,7 +100,11 @@ fun Content( if (!isLoading) { when (renderer) { ReadingRendererPreference.WebView -> - item { RYWebView(content = content) } + item { + DisableSelection { + RYWebView(content = content) + } + } ReadingRendererPreference.NativeComponent -> Reader(