pull/1705/head
kunfei 3 years ago
parent fbdda40afa
commit a2a8fd8831
  1. 3
      app/build.gradle
  2. 17
      app/src/main/java/io/legado/app/constant/Theme.kt
  3. 12
      app/src/main/java/io/legado/app/help/config/ThemeConfig.kt
  4. 3
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 28
      app/src/main/java/io/legado/app/ui/theme/AppTheme.kt
  6. 3
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  7. 5
      app/src/main/res/layout/activity_rss_source_edit.xml

@ -152,10 +152,11 @@ dependencies {
implementation('androidx.constraintlayout:constraintlayout:2.1.3') implementation('androidx.constraintlayout:constraintlayout:2.1.3')
implementation('androidx.swiperefreshlayout:swiperefreshlayout:1.1.0') implementation('androidx.swiperefreshlayout:swiperefreshlayout:1.1.0')
implementation('androidx.viewpager2:viewpager2:1.0.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.material:material:1.5.0')
implementation('com.google.android.flexbox:flexbox:3.0.0') implementation('com.google.android.flexbox:flexbox:3.0.0')
implementation('com.google.code.gson:gson:2.9.0') implementation('com.google.code.gson:gson:2.9.0')
implementation('androidx.webkit:webkit:1.4.0')
//lifecycle //lifecycle
def lifecycle_version = '2.4.1' def lifecycle_version = '2.4.1'

@ -1,22 +1,5 @@
package io.legado.app.constant package io.legado.app.constant
import io.legado.app.help.config.AppConfig
import io.legado.app.utils.ColorUtils
enum class Theme { enum class Theme {
Dark, Light, Auto, Transparent, EInk; 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
}
} }

@ -27,6 +27,16 @@ object ThemeConfig {
ArrayList(cList) 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) { fun applyDayNight(context: Context) {
ReadBookConfig.upBg() ReadBookConfig.upBg()
applyTheme(context) applyTheme(context)
@ -46,7 +56,7 @@ object ThemeConfig {
} }
fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? { fun getBgImage(context: Context, metrics: DisplayMetrics): Bitmap? {
val bgCfg = when (Theme.getTheme()) { val bgCfg = when (getTheme()) {
Theme.Light -> Pair( Theme.Light -> Pair(
context.getPrefString(PreferKey.bgImage), context.getPrefString(PreferKey.bgImage),
context.getPrefInt(PreferKey.bgImageBlurring, 0) context.getPrefInt(PreferKey.bgImageBlurring, 0)

@ -148,6 +148,9 @@ class RssSourceEditActivity :
private fun initView() { private fun initView() {
binding.recyclerView.setEdgeEffectColor(primaryColor) binding.recyclerView.setEdgeEffectColor(primaryColor)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.composeView.setContent {
}
} }
private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { private fun upRecyclerView(source: RssSource? = viewModel.rssSource) {

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

@ -9,6 +9,7 @@ import io.legado.app.constant.Theme
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityWelcomeBinding import io.legado.app.databinding.ActivityWelcomeBinding
import io.legado.app.help.config.AppConfig 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.coroutine.Coroutine
import io.legado.app.help.storage.AppWebDav import io.legado.app.help.storage.AppWebDav
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
@ -61,7 +62,7 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
override fun upBackgroundImage() { override fun upBackgroundImage() {
if (getPrefBoolean(PreferKey.customWelcome)) { if (getPrefBoolean(PreferKey.customWelcome)) {
kotlin.runCatching { kotlin.runCatching {
when (Theme.getTheme()) { when (ThemeConfig.getTheme()) {
Theme.Dark -> getPrefString(PreferKey.welcomeImageDark)?.let { path -> Theme.Dark -> getPrefString(PreferKey.welcomeImageDark)?.let { path ->
val size = windowManager.windowSize val size = windowManager.windowSize
BitmapUtils.decodeBitmap(path, size.widthPixels, size.heightPixels).let { BitmapUtils.decodeBitmap(path, size.widthPixels, size.heightPixels).let {

@ -86,4 +86,9 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_source_edit" /> tools:listitem="@layout/item_source_edit" />
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save