diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index e63dc6528..e2c935f76 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -567,14 +567,14 @@ interface JsExtensions { * 弹窗提示 */ fun toast(msg: Any?) { - appCtx.toastOnUi(msg.toString()) + appCtx.toastOnUi("${getSource()?.getTag()}: ${msg.toString()}") } /** * 弹窗提示 停留时间较长 */ fun longToast(msg: Any?) { - appCtx.longToastOnUi(msg.toString()) + appCtx.longToastOnUi("${getSource()?.getTag()}: ${msg.toString()}") } /** diff --git a/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt index a38f17cfc..85a16fdfd 100644 --- a/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt @@ -4,6 +4,8 @@ import android.annotation.SuppressLint import android.os.Bundle import android.view.View import android.view.ViewGroup +import android.view.MenuItem +import androidx.appcompat.widget.Toolbar import com.bumptech.glide.request.RequestOptions import io.legado.app.R 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.lib.theme.primaryColor import io.legado.app.ui.widget.dialog.PhotoDialog -import io.legado.app.utils.setLayout -import io.legado.app.utils.showDialogFragment +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding /** @@ -23,7 +24,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding * val key = "${sourceOrigin ?: ""}_verificationResult" * 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() { arguments = Bundle().apply { @@ -41,6 +42,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification @SuppressLint("CheckResult") override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + initMenu() binding.run { toolBar.setBackgroundColor(primaryColor) val sourceOrigin = arguments?.getString("sourceOrigin") @@ -61,17 +63,29 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification 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() verificationCode.let { CacheManager.putMemory(key, it) dismiss() } - } - tvCancel.setOnClickListener { - dismiss() - } + } } + return false } override fun onDestroy() { diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index 3973b2023..055d3509c 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -68,8 +68,9 @@ class WebViewActivity : VMBaseActivity() { R.id.menu_copy_url -> sendToClip(viewModel.baseUrl) R.id.menu_ok -> { if (viewModel.sourceVerificationEnable) { - binding.titleBar.snackbar(R.string.ok) - finish() + viewModel.saveVerificationResult { + finish() + } } } } @@ -182,9 +183,6 @@ class WebViewActivity : VMBaseActivity() { override fun onDestroy() { super.onDestroy() - runBlocking { - viewModel.saveVerificationResult() - } binding.webView.destroy() } diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt index f3fb99798..0ad527a09 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt @@ -83,11 +83,15 @@ class WebViewModel(application: Application) : BaseViewModel(application) { } } - fun saveVerificationResult() { - if (sourceVerificationEnable) { - val key = "${sourceOrigin}_verificationResult" - html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body - CacheManager.putMemory(key, html ?: "") + fun saveVerificationResult(success: () -> Unit) { + execute { + if (sourceVerificationEnable) { + val key = "${sourceOrigin}_verificationResult" + html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponseAwait(useWebView = false).body + CacheManager.putMemory(key, html ?: "") + } + }.onSuccess { + success.invoke() } } diff --git a/app/src/main/res/layout/dialog_verification_code_view.xml b/app/src/main/res/layout/dialog_verification_code_view.xml index c218ba54d..707e28051 100644 --- a/app/src/main/res/layout/dialog_verification_code_view.xml +++ b/app/src/main/res/layout/dialog_verification_code_view.xml @@ -10,7 +10,9 @@ android:id="@+id/tool_bar" android:layout_width="match_parent" android:layout_height="wrap_content" + android:elevation="5dp" android:theme="?attr/actionBarStyle" + android:background="@color/background_menu" app:title="@string/input_verification_code" app:popupTheme="@style/AppTheme.PopupOverlay" app:titleTextAppearance="@style/ToolbarTitle" /> @@ -20,18 +22,15 @@ android:scaleType="fitXY" android:layout_width="match_parent" android:layout_height="50dp" - android:paddingLeft="12dp" - android:paddingRight="12dp" - android:paddingTop="3dp" + android:padding="3dp" android:background="?android:attr/selectableItemBackgroundBorderless" tools:ignore="UnusedAttribute" /> + android:padding="3dp" + android:layout_marginTop="8dp"> - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/verification_code.xml b/app/src/main/res/menu/verification_code.xml new file mode 100644 index 000000000..5723c1b13 --- /dev/null +++ b/app/src/main/res/menu/verification_code.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file