mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +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.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.KeyEvent
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -70,6 +70,9 @@ class PermissionActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openSettingsActivity() {
|
private fun openSettingsActivity() {
|
||||||
@ -108,12 +111,6 @@ class PermissionActivity : AppCompatActivity() {
|
|||||||
overridePendingTransition(0, 0)
|
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(
|
private fun showSettingDialog(
|
||||||
permissions: Array<String>,
|
permissions: Array<String>,
|
||||||
rationale: CharSequence?,
|
rationale: CharSequence?,
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package io.legado.app.ui.book.changesource
|
package io.legado.app.ui.book.changesource
|
||||||
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.KeyEvent
|
|
||||||
import android.view.KeyEvent.ACTION_UP
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
@ -56,7 +54,6 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source),
|
class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source),
|
||||||
Toolbar.OnMenuItemClickListener,
|
Toolbar.OnMenuItemClickListener,
|
||||||
DialogInterface.OnKeyListener,
|
|
||||||
ChangeChapterSourceAdapter.CallBack,
|
ChangeChapterSourceAdapter.CallBack,
|
||||||
ChangeChapterTocAdapter.Callback {
|
ChangeChapterTocAdapter.Callback {
|
||||||
|
|
||||||
@ -111,7 +108,6 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
|||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
setLayout(1f, ViewGroup.LayoutParams.MATCH_PARENT)
|
setLayout(1f, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||||
dialog?.setOnKeyListener(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
@ -125,6 +121,13 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
|||||||
initBottomBar()
|
initBottomBar()
|
||||||
initLiveData()
|
initLiveData()
|
||||||
viewModel.searchFinishCallback = searchFinishCallback
|
viewModel.searchFinishCallback = searchFinishCallback
|
||||||
|
activity?.onBackPressedDispatcher?.addCallback(this) {
|
||||||
|
if (binding.clToc.isVisible) {
|
||||||
|
binding.clToc.gone()
|
||||||
|
return@addCallback
|
||||||
|
}
|
||||||
|
dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showTitle() {
|
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 {
|
interface CallBack {
|
||||||
val oldBook: Book?
|
val oldBook: Book?
|
||||||
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>)
|
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.Uri
|
||||||
import android.net.http.SslError
|
import android.net.http.SslError
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.KeyEvent
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.webkit.*
|
import android.webkit.*
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.core.view.size
|
import androidx.core.view.size
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
@ -57,6 +57,18 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
|||||||
binding.webView.loadDataWithBaseURL(url, html, "text/html", "utf-8", url)
|
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 {
|
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() {
|
override fun finish() {
|
||||||
SourceVerificationHelp.checkResult(viewModel.key)
|
SourceVerificationHelp.checkResult(viewModel.key)
|
||||||
super.finish()
|
super.finish()
|
||||||
|
@ -4,11 +4,11 @@ package io.legado.app.ui.main
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.view.KeyEvent
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.core.view.postDelayed
|
import androidx.core.view.postDelayed
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@ -89,6 +89,27 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
|||||||
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
|
bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
|
||||||
bottomNavigationView.setOnNavigationItemReselectedListener(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 {
|
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) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
if (AppConfig.autoRefreshBook) {
|
if (AppConfig.autoRefreshBook) {
|
||||||
|
@ -8,6 +8,7 @@ import android.net.http.SslError
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.webkit.*
|
import android.webkit.*
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.core.view.size
|
import androidx.core.view.size
|
||||||
import com.script.rhino.RhinoScriptEngine
|
import com.script.rhino.RhinoScriptEngine
|
||||||
@ -65,6 +66,18 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
initWebView()
|
initWebView()
|
||||||
initLiveData()
|
initLiveData()
|
||||||
viewModel.initData(intent)
|
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")
|
@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")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
private fun readAloud() {
|
private fun readAloud() {
|
||||||
if (viewModel.tts?.isSpeaking == true) {
|
if (viewModel.tts?.isSpeaking == true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user