pull/32/head
parent
6bb230acb6
commit
c35b7be932
@ -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,15 @@ |
|||||||
|
package io.legado.app.ui.config |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import androidx.preference.PreferenceFragmentCompat |
||||||
|
import io.legado.app.R |
||||||
|
|
||||||
|
|
||||||
|
class ThemeConfigFragment : PreferenceFragmentCompat() { |
||||||
|
|
||||||
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
||||||
|
addPreferencesFromResource(R.xml.pref_config_theme) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,2 +1,32 @@ |
|||||||
package io.legado.app.utils |
package io.legado.app.utils |
||||||
|
|
||||||
|
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.App |
||||||
|
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 |
||||||
|
|
||||||
|
val Menu.initIconColor: Menu |
||||||
|
get() = this.let { menu -> |
||||||
|
if (menu is MenuBuilder) { |
||||||
|
menu.setOptionalIconsVisible(true) |
||||||
|
} |
||||||
|
val primaryTextColor = |
||||||
|
App.INSTANCE.getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(App.INSTANCE))) |
||||||
|
val defaultTextColor = App.INSTANCE.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"?> |
||||||
|
<PreferenceScreen |
||||||
|
> |
||||||
|
|
||||||
|
|
||||||
|
</PreferenceScreen> |
@ -0,0 +1,85 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<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"/> |
||||||
|
|
||||||
|
<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"/> |
||||||
|
|
||||||
|
<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"/> |
||||||
|
|
||||||
|
<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"/> |
||||||
|
|
||||||
|
<Preference |
||||||
|
android:key="defaultTheme" |
||||||
|
android:summary="@string/restore_default_theme" |
||||||
|
android:title="@string/default_theme"/> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory android:title="白天"> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_100" |
||||||
|
android:key="colorPrimary" |
||||||
|
android:summary="白天,主色调" |
||||||
|
android:title="主色调" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_pink_600" |
||||||
|
android:key="colorAccent" |
||||||
|
android:summary="白天,强调色" |
||||||
|
android:title="强调色" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_100" |
||||||
|
android:key="colorBackground" |
||||||
|
android:summary="白天,背景色" |
||||||
|
android:title="背景色" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
</io.legado.app.lib.theme.prefs.ATEPreferenceCategory> |
||||||
|
|
||||||
|
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory android:title="夜间"> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_800" |
||||||
|
android:key="colorPrimaryNight" |
||||||
|
android:summary="夜间,主色调" |
||||||
|
android:title="主色调" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_pink_800" |
||||||
|
android:key="colorAccentNight" |
||||||
|
android:summary="夜间,强调色" |
||||||
|
android:title="强调色" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat |
||||||
|
android:defaultValue="@color/md_grey_800" |
||||||
|
android:key="colorBackgroundNight" |
||||||
|
android:summary="夜间,背景色" |
||||||
|
android:title="背景色" |
||||||
|
app:cpv_dialogType="preset"/> |
||||||
|
|
||||||
|
</io.legado.app.lib.theme.prefs.ATEPreferenceCategory> |
||||||
|
|
||||||
|
</PreferenceScreen> |
Loading…
Reference in new issue