修复主题bug

pull/332/head
gedoor 4 years ago
parent 5d5c61976d
commit b2ff27aa13
  1. 7
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 5
      app/src/main/java/io/legado/app/base/VMBaseActivity.kt
  3. 9
      app/src/main/java/io/legado/app/constant/Theme.kt
  4. 2
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  6. 8
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  7. 3
      app/src/main/res/layout-land/activity_book_info.xml
  8. 23
      app/src/main/res/layout/activity_audio_play.xml
  9. 3
      app/src/main/res/layout/activity_book_info.xml
  10. 9
      app/src/main/res/layout/view_title_bar_dark.xml
  11. 6
      app/src/main/res/values/attrs.xml

@ -25,6 +25,7 @@ abstract class BaseActivity(
private val layoutID: Int, private val layoutID: Int,
private val fullScreen: Boolean = true, private val fullScreen: Boolean = true,
private val theme: Theme = Theme.Auto, private val theme: Theme = Theme.Auto,
private val toolBarTheme: Theme = Theme.Auto,
private val transparent: Boolean = false private val transparent: Boolean = false
) : AppCompatActivity(), ) : AppCompatActivity(),
CoroutineScope by MainScope() { CoroutineScope by MainScope() {
@ -65,7 +66,7 @@ abstract class BaseActivity(
final override fun onCreateOptionsMenu(menu: Menu?): Boolean { final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let { return menu?.let {
val bool = onCompatCreateOptionsMenu(it) val bool = onCompatCreateOptionsMenu(it)
it.applyTint(this, theme) it.applyTint(this, toolBarTheme)
bool bool
} ?: super.onCreateOptionsMenu(menu) } ?: super.onCreateOptionsMenu(menu)
} }
@ -129,9 +130,9 @@ abstract class BaseActivity(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
} }
ATH.setStatusBarColorAuto(this, fullScreen) ATH.setStatusBarColorAuto(this, fullScreen)
if (theme == Theme.Dark) { if (toolBarTheme == Theme.Dark) {
ATH.setLightStatusBar(this, false) ATH.setLightStatusBar(this, false)
} else if (theme == Theme.Light) { } else if (toolBarTheme == Theme.Light) {
ATH.setLightStatusBar(this, true) ATH.setLightStatusBar(this, true)
} }
upNavigationBarColor() upNavigationBarColor()

@ -6,8 +6,9 @@ import io.legado.app.constant.Theme
abstract class VMBaseActivity<VM : ViewModel>( abstract class VMBaseActivity<VM : ViewModel>(
layoutID: Int, layoutID: Int,
fullScreen: Boolean = true, fullScreen: Boolean = true,
theme: Theme = Theme.Auto theme: Theme = Theme.Auto,
) : BaseActivity(layoutID, fullScreen, theme) { toolBarTheme: Theme = Theme.Auto
) : BaseActivity(layoutID, fullScreen, theme, toolBarTheme) {
protected abstract val viewModel: VM protected abstract val viewModel: VM

@ -1,6 +1,7 @@
package io.legado.app.constant package io.legado.app.constant
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.utils.ColorUtils
enum class Theme { enum class Theme {
Dark, Light, Auto, Transparent; Dark, Light, Auto, Transparent;
@ -11,5 +12,13 @@ enum class Theme {
Dark Dark
} else Light } else Light
} }
fun getTheme(backgroundColor: Int): Theme {
return if (ColorUtils.isColorLight(backgroundColor)) {
Light
} else {
Dark
}
}
} }
} }

@ -37,7 +37,7 @@ import org.jetbrains.anko.startActivityForResult
class AudioPlayActivity : class AudioPlayActivity :
VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play, theme = Theme.Dark), VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play, toolBarTheme = Theme.Dark),
ChangeSourceDialog.CallBack { ChangeSourceDialog.CallBack {
override val viewModel: AudioPlayViewModel override val viewModel: AudioPlayViewModel

@ -45,7 +45,7 @@ import org.jetbrains.anko.toast
class BookInfoActivity : class BookInfoActivity :
VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info, theme = Theme.Dark), VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info, toolBarTheme = Theme.Dark),
GroupSelectDialog.CallBack, GroupSelectDialog.CallBack,
ChapterListAdapter.CallBack, ChapterListAdapter.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
@ -58,6 +58,7 @@ class BookInfoActivity :
override val viewModel: BookInfoViewModel override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java) get() = getViewModel(BookInfoViewModel::class.java)
@SuppressLint("PrivateResource")
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
title_bar.transparent() title_bar.transparent()
arc_view.setBgColor(backgroundColor) arc_view.setBgColor(backgroundColor)

@ -45,8 +45,6 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
private val attachToActivity: Boolean private val attachToActivity: Boolean
init { init {
inflate(context, R.layout.view_title_bar, this)
toolbar = findViewById(R.id.toolbar)
val a = context.obtainStyledAttributes( val a = context.obtainStyledAttributes(
attrs, R.styleable.TitleBar, attrs, R.styleable.TitleBar,
R.attr.titleBarStyle, 0 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 titleText = a.getString(R.styleable.TitleBar_title)
val subtitleText = a.getString(R.styleable.TitleBar_subtitle) 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 { toolbar.apply {
navigationIcon?.let { navigationIcon?.let {
this.navigationIcon = it this.navigationIcon = it

@ -19,7 +19,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_info" /> app:title="@string/book_info"
app:themeMode="dark" />
<LinearLayout <LinearLayout
android:id="@+id/vw_bg" android:id="@+id/vw_bg"

@ -25,7 +25,8 @@
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
app:themeMode="dark" />
<TextView <TextView
android:id="@+id/tv_speed" android:id="@+id/tv_speed"
@ -37,8 +38,8 @@
android:paddingStart="3dp" android:paddingStart="3dp"
android:paddingEnd="3dp" android:paddingEnd="3dp"
android:visibility="invisible" android:visibility="invisible"
app:layout_constraintTop_toBottomOf="@id/title_bar" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintTop_toBottomOf="@id/title_bar" />
<io.legado.app.ui.widget.image.CircleImageView <io.legado.app.ui.widget.image.CircleImageView
android:id="@+id/iv_cover" android:id="@+id/iv_cover"
@ -46,8 +47,8 @@
android:layout_height="260dp" android:layout_height="260dp"
android:contentDescription="@string/img_cover" android:contentDescription="@string/img_cover"
android:scaleType="centerCrop" android:scaleType="centerCrop"
app:civ_border_width="2dp"
app:civ_border_color="@color/accent" app:civ_border_color="@color/accent"
app:civ_border_width="2dp"
app:layout_constraintBottom_toTopOf="@+id/ll_player_progress" app:layout_constraintBottom_toTopOf="@+id/ll_player_progress"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
@ -118,7 +119,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/set_timer" android:contentDescription="@string/set_timer"
android:src="@drawable/ic_timer_black_24dp" android:src="@drawable/ic_timer_black_24dp"
android:tint="@color/md_white_1000" /> app:tint="@color/md_white_1000" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
@ -132,7 +133,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/skip_previous" android:contentDescription="@string/skip_previous"
android:src="@drawable/ic_fast_rewind" android:src="@drawable/ic_fast_rewind"
android:tint="@color/md_white_1000" /> app:tint="@color/md_white_1000" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
@ -146,7 +147,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/skip_previous" android:contentDescription="@string/skip_previous"
android:src="@drawable/ic_skip_previous" android:src="@drawable/ic_skip_previous"
android:tint="@color/md_white_1000" /> app:tint="@color/md_white_1000" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_play_stop" android:id="@+id/fab_play_stop"
@ -168,7 +169,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/skip_next" android:contentDescription="@string/skip_next"
android:src="@drawable/ic_skip_next" android:src="@drawable/ic_skip_next"
android:tint="@color/md_white_1000" /> app:tint="@color/md_white_1000" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
@ -182,7 +183,7 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/skip_next" android:contentDescription="@string/skip_next"
android:src="@drawable/ic_fast_forward" android:src="@drawable/ic_fast_forward"
android:tint="@color/md_white_1000" /> app:tint="@color/md_white_1000" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
@ -195,8 +196,8 @@
android:layout_height="36dp" android:layout_height="36dp"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_chapter_list" android:src="@drawable/ic_chapter_list"
android:tint="@color/md_white_1000" android:contentDescription="@string/chapter_list"
android:contentDescription="@string/chapter_list" /> app:tint="@color/md_white_1000" />
</LinearLayout> </LinearLayout>

@ -26,7 +26,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_info" /> app:title="@string/book_info"
app:themeMode="dark" />
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay.Dark"
app:titleTextAppearance="@style/ToolbarTitle"
app:popupTheme="@style/AppTheme.PopupOverlay" />

@ -3,6 +3,11 @@
<attr name="radius" format="dimension" /> <attr name="radius" format="dimension" />
<attr name="isBottomBackground" format="boolean" /> <attr name="isBottomBackground" format="boolean" />
<attr name="themeMode" format="enum">
<enum name="dark" value="1" />
<enum name="light" value="2" />
<enum name="auto" value="0" />
</attr>
<declare-styleable name="TitleBar"> <declare-styleable name="TitleBar">
<attr name="title" /> <attr name="title" />
@ -25,6 +30,7 @@
<attr name="fitNavigationBar" format="boolean" /> <attr name="fitNavigationBar" format="boolean" />
<attr name="navigationContentDescription" format="reference|string" /> <attr name="navigationContentDescription" format="reference|string" />
<attr name="navigationIconTint" format="color|reference" /> <attr name="navigationIconTint" format="color|reference" />
<attr name="themeMode" />
<attr name="navigationIconTintMode" format="enum"> <attr name="navigationIconTintMode" format="enum">
<enum name="clear" value="0" /> <enum name="clear" value="0" />
<enum name="src" value="1" /> <enum name="src" value="1" />

Loading…
Cancel
Save