diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d33213e6e..da98accad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -359,6 +359,13 @@ + + + { + putExtra("imageUrl", imageUrl) + putExtra("sourceOrigin", getSource()?.getKey()) + } + var waitUserInput: Boolean = false + while(CacheManager.get(key) == null) { + if (!waitUserInput) { + log("等待输入验证码...") + waitUserInput = true + } + } + CacheManager.get(key)!!.let { + if (it.isBlank()) { + throw NoStackTraceException("未输入验证码或者验证码为空") + } else { + it + } + } + } + } + /** * 可从网络,本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本 */ diff --git a/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt b/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt new file mode 100644 index 000000000..13ade4694 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt @@ -0,0 +1,26 @@ +package io.legado.app.ui.association + +import android.os.Bundle +import io.legado.app.base.BaseActivity +import io.legado.app.databinding.ActivityTranslucenceBinding +import io.legado.app.utils.showDialogFragment +import io.legado.app.utils.viewbindingdelegate.viewBinding + +/** + * 验证码 + */ +class VerificationCodeActivity : + BaseActivity() { + + override val binding by viewBinding(ActivityTranslucenceBinding::inflate) + + override fun onActivityCreated(savedInstanceState: Bundle?) { + intent.getStringExtra("imageUrl")?.let { + val sourceOrigin = intent.getStringExtra("sourceOrigin") + showDialogFragment( + VerificationCodeDialog(it, sourceOrigin) + ) + } ?: finish() + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..568800b29 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt @@ -0,0 +1,83 @@ +package io.legado.app.ui.association + +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.net.Uri +import com.bumptech.glide.request.RequestOptions +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment +import io.legado.app.databinding.DialogVerificationCodeViewBinding +import io.legado.app.help.CacheManager +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.viewbindingdelegate.viewBinding + +//图片验证码输入对话框 +class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification_code_view) { + + constructor(imageUrl: String, sourceOrigin: String? = null) : this() { + arguments = Bundle().apply { + putString("sourceOrigin", sourceOrigin) + putString("imageUrl", imageUrl) + } + } + + val binding by viewBinding(DialogVerificationCodeViewBinding::bind) + + override fun onStart() { + super.onStart() + setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.run { + toolBar.setBackgroundColor(primaryColor) + val sourceOrigin = arguments?.getString("sourceOrigin") + val key = "${sourceOrigin ?: ""}_verificationCode" + arguments?.getString("imageUrl")?.let { imageUrl -> + ImageLoader.load(requireContext(), imageUrl).apply { + sourceOrigin?.let { + apply( + RequestOptions().set( + OkHttpModelLoader.sourceOriginOption, + it + ) + ) + } + }.error(R.drawable.image_loading_error) + .into(ivImage) + ivImage.setOnClickListener { + showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) + } + ivImage.setOnLongClickListener { + showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) + true + } + } + tvOk.setOnClickListener { + val verificationCode = binding.verificationCode.text.toString() + verificationCode?.let { + CacheManager.put(key, it) + dismiss() + } + } + tvCancel.setOnClickListener { + dismiss() + } + } + } + + override fun onDestroy() { + val sourceOrigin = arguments?.getString("sourceOrigin") + val key = "${sourceOrigin ?: ""}_verificationCode" + CacheManager.get(key) ?: CacheManager.put(key, "") + super.onDestroy() + activity?.finish() + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_verification_code_view.xml b/app/src/main/res/layout/dialog_verification_code_view.xml new file mode 100644 index 000000000..c218ba54d --- /dev/null +++ b/app/src/main/res/layout/dialog_verification_code_view.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 4806bfc88..f62a1d248 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -969,5 +969,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 3385b091b..11a2729de 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 863b931ad..f0e4b8cf3 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 416e92a93..7b938e9f3 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -969,5 +969,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 874d66764..6ba87de41 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -971,5 +971,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6b9b415d0..7b0f3ef18 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -971,5 +971,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bc5f63327..05df4e53b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码