This commit is contained in:
kunfei 2023-07-31 22:32:24 +08:00
parent 93029ed1a1
commit d9e08cfed7
3 changed files with 24 additions and 56 deletions

View File

@ -27,6 +27,7 @@
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme.Light"
android:enableOnBackInvokedCallback="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnusedAttribute">
<!-- 主入口 -->
<activity

View File

@ -7,6 +7,7 @@ import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.view.*
import androidx.activity.addCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.get
@ -184,6 +185,28 @@ class ReadBookActivity : BaseReadBookActivity(),
upScreenTimeOut()
ReadBook.callBack?.notifyBookChanged()
ReadBook.callBack = this
onBackPressedDispatcher.addCallback(this) {
if (isShowingSearchResult) {
exitSearchMenu()
restoreLastBookProcess()
return@addCallback
}
//拦截返回供恢复阅读进度
if (ReadBook.lastBookPress != null && confirmRestoreProcess != false) {
restoreLastBookProcess()
return@addCallback
}
if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(this@ReadBookActivity)
toastOnUi(R.string.read_aloud_pause)
return@addCallback
}
if (isAutoPage) {
autoPageStop()
return@addCallback
}
finish()
}
}
override fun onPostCreate(savedInstanceState: Bundle?) {
@ -544,35 +567,10 @@ class ReadBookActivity : BaseReadBookActivity(),
return true
}
keyCode == KeyEvent.KEYCODE_BACK -> {
if (isShowingSearchResult) {
exitSearchMenu()
restoreLastBookProcess()
return true
}
//拦截返回供恢复阅读进度
if (ReadBook.lastBookPress != null && confirmRestoreProcess != false) {
restoreLastBookProcess()
return true
}
}
}
return super.onKeyDown(keyCode, event)
}
/**
* 长按事件
*/
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
finish()
return true
}
}
return super.onKeyLongPress(keyCode, event)
}
/**
* 松开按键事件
*/
@ -584,30 +582,6 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
KeyEvent.KEYCODE_BACK -> {
event?.let {
if ((event.flags and KeyEvent.FLAG_CANCELED_LONG_PRESS == 0)
&& event.isTracking
&& !event.isCanceled
) {
if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(this)
toastOnUi(R.string.read_aloud_pause)
return true
}
if (isAutoPage) {
autoPageStop()
return true
}
if (getPrefBoolean("disableReturnKey")) {
if (menuLayoutIsVisible) {
finish()
}
return true
}
}
}
}
}
return super.onKeyUp(keyCode, event)
}

View File

@ -149,13 +149,6 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="disableReturnKey"
android:title="@string/disable_return_key"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.lib.prefs.Preference
android:key="customPageKey"
android:title="@string/custom_page_key"