Merge pull request #1848 from Xwite/master
更新界面 使用startBrowserAwait卡顿的问题
This commit is contained in:
@@ -567,14 +567,14 @@ interface JsExtensions {
|
|||||||
* 弹窗提示
|
* 弹窗提示
|
||||||
*/
|
*/
|
||||||
fun toast(msg: Any?) {
|
fun toast(msg: Any?) {
|
||||||
appCtx.toastOnUi(msg.toString())
|
appCtx.toastOnUi("${getSource()?.getTag()}: ${msg.toString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 弹窗提示 停留时间较长
|
* 弹窗提示 停留时间较长
|
||||||
*/
|
*/
|
||||||
fun longToast(msg: Any?) {
|
fun longToast(msg: Any?) {
|
||||||
appCtx.longToastOnUi(msg.toString())
|
appCtx.longToastOnUi("${getSource()?.getTag()}: ${msg.toString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.annotation.SuppressLint
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
@@ -13,8 +15,7 @@ import io.legado.app.help.glide.ImageLoader
|
|||||||
import io.legado.app.help.glide.OkHttpModelLoader
|
import io.legado.app.help.glide.OkHttpModelLoader
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
import io.legado.app.ui.widget.dialog.PhotoDialog
|
import io.legado.app.ui.widget.dialog.PhotoDialog
|
||||||
import io.legado.app.utils.setLayout
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.utils.showDialogFragment
|
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +24,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
* val key = "${sourceOrigin ?: ""}_verificationResult"
|
* val key = "${sourceOrigin ?: ""}_verificationResult"
|
||||||
* CacheManager.get(key)
|
* CacheManager.get(key)
|
||||||
*/
|
*/
|
||||||
class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification_code_view) {
|
class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification_code_view), Toolbar.OnMenuItemClickListener {
|
||||||
|
|
||||||
constructor(imageUrl: String, sourceOrigin: String? = null) : this() {
|
constructor(imageUrl: String, sourceOrigin: String? = null) : this() {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
@@ -41,6 +42,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
|
|||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
initMenu()
|
||||||
binding.run {
|
binding.run {
|
||||||
toolBar.setBackgroundColor(primaryColor)
|
toolBar.setBackgroundColor(primaryColor)
|
||||||
val sourceOrigin = arguments?.getString("sourceOrigin")
|
val sourceOrigin = arguments?.getString("sourceOrigin")
|
||||||
@@ -61,17 +63,29 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
|
|||||||
showDialogFragment(PhotoDialog(imageUrl, sourceOrigin))
|
showDialogFragment(PhotoDialog(imageUrl, sourceOrigin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tvOk.setOnClickListener {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initMenu() {
|
||||||
|
binding.toolBar.setOnMenuItemClickListener(this)
|
||||||
|
binding.toolBar.inflateMenu(R.menu.verification_code)
|
||||||
|
binding.toolBar.menu.applyTint(requireContext())
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.menu_ok -> {
|
||||||
|
val sourceOrigin = arguments?.getString("sourceOrigin")
|
||||||
|
val key = "${sourceOrigin}_verificationResult"
|
||||||
val verificationCode = binding.verificationCode.text.toString()
|
val verificationCode = binding.verificationCode.text.toString()
|
||||||
verificationCode.let {
|
verificationCode.let {
|
||||||
CacheManager.putMemory(key, it)
|
CacheManager.putMemory(key, it)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tvCancel.setOnClickListener {
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
@@ -68,8 +68,9 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
|||||||
R.id.menu_copy_url -> sendToClip(viewModel.baseUrl)
|
R.id.menu_copy_url -> sendToClip(viewModel.baseUrl)
|
||||||
R.id.menu_ok -> {
|
R.id.menu_ok -> {
|
||||||
if (viewModel.sourceVerificationEnable) {
|
if (viewModel.sourceVerificationEnable) {
|
||||||
binding.titleBar.snackbar(R.string.ok)
|
viewModel.saveVerificationResult {
|
||||||
finish()
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,9 +183,6 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
runBlocking {
|
|
||||||
viewModel.saveVerificationResult()
|
|
||||||
}
|
|
||||||
binding.webView.destroy()
|
binding.webView.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,11 +83,15 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveVerificationResult() {
|
fun saveVerificationResult(success: () -> Unit) {
|
||||||
if (sourceVerificationEnable) {
|
execute {
|
||||||
val key = "${sourceOrigin}_verificationResult"
|
if (sourceVerificationEnable) {
|
||||||
html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body
|
val key = "${sourceOrigin}_verificationResult"
|
||||||
CacheManager.putMemory(key, html ?: "")
|
html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponseAwait(useWebView = false).body
|
||||||
|
CacheManager.putMemory(key, html ?: "")
|
||||||
|
}
|
||||||
|
}.onSuccess {
|
||||||
|
success.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
android:id="@+id/tool_bar"
|
android:id="@+id/tool_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="5dp"
|
||||||
android:theme="?attr/actionBarStyle"
|
android:theme="?attr/actionBarStyle"
|
||||||
|
android:background="@color/background_menu"
|
||||||
app:title="@string/input_verification_code"
|
app:title="@string/input_verification_code"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||||
app:titleTextAppearance="@style/ToolbarTitle" />
|
app:titleTextAppearance="@style/ToolbarTitle" />
|
||||||
@@ -20,18 +22,15 @@
|
|||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:paddingLeft="12dp"
|
android:padding="3dp"
|
||||||
android:paddingRight="12dp"
|
|
||||||
android:paddingTop="3dp"
|
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
tools:ignore="UnusedAttribute" />
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
<io.legado.app.ui.widget.text.TextInputLayout
|
<io.legado.app.ui.widget.text.TextInputLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="12dp"
|
android:padding="3dp"
|
||||||
android:paddingRight="12dp"
|
android:layout_marginTop="8dp">
|
||||||
android:paddingTop="3dp">
|
|
||||||
|
|
||||||
<io.legado.app.lib.theme.view.ThemeEditText
|
<io.legado.app.lib.theme.view.ThemeEditText
|
||||||
android:id="@+id/verification_code"
|
android:id="@+id/verification_code"
|
||||||
@@ -42,29 +41,4 @@
|
|||||||
|
|
||||||
</io.legado.app.ui.widget.text.TextInputLayout>
|
</io.legado.app.ui.widget.text.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.flexbox.FlexboxLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="12dp"
|
|
||||||
android:paddingRight="12dp"
|
|
||||||
app:justifyContent="flex_end">
|
|
||||||
|
|
||||||
<io.legado.app.ui.widget.text.AccentTextView
|
|
||||||
android:id="@+id/tv_cancel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:text="@string/cancel"
|
|
||||||
tools:ignore="RtlHardcoded" />
|
|
||||||
|
|
||||||
<io.legado.app.ui.widget.text.AccentTextView
|
|
||||||
android:id="@+id/tv_ok"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:text="@string/ok"
|
|
||||||
tools:ignore="RtlHardcoded" />
|
|
||||||
|
|
||||||
</com.google.android.flexbox.FlexboxLayout>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
tools:ignore="AlwaysShowAction">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_ok"
|
||||||
|
android:icon="@drawable/ic_check"
|
||||||
|
android:title="@string/ok"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user