feat: 优化代码

pull/149/head
kunfei 5 years ago
parent ad00e02df0
commit 9a907f5f19
  1. 1
      app/src/main/AndroidManifest.xml
  2. 13
      app/src/main/java/io/legado/app/ui/book/read/Help.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 5
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  5. 7
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  6. 8
      app/src/main/res/xml/pref_config_other.xml
  7. 8
      app/src/main/res/xml/pref_config_read.xml

@ -185,6 +185,7 @@
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<activity <activity
android:name="io.legado.app.ui.book.chapterlist.ChapterListActivity" android:name="io.legado.app.ui.book.chapterlist.ChapterListActivity"
android:screenOrientation="behind"
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<!--RSS阅读--> <!--RSS阅读-->
<activity <activity

@ -3,6 +3,7 @@ package io.legado.app.ui.book.read
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.pm.ActivityInfo
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.view.* import android.view.*
@ -62,6 +63,18 @@ object Help {
} }
} }
@SuppressLint("SourceLockedOrientationActivity")
fun setOrientation(activity: Activity) = activity.apply {
when (AppConfig.requestedDirection) {
"0" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
"1" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
"2" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
"3" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
}
}
/** /**
* 返回NavigationBar是否存在 * 返回NavigationBar是否存在
* 该方法需要在View完全被绘制出来之后调用否则判断不了 * 该方法需要在View完全被绘制出来之后调用否则判断不了

@ -88,6 +88,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override val pageFactory: TextPageFactory get() = page_view.pageFactory override val pageFactory: TextPageFactory get() = page_view.pageFactory
override val headerHeight: Int get() = page_view.curPage.headerHeight override val headerHeight: Int get() = page_view.curPage.headerHeight
override fun onCreate(savedInstanceState: Bundle?) {
Help.setOrientation(this)
super.onCreate(savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
Help.upLayoutInDisplayCutoutMode(window) Help.upLayoutInDisplayCutoutMode(window)
initView() initView()

@ -104,6 +104,11 @@ class MoreConfigDialog : DialogFragment() {
} }
PreferKey.keepLight -> postEvent(key, true) PreferKey.keepLight -> postEvent(key, true)
PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key)) PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key))
getString(R.string.pk_requested_direction) -> {
activity?.let {
Help.setOrientation(it)
}
}
} }
} }

@ -43,10 +43,6 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
upPreferenceSummary(getString(R.string.pk_download_path), BookHelp.downloadPath) upPreferenceSummary(getString(R.string.pk_download_path), BookHelp.downloadPath)
upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString()) upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString())
upPreferenceSummary(PreferKey.webPort, webPort.toString()) upPreferenceSummary(PreferKey.webPort, webPort.toString())
upPreferenceSummary(
getString(R.string.pk_requested_direction),
AppConfig.requestedDirection
)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -107,9 +103,6 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
setProcessTextEnable(it.getBoolean(key, true)) setProcessTextEnable(it.getBoolean(key, true))
} }
PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused") PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused")
getString(R.string.pk_requested_direction) -> {
upPreferenceSummary(key, AppConfig.requestedDirection)
}
} }
} }

@ -6,14 +6,6 @@
android:title="@string/main_activity" android:title="@string/main_activity"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false">
<ListPreference
android:key="@string/pk_requested_direction"
android:defaultValue="0"
android:title="@string/screen_direction"
android:entries="@array/screen_direction_title"
android:entryValues="@array/screen_direction_value"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pk_auto_refresh" android:key="@string/pk_auto_refresh"

@ -2,6 +2,14 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.ui.widget.prefs.NameListPreference
android:key="@string/pk_requested_direction"
android:defaultValue="0"
android:title="@string/screen_direction"
android:entries="@array/screen_direction_title"
android:entryValues="@array/screen_direction_value"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.NameListPreference <io.legado.app.ui.widget.prefs.NameListPreference
android:key="keep_light" android:key="keep_light"
android:defaultValue="0" android:defaultValue="0"

Loading…
Cancel
Save