From 5c12481813cfc108f100191148f3044fa49d5e34 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Tue, 27 Sep 2022 12:36:01 +0200 Subject: [PATCH] Article viewer theming. --- .../android/fragments/ArticleFragment.kt | 26 +++++++++---------- androidApp/src/main/res/layout/card_item.xml | 3 +-- .../src/main/res/layout/fragment_article.xml | 2 +- .../src/main/res/values-night/styles.xml | 2 +- androidApp/src/main/res/values/attrs.xml | 1 + androidApp/src/main/res/values/styles.xml | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 703974c..4e9ada7 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -8,6 +8,7 @@ import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle +import android.util.TypedValue import android.view.* import android.webkit.WebResourceResponse import android.webkit.WebSettings @@ -56,6 +57,7 @@ import java.net.URL import java.util.* import java.util.concurrent.ExecutionException + class ArticleFragment : Fragment(), DIAware { private var fontSize: Int = 16 private lateinit var item: SelfossModel.Item @@ -333,7 +335,6 @@ class ArticleFragment : Fragment(), DIAware { } private fun htmlToWebview() { - val stringColor = String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent)) val attrs: IntArray = intArrayOf(android.R.attr.fontFamily) val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs) @@ -342,12 +343,11 @@ class ArticleFragment : Fragment(), DIAware { binding.webcontent.settings.standardFontFamily = a.getString(0) binding.webcontent.visibility = View.VISIBLE - // TODO: Set the color strings programmatically - val (stringTextColor, stringBackgroundColor) = if (appSettingsService.isDarkThemeEnabled()) { - Pair("#FFFFFF", "#303030") - } else { - Pair("#212121", "#FAFAFA") - } + val colorOnSurface = TypedValue() + requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true) + + val colorSurface = TypedValue() + requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) binding.webcontent.settings.useWideViewPort = true binding.webcontent.settings.loadWithOverviewMode = true @@ -436,10 +436,10 @@ class ArticleFragment : Fragment(), DIAware { | max-width: 100%; | } | a { - | color: $stringColor !important; + | color: ${String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent))} !important; | } | *:not(a) { - | color: $stringTextColor; + | color: ${String.format("#%06X", 0xFFFFFF and colorOnSurface.data)}; | } | * { | font-size: ${fontSize}px; @@ -447,11 +447,11 @@ class ArticleFragment : Fragment(), DIAware { | word-break: break-word; | overflow:hidden; | line-height: 1.5em; - | background-color: $stringBackgroundColor; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)}; | } | body, html { - | background-color: $stringBackgroundColor !important; - | border-color: $stringBackgroundColor !important; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important; + | border-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important; | padding: 0 !important; | margin: 0 !important; | } @@ -461,7 +461,7 @@ class ArticleFragment : Fragment(), DIAware { | pre, code { | white-space: pre-wrap; | width:100%; - | background-color: $stringBackgroundColor; + | background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)}; | } | | $fontLinkAndStyle diff --git a/androidApp/src/main/res/layout/card_item.xml b/androidApp/src/main/res/layout/card_item.xml index 7b6863d..023be37 100644 --- a/androidApp/src/main/res/layout/card_item.xml +++ b/androidApp/src/main/res/layout/card_item.xml @@ -16,8 +16,7 @@ app:layout_constraintTop_toTopOf="parent" card_view:cardElevation="2dp" card_view:cardUseCompatPadding="true" - card_view:layout_constraintBottom_toBottomOf="parent" - app:cardBackgroundColor="?cardBackgroundColor"> + card_view:layout_constraintBottom_toBottomOf="parent"> @color/colorPrimaryDark @color/colorAccent @color/colorAccentDark - @color/white @style/PreferenceStyle @color/dark @color/dark @style/ThemeOverlay.AppCompat.Dark + @color/dark diff --git a/androidApp/src/main/res/values/attrs.xml b/androidApp/src/main/res/values/attrs.xml index d37d5bb..a39851f 100644 --- a/androidApp/src/main/res/values/attrs.xml +++ b/androidApp/src/main/res/values/attrs.xml @@ -4,5 +4,6 @@ + \ No newline at end of file diff --git a/androidApp/src/main/res/values/styles.xml b/androidApp/src/main/res/values/styles.xml index cb97140..57db461 100644 --- a/androidApp/src/main/res/values/styles.xml +++ b/androidApp/src/main/res/values/styles.xml @@ -9,11 +9,11 @@ @color/colorPrimaryDark @color/colorAccent @color/colorAccentDark - @color/white @style/PreferenceStyle ?attr/colorPrimary @color/white @style/ThemeOverlay.AppCompat.Light + @color/white