diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 0574813a2..6e3b8ece2 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -25,6 +25,7 @@ abstract class BaseActivity( private val layoutID: Int, private val fullScreen: Boolean = true, private val theme: Theme = Theme.Auto, + private val toolBarTheme: Theme = Theme.Auto, private val transparent: Boolean = false ) : AppCompatActivity(), CoroutineScope by MainScope() { @@ -65,7 +66,7 @@ abstract class BaseActivity( final override fun onCreateOptionsMenu(menu: Menu?): Boolean { return menu?.let { val bool = onCompatCreateOptionsMenu(it) - it.applyTint(this, theme) + it.applyTint(this, toolBarTheme) bool } ?: super.onCreateOptionsMenu(menu) } @@ -129,9 +130,9 @@ abstract class BaseActivity( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE } ATH.setStatusBarColorAuto(this, fullScreen) - if (theme == Theme.Dark) { + if (toolBarTheme == Theme.Dark) { ATH.setLightStatusBar(this, false) - } else if (theme == Theme.Light) { + } else if (toolBarTheme == Theme.Light) { ATH.setLightStatusBar(this, true) } upNavigationBarColor() diff --git a/app/src/main/java/io/legado/app/base/VMBaseActivity.kt b/app/src/main/java/io/legado/app/base/VMBaseActivity.kt index 3643588af..f8de615de 100644 --- a/app/src/main/java/io/legado/app/base/VMBaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/VMBaseActivity.kt @@ -6,8 +6,9 @@ import io.legado.app.constant.Theme abstract class VMBaseActivity( layoutID: Int, fullScreen: Boolean = true, - theme: Theme = Theme.Auto -) : BaseActivity(layoutID, fullScreen, theme) { + theme: Theme = Theme.Auto, + toolBarTheme: Theme = Theme.Auto +) : BaseActivity(layoutID, fullScreen, theme, toolBarTheme) { protected abstract val viewModel: VM 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 a4f313a80..720c339f9 100644 --- a/app/src/main/java/io/legado/app/constant/Theme.kt +++ b/app/src/main/java/io/legado/app/constant/Theme.kt @@ -1,6 +1,7 @@ package io.legado.app.constant import io.legado.app.help.AppConfig +import io.legado.app.utils.ColorUtils enum class Theme { Dark, Light, Auto, Transparent; @@ -11,5 +12,13 @@ enum class Theme { Dark } else Light } + + fun getTheme(backgroundColor: Int): Theme { + return if (ColorUtils.isColorLight(backgroundColor)) { + Light + } else { + Dark + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index 2a339f46d..9ed2b173d 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -37,7 +37,7 @@ import org.jetbrains.anko.startActivityForResult class AudioPlayActivity : - VMBaseActivity(R.layout.activity_audio_play, theme = Theme.Dark), + VMBaseActivity(R.layout.activity_audio_play, toolBarTheme = Theme.Dark), ChangeSourceDialog.CallBack { override val viewModel: AudioPlayViewModel diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index d7c625c2f..906cacaf7 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -45,7 +45,7 @@ import org.jetbrains.anko.toast class BookInfoActivity : - VMBaseActivity(R.layout.activity_book_info, theme = Theme.Dark), + VMBaseActivity(R.layout.activity_book_info, toolBarTheme = Theme.Dark), GroupSelectDialog.CallBack, ChapterListAdapter.CallBack, ChangeSourceDialog.CallBack, @@ -58,6 +58,7 @@ class BookInfoActivity : override val viewModel: BookInfoViewModel get() = getViewModel(BookInfoViewModel::class.java) + @SuppressLint("PrivateResource") override fun onActivityCreated(savedInstanceState: Bundle?) { title_bar.transparent() arc_view.setBgColor(backgroundColor) diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 94d3b7be6..3b9d28757 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -45,8 +45,6 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a private val attachToActivity: Boolean init { - inflate(context, R.layout.view_title_bar, this) - toolbar = findViewById(R.id.toolbar) val a = context.obtainStyledAttributes( attrs, R.styleable.TitleBar, R.attr.titleBarStyle, 0 @@ -62,6 +60,12 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a val titleText = a.getString(R.styleable.TitleBar_title) val subtitleText = a.getString(R.styleable.TitleBar_subtitle) + when (a.getInt(R.styleable.TitleBar_themeMode, 0)) { + 1 -> inflate(context, R.layout.view_title_bar_dark, this) + else -> inflate(context, R.layout.view_title_bar, this) + } + toolbar = findViewById(R.id.toolbar) + toolbar.apply { navigationIcon?.let { this.navigationIcon = it diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index d99efc484..05a4b316a 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -19,7 +19,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent" - app:title="@string/book_info" /> + app:title="@string/book_info" + app:themeMode="dark" /> + app:layout_constraintTop_toTopOf="parent" + app:themeMode="dark" /> + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@id/title_bar" /> + app:tint="@color/md_white_1000" /> + app:tint="@color/md_white_1000" /> + app:tint="@color/md_white_1000" /> + app:tint="@color/md_white_1000" /> + app:tint="@color/md_white_1000" /> + android:contentDescription="@string/chapter_list" + app:tint="@color/md_white_1000" /> diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 02aaf18f3..e2d35458f 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -26,7 +26,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent" - app:title="@string/book_info" /> + app:title="@string/book_info" + app:themeMode="dark" /> + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 507cbc347..bdb8fd0b1 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -3,6 +3,11 @@ + + + + + @@ -25,6 +30,7 @@ +