mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
d9e08cfed7
commit
d639e4957b
@ -5,7 +5,7 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -70,6 +70,9 @@ class PermissionActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun openSettingsActivity() {
|
||||
@ -108,12 +111,6 @@ class PermissionActivity : AppCompatActivity() {
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||
return if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
true
|
||||
} else super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
private fun showSettingDialog(
|
||||
permissions: Array<String>,
|
||||
rationale: CharSequence?,
|
||||
|
@ -1,13 +1,11 @@
|
||||
package io.legado.app.ui.book.changesource
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.view.KeyEvent.ACTION_UP
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.os.bundleOf
|
||||
@ -56,7 +54,6 @@ import kotlinx.coroutines.launch
|
||||
|
||||
class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source),
|
||||
Toolbar.OnMenuItemClickListener,
|
||||
DialogInterface.OnKeyListener,
|
||||
ChangeChapterSourceAdapter.CallBack,
|
||||
ChangeChapterTocAdapter.Callback {
|
||||
|
||||
@ -111,7 +108,6 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setLayout(1f, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
dialog?.setOnKeyListener(this)
|
||||
}
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@ -125,6 +121,13 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
initBottomBar()
|
||||
initLiveData()
|
||||
viewModel.searchFinishCallback = searchFinishCallback
|
||||
activity?.onBackPressedDispatcher?.addCallback(this) {
|
||||
if (binding.clToc.isVisible) {
|
||||
binding.clToc.gone()
|
||||
return@addCallback
|
||||
}
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showTitle() {
|
||||
@ -392,18 +395,6 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKey(dialog: DialogInterface?, keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> event?.let {
|
||||
if (it.action == ACTION_UP && binding.clToc.isVisible) {
|
||||
binding.clToc.gone()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
val oldBook: Book?
|
||||
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>)
|
||||
|
@ -5,11 +5,11 @@ import android.content.pm.ActivityInfo
|
||||
import android.net.Uri
|
||||
import android.net.http.SslError
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.webkit.*
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.size
|
||||
import io.legado.app.R
|
||||
@ -57,6 +57,18 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
binding.webView.loadDataWithBaseURL(url, html, "text/html", "utf-8", url)
|
||||
}
|
||||
}
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (binding.customWebView.size > 0) {
|
||||
customWebViewCallback?.onCustomViewHidden()
|
||||
return@addCallback
|
||||
} else if (binding.webView.canGoBack()
|
||||
&& binding.webView.copyBackForwardList().size > 1
|
||||
) {
|
||||
binding.webView.goBack()
|
||||
return@addCallback
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@ -145,33 +157,6 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> {
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onKeyLongPress(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
event?.let {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled && binding.webView.canGoBack()) {
|
||||
if (binding.customWebView.size > 0) {
|
||||
customWebViewCallback?.onCustomViewHidden()
|
||||
return true
|
||||
} else if (binding.webView.copyBackForwardList().size > 1) {
|
||||
binding.webView.goBack()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode, event)
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
SourceVerificationHelp.checkResult(viewModel.key)
|
||||
super.finish()
|
||||
|
@ -4,11 +4,11 @@ package io.legado.app.ui.main
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils
|
||||
import android.view.KeyEvent
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.postDelayed
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -89,6 +89,27 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
|
||||
bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
|
||||
}
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (pagePosition != 0) {
|
||||
binding.viewPagerMain.currentItem = 0
|
||||
return@addCallback
|
||||
}
|
||||
(fragmentMap[getFragmentId(0)] as? BookshelfFragment2)?.let {
|
||||
if (it.back()) {
|
||||
return@addCallback
|
||||
}
|
||||
}
|
||||
if (System.currentTimeMillis() - exitTime > 2000) {
|
||||
toastOnUi(R.string.double_click_exit)
|
||||
exitTime = System.currentTimeMillis()
|
||||
} else {
|
||||
if (BaseReadAloudService.pause) {
|
||||
finish()
|
||||
} else {
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
||||
@ -263,36 +284,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
event?.let {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled) {
|
||||
if (pagePosition != 0) {
|
||||
binding.viewPagerMain.currentItem = 0
|
||||
return true
|
||||
}
|
||||
(fragmentMap[getFragmentId(0)] as? BookshelfFragment2)?.let {
|
||||
if (it.back()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if (System.currentTimeMillis() - exitTime > 2000) {
|
||||
toastOnUi(R.string.double_click_exit)
|
||||
exitTime = System.currentTimeMillis()
|
||||
} else {
|
||||
if (BaseReadAloudService.pause) {
|
||||
finish()
|
||||
} else {
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
if (AppConfig.autoRefreshBook) {
|
||||
|
@ -8,6 +8,7 @@ import android.net.http.SslError
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.webkit.*
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.size
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
@ -65,6 +66,18 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
||||
initWebView()
|
||||
initLiveData()
|
||||
viewModel.initData(intent)
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (binding.customWebView.size > 0) {
|
||||
customWebViewCallback?.onCustomViewHidden()
|
||||
return@addCallback
|
||||
} else if (binding.webView.canGoBack()
|
||||
&& binding.webView.copyBackForwardList().size > 1
|
||||
) {
|
||||
binding.webView.goBack()
|
||||
return@addCallback
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@ -262,33 +275,6 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> {
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onKeyLongPress(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
event?.let {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled && binding.webView.canGoBack()) {
|
||||
if (binding.customWebView.size > 0) {
|
||||
customWebViewCallback?.onCustomViewHidden()
|
||||
return true
|
||||
} else if (binding.webView.copyBackForwardList().size > 1) {
|
||||
binding.webView.goBack()
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode, event)
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private fun readAloud() {
|
||||
if (viewModel.tts?.isSpeaking == true) {
|
||||
|
Loading…
Reference in New Issue
Block a user