commit
afb58c356a
@ -0,0 +1,36 @@ |
|||||||
|
package io.legado.app.ui.config |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.base.BaseActivity |
||||||
|
import io.legado.app.utils.getViewModel |
||||||
|
import kotlinx.android.synthetic.main.activity_config.* |
||||||
|
import kotlinx.android.synthetic.main.view_titlebar.* |
||||||
|
|
||||||
|
class ConfigActivity : BaseActivity<ConfigViewModel>() { |
||||||
|
override val viewModel: ConfigViewModel |
||||||
|
get() = getViewModel(ConfigViewModel::class.java) |
||||||
|
override val layoutID: Int |
||||||
|
get() = R.layout.activity_config |
||||||
|
|
||||||
|
override fun onViewModelCreated(viewModel: ConfigViewModel, savedInstanceState: Bundle?) { |
||||||
|
intent.getIntExtra("configType", -1).let { |
||||||
|
if (it != -1) viewModel.configType = it |
||||||
|
} |
||||||
|
this.setSupportActionBar(toolbar) |
||||||
|
|
||||||
|
when (viewModel.configType) { |
||||||
|
ConfigViewModel.TYPE_CONFIG -> { |
||||||
|
title_bar.title = "设置" |
||||||
|
supportFragmentManager.beginTransaction().replace(R.id.configFrameLayout, ConfigFragment()).commit() |
||||||
|
} |
||||||
|
ConfigViewModel.TYPE_THEME_CONFIG -> { |
||||||
|
title_bar.title = "主题设置" |
||||||
|
supportFragmentManager.beginTransaction().replace(R.id.configFrameLayout, ThemeConfigFragment()) |
||||||
|
.commit() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package io.legado.app.ui.config |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import androidx.preference.PreferenceFragmentCompat |
||||||
|
import io.legado.app.R |
||||||
|
|
||||||
|
|
||||||
|
class ConfigFragment : PreferenceFragmentCompat() { |
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
||||||
|
addPreferencesFromResource(R.xml.pref_config) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package io.legado.app.ui.config |
||||||
|
|
||||||
|
import android.app.Application |
||||||
|
import androidx.lifecycle.AndroidViewModel |
||||||
|
|
||||||
|
class ConfigViewModel(application: Application) : AndroidViewModel(application) { |
||||||
|
companion object { |
||||||
|
val TYPE_CONFIG = 0 |
||||||
|
val TYPE_THEME_CONFIG = 1 |
||||||
|
} |
||||||
|
|
||||||
|
var configType: Int = TYPE_CONFIG |
||||||
|
|
||||||
|
} |
@ -0,0 +1,86 @@ |
|||||||
|
package io.legado.app.ui.config |
||||||
|
|
||||||
|
import android.content.SharedPreferences |
||||||
|
import android.os.Bundle |
||||||
|
import androidx.appcompat.app.AlertDialog |
||||||
|
import androidx.preference.PreferenceFragmentCompat |
||||||
|
import io.legado.app.App |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.lib.theme.ColorUtils |
||||||
|
import io.legado.app.utils.getCompatColor |
||||||
|
import io.legado.app.utils.getPrefBoolean |
||||||
|
import io.legado.app.utils.putPrefInt |
||||||
|
import io.legado.app.utils.upTint |
||||||
|
|
||||||
|
|
||||||
|
class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { |
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
||||||
|
addPreferencesFromResource(R.xml.pref_config_theme) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResume() { |
||||||
|
super.onResume() |
||||||
|
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onPause() { |
||||||
|
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) |
||||||
|
super.onPause() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { |
||||||
|
sharedPreferences ?: return |
||||||
|
when (key) { |
||||||
|
"colorPrimary", "colorAccent", "colorBackground" -> if (!ColorUtils.isColorLight( |
||||||
|
sharedPreferences.getInt( |
||||||
|
"colorBackground", |
||||||
|
App.INSTANCE.getCompatColor(R.color.md_grey_100) |
||||||
|
) |
||||||
|
) |
||||||
|
) { |
||||||
|
AlertDialog.Builder(App.INSTANCE) |
||||||
|
.setTitle("白天背景太暗") |
||||||
|
.setMessage("将会恢复默认背景?") |
||||||
|
.setPositiveButton(R.string.ok) { dialog, which -> |
||||||
|
App.INSTANCE.putPrefInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100)) |
||||||
|
upTheme(false) |
||||||
|
} |
||||||
|
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(false) } |
||||||
|
.show().upTint |
||||||
|
} else { |
||||||
|
upTheme(false) |
||||||
|
} |
||||||
|
"colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" -> if (ColorUtils.isColorLight( |
||||||
|
sharedPreferences.getInt( |
||||||
|
"colorBackgroundNight", |
||||||
|
App.INSTANCE.getCompatColor(R.color.md_grey_800) |
||||||
|
) |
||||||
|
) |
||||||
|
) { |
||||||
|
AlertDialog.Builder(App.INSTANCE) |
||||||
|
.setTitle("夜间背景太亮") |
||||||
|
.setMessage("将会恢复默认背景?") |
||||||
|
.setPositiveButton(R.string.ok) { dialog, which -> |
||||||
|
App.INSTANCE.putPrefInt( |
||||||
|
"colorBackgroundNight", |
||||||
|
App.INSTANCE.getCompatColor(R.color.md_grey_800) |
||||||
|
) |
||||||
|
upTheme(true) |
||||||
|
} |
||||||
|
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(true) } |
||||||
|
.show() |
||||||
|
} else { |
||||||
|
upTheme(true) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private fun upTheme(isNightTheme: Boolean) { |
||||||
|
if (App.INSTANCE.getPrefBoolean("isNightTheme", false) == isNightTheme) { |
||||||
|
App.INSTANCE.upThemeStore() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,2 +1,30 @@ |
|||||||
package io.legado.app.utils |
package io.legado.app.utils |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.view.Menu |
||||||
|
import androidx.appcompat.view.menu.MenuBuilder |
||||||
|
import androidx.appcompat.view.menu.MenuItemImpl |
||||||
|
import androidx.core.view.forEach |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.lib.theme.ColorUtils |
||||||
|
import io.legado.app.lib.theme.DrawableUtils |
||||||
|
import io.legado.app.lib.theme.ThemeStore |
||||||
|
import io.legado.app.lib.theme.getPrimaryTextColor |
||||||
|
|
||||||
|
fun Menu.setIconColor(context: Context): Menu = this.let { menu -> |
||||||
|
if (menu is MenuBuilder) { |
||||||
|
menu.setOptionalIconsVisible(true) |
||||||
|
} |
||||||
|
val primaryTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(context))) |
||||||
|
val defaultTextColor = context.getCompatColor(R.color.tv_text_default) |
||||||
|
menu.forEach { item -> |
||||||
|
(item as MenuItemImpl).let { impl -> |
||||||
|
//overflow:展开的item |
||||||
|
DrawableUtils.setTint( |
||||||
|
impl.icon, |
||||||
|
if (impl.requiresOverflow()) defaultTextColor else primaryTextColor |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
return menu |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
android:orientation="vertical" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
<io.legado.app.ui.widget.TitleBar |
||||||
|
android:id="@+id/title_bar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
app:title="设置"/> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:id="@+id/configFrameLayout" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:orientation="vertical"/> |
||||||
|
|
||||||
|
</LinearLayout> |
@ -0,0 +1,6 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.preference.PreferenceScreen |
||||||
|
> |
||||||
|
|
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen> |
@ -0,0 +1,101 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.preference.PreferenceScreen |
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||||
|
android:defaultValue="false" |
||||||
|
android:key="immersionStatusBar" |
||||||
|
android:summary="@string/status_bar_immersion" |
||||||
|
android:title="@string/immersion_status_bar" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||||
|
android:defaultValue="false" |
||||||
|
android:key="navigationBarColorChange" |
||||||
|
android:summary="@string/navigation_bar_color_change_s" |
||||||
|
android:title="@string/navigation_bar_color_change" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||||
|
android:defaultValue="true" |
||||||
|
android:key="behaviorMain" |
||||||
|
android:summary="@string/behavior_main_s" |
||||||
|
android:title="@string/behavior_main_t" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||||
|
android:defaultValue="false" |
||||||
|
android:key="E-InkMode" |
||||||
|
android:summary="@string/e_ink_mode_detail" |
||||||
|
android:title="@string/e_ink_mode" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<Preference |
||||||
|
android:key="defaultTheme" |
||||||
|
android:summary="@string/restore_default_theme" |
||||||
|
android:title="@string/default_theme" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory |
||||||
|
android:title="白天" |
||||||
|
app:iconSpaceReserved="false"> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_100" |
||||||
|
android:key="colorPrimary" |
||||||
|
android:summary="白天,主色调" |
||||||
|
android:title="主色调" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_pink_600" |
||||||
|
android:key="colorAccent" |
||||||
|
android:summary="白天,强调色" |
||||||
|
android:title="强调色" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_100" |
||||||
|
android:key="colorBackground" |
||||||
|
android:summary="白天,背景色" |
||||||
|
android:title="背景色" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
</io.legado.app.lib.theme.prefs.ATEPreferenceCategory> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory |
||||||
|
android:title="夜间" |
||||||
|
app:iconSpaceReserved="false"> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_800" |
||||||
|
android:key="colorPrimaryNight" |
||||||
|
android:summary="夜间,主色调" |
||||||
|
android:title="主色调" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_pink_800" |
||||||
|
android:key="colorAccentNight" |
||||||
|
android:summary="夜间,强调色" |
||||||
|
android:title="强调色" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_800" |
||||||
|
android:key="colorBackgroundNight" |
||||||
|
android:summary="夜间,背景色" |
||||||
|
android:title="背景色" |
||||||
|
app:cpv_dialogType="preset" |
||||||
|
app:iconSpaceReserved="false"/> |
||||||
|
|
||||||
|
</io.legado.app.lib.theme.prefs.ATEPreferenceCategory> |
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen> |
Loading…
Reference in new issue