优化代码

pull/540/head
gedoor 4 years ago
parent 045bbd7c42
commit 4234de1c32
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 4
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  5. 3
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  6. 1
      app/src/main/res/values/pref_key_value.xml
  7. 2
      app/src/main/res/xml/pref_config_read.xml

@ -61,6 +61,7 @@ object PreferKey {
const val autoClearExpired = "autoClearExpired"
const val autoChangeSource = "autoChangeSource"
const val importKeepName = "importKeepName"
const val screenDirection = "screenDirection"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

@ -79,8 +79,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
context.putPrefBoolean(PreferKey.transparentStatusBar, value)
}
val requestedDirection: String?
get() = context.getPrefString(R.string.pk_requested_direction)
val screenDirection: String?
get() = context.getPrefString(PreferKey.screenDirection)
var backupPath: String?
get() = context.getPrefString(PreferKey.backupPath)

@ -77,7 +77,7 @@ abstract class ReadBookBaseActivity :
*/
@SuppressLint("SourceLockedOrientationActivity")
fun setOrientation() {
when (AppConfig.requestedDirection) {
when (AppConfig.screenDirection) {
"0" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
"1" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
"2" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

@ -41,7 +41,7 @@ class MoreConfigDialog : DialogFragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
(activity as ReadBookActivity).bottomDialog++
val view = LinearLayout(context)
view.setBackgroundColor(requireContext().bottomBackground)
@ -107,7 +107,7 @@ class MoreConfigDialog : DialogFragment() {
}
PreferKey.keepLight -> postEvent(key, true)
PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key))
getString(R.string.pk_requested_direction) -> {
PreferKey.screenDirection -> {
(activity as? ReadBookActivity)?.setOrientation()
}
PreferKey.textFullJustify,

@ -53,9 +53,6 @@ fun Context.putPrefLong(key: String, value: Long) =
fun Context.getPrefString(key: String, defValue: String? = null) =
defaultSharedPreferences.getString(key, defValue)
fun Context.getPrefString(@StringRes keyId: Int, defValue: String? = null) =
defaultSharedPreferences.getString(getString(keyId), defValue)
fun Context.putPrefString(key: String, value: String?) =
defaultSharedPreferences.edit { putString(key, value) }

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pk_auto_refresh" translatable="false">auto_refresh</string>
<string name="pk_requested_direction" translatable="false">list_screen_direction</string>
<string name="pk_bookshelf_px" translatable="false">bookshelf_px</string>
<string name="pk_default_read" translatable="false">defaultToRead</string>
<string name="legado_gzh" translatable="false">开源阅读</string>

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.ui.widget.prefs.NameListPreference
android:key="@string/pk_requested_direction"
android:key="screenDirection"
android:defaultValue="0"
android:title="@string/screen_direction"
android:entries="@array/screen_direction_title"

Loading…
Cancel
Save