From a2a8fd883111b0047f7d837e5ff7aaf324b1bf34 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 12 Mar 2022 23:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +- .../main/java/io/legado/app/constant/Theme.kt | 17 ----------- .../io/legado/app/help/config/ThemeConfig.kt | 12 +++++++- .../rss/source/edit/RssSourceEditActivity.kt | 3 ++ .../java/io/legado/app/ui/theme/AppTheme.kt | 28 +++++++++++++++++++ .../legado/app/ui/welcome/WelcomeActivity.kt | 3 +- .../res/layout/activity_rss_source_edit.xml | 5 ++++ 7 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/theme/AppTheme.kt diff --git a/app/build.gradle b/app/build.gradle index 8d1fc4d45..040def085 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -152,10 +152,11 @@ dependencies { implementation('androidx.constraintlayout:constraintlayout:2.1.3') implementation('androidx.swiperefreshlayout:swiperefreshlayout:1.1.0') implementation('androidx.viewpager2:viewpager2:1.0.0') + implementation('androidx.webkit:webkit:1.4.0') + implementation('com.google.android.material:material:1.5.0') implementation('com.google.android.flexbox:flexbox:3.0.0') implementation('com.google.code.gson:gson:2.9.0') - implementation('androidx.webkit:webkit:1.4.0') //lifecycle def lifecycle_version = '2.4.1' diff --git a/app/src/main/java/io/legado/app/constant/Theme.kt b/app/src/main/java/io/legado/app/constant/Theme.kt index 5c7ac5bb0..c5f063bee 100644 --- a/app/src/main/java/io/legado/app/constant/Theme.kt +++ b/app/src/main/java/io/legado/app/constant/Theme.kt @@ -1,22 +1,5 @@ package io.legado.app.constant -import io.legado.app.help.config.AppConfig -import io.legado.app.utils.ColorUtils - enum class Theme { Dark, Light, Auto, Transparent, EInk; - - companion object { - fun getTheme() = when { - AppConfig.isEInkMode -> EInk - AppConfig.isNightTheme -> Dark - else -> Light - } - - @Suppress("unused") - fun fromBackground(backgroundColor: Int) = - if (ColorUtils.isColorLight(backgroundColor)) Light - else Dark - - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt index 0b222e292..b0ba7dceb 100644 --- a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt @@ -27,6 +27,16 @@ object ThemeConfig { ArrayList(cList) } + fun getTheme() = when { + AppConfig.isEInkMode -> Theme.EInk + AppConfig.isNightTheme -> Theme.Dark + else -> Theme.Light + } + + fun isDarkTheme(): Boolean { + return getTheme() == Theme.Dark + } + fun applyDayNight(context: Context) { ReadBookConfig.upBg() applyTheme(context) @@ -46,7 +56,7 @@ object ThemeConfig { } fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? { - val bgCfg = when (Theme.getTheme()) { + val bgCfg = when (getTheme()) { Theme.Light -> Pair( context.getPrefString(PreferKey.bgImage), context.getPrefInt(PreferKey.bgImageBlurring, 0) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 08961c6aa..61b7aa385 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -148,6 +148,9 @@ class RssSourceEditActivity : private fun initView() { binding.recyclerView.setEdgeEffectColor(primaryColor) binding.recyclerView.adapter = adapter + binding.composeView.setContent { + + } } private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { diff --git a/app/src/main/java/io/legado/app/ui/theme/AppTheme.kt b/app/src/main/java/io/legado/app/ui/theme/AppTheme.kt new file mode 100644 index 000000000..3aa2b95c1 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/theme/AppTheme.kt @@ -0,0 +1,28 @@ +package io.legado.app.ui.theme + +import androidx.compose.material.MaterialTheme +import androidx.compose.material.darkColors +import androidx.compose.material.lightColors +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import io.legado.app.help.config.ThemeConfig +import io.legado.app.lib.theme.primaryColor +import splitties.init.appCtx + + +@Composable +fun AppTheme(content: @Composable () -> Unit) { + val colors = if (ThemeConfig.isDarkTheme()) { + darkColors( + primary = Color(appCtx.primaryColor), + ) + } else { + lightColors( + primary = Color(appCtx.primaryColor), + ) + } + MaterialTheme( + colors = colors, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 039603e2f..5f2feefe6 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -9,6 +9,7 @@ import io.legado.app.constant.Theme import io.legado.app.data.appDb import io.legado.app.databinding.ActivityWelcomeBinding import io.legado.app.help.config.AppConfig +import io.legado.app.help.config.ThemeConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.AppWebDav import io.legado.app.lib.theme.accentColor @@ -61,7 +62,7 @@ open class WelcomeActivity : BaseActivity() { override fun upBackgroundImage() { if (getPrefBoolean(PreferKey.customWelcome)) { kotlin.runCatching { - when (Theme.getTheme()) { + when (ThemeConfig.getTheme()) { Theme.Dark -> getPrefString(PreferKey.welcomeImageDark)?.let { path -> val size = windowManager.windowSize BitmapUtils.decodeBitmap(path, size.widthPixels, size.heightPixels).let { diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index d839b5170..3c3e68813 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -86,4 +86,9 @@ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:listitem="@layout/item_source_edit" /> + + \ No newline at end of file