Article viewer theming.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
aminecmi 2022-09-27 12:36:01 +02:00
parent b16f86dda1
commit 5c12481813
6 changed files with 18 additions and 18 deletions

View File

@ -8,6 +8,7 @@ import android.graphics.Typeface
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.* import android.view.*
import android.webkit.WebResourceResponse import android.webkit.WebResourceResponse
import android.webkit.WebSettings import android.webkit.WebSettings
@ -56,6 +57,7 @@ import java.net.URL
import java.util.* import java.util.*
import java.util.concurrent.ExecutionException import java.util.concurrent.ExecutionException
class ArticleFragment : Fragment(), DIAware { class ArticleFragment : Fragment(), DIAware {
private var fontSize: Int = 16 private var fontSize: Int = 16
private lateinit var item: SelfossModel.Item private lateinit var item: SelfossModel.Item
@ -333,7 +335,6 @@ class ArticleFragment : Fragment(), DIAware {
} }
private fun htmlToWebview() { private fun htmlToWebview() {
val stringColor = String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent))
val attrs: IntArray = intArrayOf(android.R.attr.fontFamily) val attrs: IntArray = intArrayOf(android.R.attr.fontFamily)
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs) val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
@ -342,12 +343,11 @@ class ArticleFragment : Fragment(), DIAware {
binding.webcontent.settings.standardFontFamily = a.getString(0) binding.webcontent.settings.standardFontFamily = a.getString(0)
binding.webcontent.visibility = View.VISIBLE binding.webcontent.visibility = View.VISIBLE
// TODO: Set the color strings programmatically val colorOnSurface = TypedValue()
val (stringTextColor, stringBackgroundColor) = if (appSettingsService.isDarkThemeEnabled()) { requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
Pair("#FFFFFF", "#303030")
} else { val colorSurface = TypedValue()
Pair("#212121", "#FAFAFA") requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
}
binding.webcontent.settings.useWideViewPort = true binding.webcontent.settings.useWideViewPort = true
binding.webcontent.settings.loadWithOverviewMode = true binding.webcontent.settings.loadWithOverviewMode = true
@ -436,10 +436,10 @@ class ArticleFragment : Fragment(), DIAware {
| max-width: 100%; | max-width: 100%;
| } | }
| a { | a {
| color: $stringColor !important; | color: ${String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent))} !important;
| } | }
| *:not(a) { | *:not(a) {
| color: $stringTextColor; | color: ${String.format("#%06X", 0xFFFFFF and colorOnSurface.data)};
| } | }
| * { | * {
| font-size: ${fontSize}px; | font-size: ${fontSize}px;
@ -447,11 +447,11 @@ class ArticleFragment : Fragment(), DIAware {
| word-break: break-word; | word-break: break-word;
| overflow:hidden; | overflow:hidden;
| line-height: 1.5em; | line-height: 1.5em;
| background-color: $stringBackgroundColor; | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)};
| } | }
| body, html { | body, html {
| background-color: $stringBackgroundColor !important; | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important;
| border-color: $stringBackgroundColor !important; | border-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important;
| padding: 0 !important; | padding: 0 !important;
| margin: 0 !important; | margin: 0 !important;
| } | }
@ -461,7 +461,7 @@ class ArticleFragment : Fragment(), DIAware {
| pre, code { | pre, code {
| white-space: pre-wrap; | white-space: pre-wrap;
| width:100%; | width:100%;
| background-color: $stringBackgroundColor; | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)};
| } | }
| </style> | </style>
| $fontLinkAndStyle | $fontLinkAndStyle

View File

@ -16,8 +16,7 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
card_view:cardElevation="2dp" card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true" card_view:cardUseCompatPadding="true"
card_view:layout_constraintBottom_toBottomOf="parent" card_view:layout_constraintBottom_toBottomOf="parent">
app:cardBackgroundColor="?cardBackgroundColor">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -66,7 +66,7 @@
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:paddingBottom="48dp" android:paddingBottom="48dp"
android:background="?android:colorBackground" android:background="?attr/webviewBackground"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"

View File

@ -4,10 +4,10 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDark">@color/colorAccentDark</item> <item name="colorAccentDark">@color/colorAccentDark</item>
<item name="cardBackgroundColor">@color/white</item>
<item name="preferenceTheme">@style/PreferenceStyle</item> <item name="preferenceTheme">@style/PreferenceStyle</item>
<item name="android:statusBarColor">@color/dark</item> <item name="android:statusBarColor">@color/dark</item>
<item name="bottomBarBackground">@color/dark</item> <item name="bottomBarBackground">@color/dark</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="webviewBackground">@color/dark</item>
</style> </style>
</resources> </resources>

View File

@ -4,5 +4,6 @@
<attr name="colorAccentDark" format="reference|color" /> <attr name="colorAccentDark" format="reference|color" />
<attr name="bottomBarBackground" format="reference|color" /> <attr name="bottomBarBackground" format="reference|color" />
<attr name="toolbarPopupTheme" format="reference|color" /> <attr name="toolbarPopupTheme" format="reference|color" />
<attr name="webviewBackground" format="reference|color" />
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -9,11 +9,11 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDark">@color/colorAccentDark</item> <item name="colorAccentDark">@color/colorAccentDark</item>
<item name="cardBackgroundColor">@color/white</item>
<item name="preferenceTheme">@style/PreferenceStyle</item> <item name="preferenceTheme">@style/PreferenceStyle</item>
<item name="android:statusBarColor">?attr/colorPrimary</item> <item name="android:statusBarColor">?attr/colorPrimary</item>
<item name="bottomBarBackground">@color/white</item> <item name="bottomBarBackground">@color/white</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="webviewBackground">@color/white</item>
</style> </style>
<!-- Preference Theme --> <!-- Preference Theme -->