From aa507d214a87a7ec2c509b2ed7906991e385f397 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 4 Sep 2020 12:12:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BF=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 21 +++++++------ .../read/{Help.kt => ReadBookActivityHelp.kt} | 31 +++---------------- .../io/legado/app/ui/book/read/ReadMenu.kt | 4 ++- .../ui/book/read/config/BgTextConfigDialog.kt | 4 +-- .../ui/book/read/config/MoreConfigDialog.kt | 4 +-- .../ui/book/read/config/TipConfigDialog.kt | 4 +-- .../page/delegate/HorizontalPageDelegate.kt | 9 ++++-- .../book/read/page/delegate/PageDelegate.kt | 2 +- .../java/io/legado/app/utils/SystemUtils.kt | 26 ++++++++++++++++ 9 files changed, 59 insertions(+), 46 deletions(-) rename app/src/main/java/io/legado/app/ui/book/read/{Help.kt => ReadBookActivityHelp.kt} (87%) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 4a1f224fe..fe21c3b40 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -89,7 +89,8 @@ class ReadBookActivity : VMBaseActivity(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(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(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(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(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(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) } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt similarity index 87% rename from app/src/main/java/io/legado/app/ui/book/read/Help.kt rename to app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt index 6a6a59912..558975cba 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt @@ -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 - } - /** * 保持亮屏 */ 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 8dd04832e..6d069ff68 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 @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index eaaf2f4d4..c4dd34127 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -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) } } } 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 1e7aa8d1c..4a3b4bd23 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 @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index 2a6f414cb..325279977 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 3ce2dce01..9aa807cb8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -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() + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 21dc78dcd..62ec34923 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/utils/SystemUtils.kt b/app/src/main/java/io/legado/app/utils/SystemUtils.kt index c29381bbf..b8027528d 100644 --- a/app/src/main/java/io/legado/app/utils/SystemUtils.kt +++ b/app/src/main/java/io/legado/app/utils/SystemUtils.kt @@ -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 + } }