优化翻页

pull/357/head
gedoor 4 years ago
parent 03a94956be
commit aa507d214a
  1. 21
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 31
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  7. 9
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  9. 26
      app/src/main/java/io/legado/app/utils/SystemUtils.kt

@ -89,7 +89,8 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override val isInitFinish: Boolean get() = viewModel.isInitFinish
private val mHandler = Handler()
private val keepScreenRunnable: Runnable = Runnable { Help.keepScreenOn(window, false) }
private val keepScreenRunnable: Runnable =
Runnable { ReadBookActivityHelp.keepScreenOn(window, false) }
private val autoPageRunnable: Runnable = Runnable { autoPagePlus() }
override var autoPageProgress = 0
override var isAutoPage = false
@ -100,12 +101,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
Help.setOrientation(this)
ReadBookActivityHelp.setOrientation(this)
super.onCreate(savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
Help.upLayoutInDisplayCutoutMode(window)
ReadBookActivityHelp.upLayoutInDisplayCutoutMode(window)
initView()
upScreenTimeOut()
ReadBook.callBack = this
@ -248,8 +249,8 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
viewModel.refreshContent(it)
}
}
R.id.menu_download -> Help.showDownloadDialog(this)
R.id.menu_add_bookmark -> Help.showBookMark(this)
R.id.menu_download -> ReadBookActivityHelp.showDownloadDialog(this)
R.id.menu_add_bookmark -> ReadBookActivityHelp.showBookMark(this)
R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let {
@ -276,7 +277,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
Pair("loginUrl", it.loginUrl)
)
}
R.id.menu_set_charset -> Help.showCharsetConfig(this)
R.id.menu_set_charset -> ReadBookActivityHelp.showCharsetConfig(this)
}
return super.onCompatOptionsItemSelected(item)
}
@ -693,7 +694,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
* 更新状态栏,导航栏
*/
override fun upSystemUiVisibility() {
Help.upSystemUiVisibility(window, !read_menu.isVisible)
ReadBookActivityHelp.upSystemUiVisibility(window, !read_menu.isVisible)
upNavigationBarColor()
}
@ -854,16 +855,16 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
*/
override fun screenOffTimerStart() {
if (screenTimeOut < 0) {
Help.keepScreenOn(window, true)
ReadBookActivityHelp.keepScreenOn(window, true)
return
}
val t = screenTimeOut - sysScreenOffTime
if (t > 0) {
mHandler.removeCallbacks(keepScreenRunnable)
Help.keepScreenOn(window, true)
ReadBookActivityHelp.keepScreenOn(window, true)
mHandler.postDelayed(keepScreenRunnable, screenTimeOut)
} else {
Help.keepScreenOn(window, false)
ReadBookActivityHelp.keepScreenOn(window, false)
}
}
}

@ -6,8 +6,10 @@ import android.content.Context
import android.content.pm.ActivityInfo
import android.os.AsyncTask
import android.os.Build
import android.view.*
import android.view.View.NO_ID
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.EditText
import io.legado.app.App
import io.legado.app.R
@ -28,9 +30,8 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import org.jetbrains.anko.layoutInflater
object Help {
object ReadBookActivityHelp {
private const val NAVIGATION = "navigationBarBackground"
/**
* 更新状态栏,导航栏
@ -76,28 +77,6 @@ object Help {
}
/**
* 返回NavigationBar是否存在
* 该方法需要在View完全被绘制出来之后调用否则判断不了
* 在比如 onWindowFocusChanged方法中可以得到正确的结果
*/
fun isNavigationBarExist(activity: Activity?): Boolean {
activity?.let {
val vp = it.window.decorView as? ViewGroup
if (vp != null) {
for (i in 0 until vp.childCount) {
vp.getChildAt(i).context.packageName
if (vp.getChildAt(i).id != NO_ID
&& NAVIGATION == activity.resources.getResourceEntryName(vp.getChildAt(i).id)
) {
return true
}
}
}
}
return false
}
/**
* 保持亮屏
*/

@ -239,7 +239,9 @@ class ReadMenu : FrameLayout {
vw_menu_bg.onClick { runMenuOut() }
vwNavigationBar.layoutParams = vwNavigationBar.layoutParams.apply {
height =
if (ReadBookConfig.hideNavigationBar && Help.isNavigationBarExist(activity))
if (ReadBookConfig.hideNavigationBar
&& SystemUtils.isNavigationBarExist(activity)
)
context.navigationBarHeight
else 0
}

@ -23,7 +23,7 @@ import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.ui.book.read.Help
import io.legado.app.ui.book.read.ReadBookActivityHelp
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_read_bg_text.*
import kotlinx.android.synthetic.main.item_bg_image.view.*
@ -100,7 +100,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
if (buttonView?.isPressed == true) {
setStatusIconDark(isChecked)
activity?.window?.let {
Help.upSystemUiVisibility(it)
ReadBookActivityHelp.upSystemUiVisibility(it)
}
}
}

@ -15,7 +15,7 @@ import io.legado.app.constant.PreferKey
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.ui.book.read.ReadBookActivityHelp
import io.legado.app.utils.dp
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent
@ -107,7 +107,7 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key))
getString(R.string.pk_requested_direction) -> {
activity?.let {
Help.setOrientation(it)
ReadBookActivityHelp.setOrientation(it)
}
}
PreferKey.textFullJustify,

@ -10,7 +10,7 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.help.ReadTipConfig
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.book.read.Help
import io.legado.app.ui.book.read.ReadBookActivityHelp
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.dialog_tip_config.*
import org.jetbrains.anko.sdk27.listeners.onCheckedChange
@ -25,7 +25,7 @@ class TipConfigDialog : BaseDialogFragment() {
it.windowManager?.defaultDisplay?.getMetrics(dm)
}
dialog?.window?.let {
Help.upSystemUiVisibility(it)
ReadBookActivityHelp.upSystemUiVisibility(it)
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
}

@ -101,8 +101,13 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
override fun abortAnim() {
if (!scroller.isFinished) {
scroller.abortAnimation()
onAnimStop()
stopScroll()
isStarted = false
isMoved = false
isRunning = false
if (!isCancel) {
pageView.fillPage(mDirection)
pageView.invalidate()
}
}
}

@ -50,7 +50,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
var mDirection = Direction.NONE
var isCancel = false
var isRunning = false
private var isStarted = false
var isStarted = false
private var selectedOnDown = false

@ -8,11 +8,15 @@ import android.content.Intent
import android.net.Uri
import android.os.PowerManager
import android.provider.Settings
import android.view.View
import android.view.ViewGroup
@Suppress("unused")
object SystemUtils {
private const val NAVIGATION = "navigationBarBackground"
fun getScreenOffTime(context: Context): Int {
var screenOffTime = 0
try {
@ -44,4 +48,26 @@ object SystemUtils {
}
}
/**
* 返回NavigationBar是否存在
* 该方法需要在View完全被绘制出来之后调用否则判断不了
* 在比如 onWindowFocusChanged方法中可以得到正确的结果
*/
fun isNavigationBarExist(activity: Activity?): Boolean {
activity?.let {
val vp = it.window.decorView as? ViewGroup
if (vp != null) {
for (i in 0 until vp.childCount) {
vp.getChildAt(i).context.packageName
if (vp.getChildAt(i).id != View.NO_ID
&& NAVIGATION == activity.resources.getResourceEntryName(vp.getChildAt(i).id)
) {
return true
}
}
}
}
return false
}
}

Loading…
Cancel
Save