diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 79353351c..fef825c70 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -81,7 +81,7 @@ object AppConfig { get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0" val isEInkMode: Boolean - get() = App.INSTANCE.getPrefBoolean("isEInkMode") + get() = App.INSTANCE.getPrefBoolean(PreferKey.einkMode) val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 9828bb3a1..abb739682 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -26,12 +26,25 @@ object ReadBookConfig { val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) GSON.fromJsonArray(json)!! } - val durConfig get() = getConfig(styleSelect) + val durConfig get() = + if (AppConfig.isEInkMode) + einkConfig + else + getConfig(styleSelect) + var bg: Drawable? = null var bgMeanColor: Int = 0 + val einkConfig:Config init { upConfig() + einkConfig = Config( + bgStr = "#FFFFFF", + bgStrNight = "#FFFFFF", + textColor = "#000000", + textColorNight = "#000000", + darkStatusIconNight = true + ) } @Synchronized diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index e44666349..17c7eb4e6 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -6,16 +6,16 @@ import android.os.Bundle import android.view.View import androidx.annotation.StringRes import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.utils.PreferenceFragmentSupport import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip import io.legado.app.utils.toast -class AboutFragment : PreferenceFragmentCompat() { +class AboutFragment : PreferenceFragmentSupport() { private val licenseUrl = "https://github.com/gedoor/legado/blob/master/LICENSE" private val disclaimerUrl = "https://gedoor.github.io/MyBookshelf/disclaimer.html" diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index b716c8f05..6223b5865 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -5,14 +5,14 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.utils.ACache +import io.legado.app.utils.PreferenceFragmentSupport import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip import org.jetbrains.anko.longToast -class DonateFragment : PreferenceFragmentCompat() { +class DonateFragment : PreferenceFragmentSupport() { private val zfbHbRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png" private val zfbSkRwmUrl = "https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg" diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 317af6aab..36793bed1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -194,8 +194,8 @@ class ReadMenu : FrameLayout { } private fun initAnimation() { - menuTopIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_top_in) - menuBottomIn = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_in) + menuTopIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_top_in) + menuBottomIn = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_in) menuTopIn.setAnimationListener(object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation) { callBack?.upSystemUiVisibility() @@ -217,8 +217,8 @@ class ReadMenu : FrameLayout { }) //隐藏菜单 - menuTopOut = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_top_out) - menuBottomOut = AnimationUtils.loadAnimation(context, R.anim.anim_readbook_bottom_out) + menuTopOut = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_top_out) + menuBottomOut = AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out) menuTopOut.setAnimationListener(object : Animation.AnimationListener { override fun onAnimationStart(animation: Animation) { vw_menu_bg.setOnClickListener(null) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 7033b82d0..cf1558087 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -10,7 +10,6 @@ import android.view.ViewGroup import android.widget.LinearLayout import androidx.fragment.app.DialogFragment import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey @@ -18,6 +17,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.bottomBackground import io.legado.app.ui.book.read.Help +import io.legado.app.utils.PreferenceFragmentSupport import io.legado.app.utils.dp import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent @@ -64,7 +64,7 @@ class MoreConfigDialog : DialogFragment() { .commit() } - class ReadPreferenceFragment : PreferenceFragmentCompat(), + class ReadPreferenceFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index cdb10159e..dd5eadf9c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -10,7 +10,6 @@ import android.widget.LinearLayout import androidx.fragment.app.DialogFragment import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey @@ -20,6 +19,7 @@ import io.legado.app.lib.theme.backgroundColor import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.ui.book.read.Help +import io.legado.app.utils.PreferenceFragmentSupport import io.legado.app.utils.postEvent class ReadAloudConfigDialog : DialogFragment() { @@ -59,7 +59,7 @@ class ReadAloudConfigDialog : DialogFragment() { .commit() } - class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), + class ReadAloudPreferenceFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 9df96e3f2..7ff39a7b3 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -8,15 +8,15 @@ import android.view.View import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.filechooser.FileChooserDialog +import io.legado.app.utils.PreferenceFragmentSupport import io.legado.app.utils.getPrefString -class BackupConfigFragment : PreferenceFragmentCompat(), +class BackupConfigFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener, FileChooserDialog.CallBack { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index f23fee053..07a70b110 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -7,7 +7,6 @@ import android.os.Bundle import android.view.View import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.constant.EventBus @@ -21,7 +20,7 @@ import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.* -class OtherConfigFragment : PreferenceFragmentCompat(), +class OtherConfigFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener { private val packageManager = App.INSTANCE.packageManager diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 6416040c3..774dd07e0 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -9,7 +9,6 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.constant.EventBus @@ -26,7 +25,7 @@ import io.legado.app.ui.widget.prefs.IconListPreference import io.legado.app.utils.* -class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { +class ThemeConfigFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener { val items = arrayListOf("极简", "曜夜", "经典", "黑白", "A屏黑") diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index dab9eb544..de219c0aa 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -7,13 +7,13 @@ import android.view.Menu import android.view.MenuItem import android.view.View import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity @@ -65,7 +65,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. BackupRestoreUi.onActivityResult(requestCode, resultCode, data) } - class PreferenceFragment : PreferenceFragmentCompat(), + class PreferenceFragment : PreferenceFragmentSupport(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -123,6 +123,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. "recordLog" -> LogUtils.upLevel() PreferKey.einkMode -> { postEvent(EventBus.RECREATE, "") + ReadBookConfig.pageAnim = 4 } } } diff --git a/app/src/main/java/io/legado/app/utils/AnimationUtilsSupport.kt b/app/src/main/java/io/legado/app/utils/AnimationUtilsSupport.kt new file mode 100644 index 000000000..1400b11f2 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/AnimationUtilsSupport.kt @@ -0,0 +1,17 @@ +package io.legado.app.utils + +import android.content.Context +import android.view.animation.Animation +import android.view.animation.AnimationUtils +import androidx.annotation.AnimRes +import io.legado.app.help.AppConfig + +object AnimationUtilsSupport { + fun loadAnimation(context: Context, @AnimRes id: Int): Animation { + val animation = AnimationUtils.loadAnimation(context, id) + if (AppConfig.isEInkMode) { + animation.duration = 0 + } + return animation + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/PreferenceFragmentSupport.kt b/app/src/main/java/io/legado/app/utils/PreferenceFragmentSupport.kt new file mode 100644 index 000000000..23848fb52 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/PreferenceFragmentSupport.kt @@ -0,0 +1,41 @@ +package io.legado.app.utils + +import android.content.pm.PackageManager +import android.os.Bundle +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.view.setPadding +import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceRecyclerViewAccessibilityDelegate +import androidx.recyclerview.widget.RecyclerView +import fadeapp.widgets.ScrollLessRecyclerView +import io.legado.app.R +import io.legado.app.help.AppConfig + +abstract class PreferenceFragmentSupport : PreferenceFragmentCompat(){ + + override fun onCreateRecyclerView( + inflater: LayoutInflater, + parent: ViewGroup, + savedInstanceState: Bundle? + ): RecyclerView { + + if (context?.packageManager?.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)==true) { + val recyclerView: RecyclerView?= parent.findViewById(R.id.recycler_view) + if (recyclerView != null) { + return recyclerView + } + } + val recyclerView = ScrollLessRecyclerView(inflater.context,null,R.attr.preferenceFragmentListStyle) + recyclerView.id = R.id.recycler_view + recyclerView.setPadding(0) + recyclerView.clipToPadding = false + recyclerView.isEnableScroll = !AppConfig.isEInkMode + recyclerView.layoutManager = onCreateLayoutManager() + recyclerView.setAccessibilityDelegateCompat( + PreferenceRecyclerViewAccessibilityDelegate(recyclerView) + ) + + return recyclerView + } +} \ No newline at end of file