Merge pull request #142 from yangyxd/master

主题设置中增加导航栏阴影设置
pull/145/head
kunfei 5 years ago committed by GitHub
commit 16ad9c6dfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 12
      app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt
  3. 5
      app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt
  4. 8
      app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt
  5. 2
      app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt
  6. 22
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  7. 9
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  8. 11
      app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt
  9. 4
      app/src/main/res/values/strings.xml
  10. 7
      app/src/main/res/xml/pref_config_theme.xml

@ -111,4 +111,9 @@ object AppConfig {
App.INSTANCE.putPrefBoolean("bookGroupAudio", value)
}
var elevation: Int
get() = App.INSTANCE.getPrefInt("elevation", -1)
set(value) {
App.INSTANCE.putPrefInt("elevation", value)
}
}

@ -19,4 +19,16 @@ object ATHUtils {
a.recycle()
}
}
@JvmOverloads
fun resolveFloat(context: Context, @AttrRes attr: Int, fallback: Float = 0.0f): Float {
val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
return try {
a.getFloat(0, fallback)
} catch (e: Exception) {
fallback
} finally {
a.recycle()
}
}
}

@ -107,4 +107,7 @@ val Context.isDarkTheme: Boolean
get() = ColorUtils.isColorLight(ThemeStore.primaryColor(this))
val Fragment.isDarkTheme: Boolean
get() = requireContext().isDarkTheme
get() = requireContext().isDarkTheme
val Context.elevation: Float
get() = ThemeStore.elevation(this)

@ -284,6 +284,14 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
)
}
@CheckResult
fun elevation(context: Context): Float {
return prefs(context).getFloat(
ThemeStorePrefKeys.KEY_ELEVATION,
ATHUtils.resolveFloat(context, android.R.attr.elevation, context.resources.getDimension(R.dimen.design_appbar_elevation))
)
}
@CheckResult
@ColorInt
fun bottomBackground(context: Context): Int {

@ -27,4 +27,6 @@ object ThemeStorePrefKeys {
const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar"
const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar"
const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
const val KEY_ELEVATION = "elevation"
}

@ -16,6 +16,8 @@ import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.elevation
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.utils.*
@ -25,6 +27,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme)
upPreferenceSummary("barElevation", AppConfig.elevation.toString())
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -145,6 +148,19 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
recreateActivities()
}
}.show().applyTint()
"barElevation" -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.bar_elevation))
.setMaxValue(32)
.setMinValue(0)
.setValue(AppConfig.elevation)
.setCustomButton((R.string.btn_default_s)) {
AppConfig.elevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
recreateActivities()
}
.show {
AppConfig.elevation = it
recreateActivities()
}
}
return super.onPreferenceTreeClick(preference)
}
@ -180,4 +196,10 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
postEvent(EventBus.RECREATE, "")
}
private fun upPreferenceSummary(preferenceKey: String, value: String?) {
val preference = findPreference<Preference>(preferenceKey) ?: return
when (preferenceKey) {
"barElevation" -> preference.summary = getString(R.string.bar_elevation_s, value)
}
}
}

@ -10,6 +10,8 @@ import androidx.annotation.StyleRes
import androidx.appcompat.widget.Toolbar
import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.elevation
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.activity
import io.legado.app.utils.navigationBarHeight
@ -140,6 +142,13 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
}
backgroundColor = context.primaryColor
// targetElevation = context.elevation
stateListAnimator = null
if (AppConfig.elevation < 0) {
elevation = context.elevation
} else {
elevation = AppConfig.elevation.toFloat()
}
a.recycle()
}

@ -40,6 +40,17 @@ class NumberPickerDialog(context: Context) {
return this
}
fun setCustomButton(textId: Int, listener: (() -> Unit)?): NumberPickerDialog {
builder.setNeutralButton(textId) { _, _ ->
numberPicker?.let {
it.clearFocus()
it.hideSoftInput()
listener?.invoke()
}
}
return this;
}
fun show(callBack: ((value: Int) -> Unit)?) {
builder.setPositiveButton(R.string.ok) { _, _ ->
numberPicker?.let {

@ -643,4 +643,8 @@
<string name="no_default_path">没有默认路径</string>
<string name="change_group">设置分组</string>
<string name="view_toc">查看目录</string>
<string name="bar_elevation">导航栏阴影</string>
<string name="bar_elevation_s">当前阴影大小(elevation): %s</string>
<string name="btn_default_s">默认</string>
</resources>

@ -26,6 +26,13 @@
android:title="@string/navigation_bar_color_change"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:defaultValue="true"
android:key="barElevation"
android:summary="@string/bar_elevation_s"
android:title="@string/bar_elevation"
app:iconSpaceReserved="false" />
<androidx.preference.Preference
android:key="defaultTheme"
android:summary="@string/restore_default_theme"

Loading…
Cancel
Save