Merge remote-tracking branch 'origin/master'

pull/1854/head
kunfei 3 years ago
commit 935fa500f0
  1. 4
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  2. 30
      app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt
  3. 8
      app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
  4. 14
      app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt
  5. 36
      app/src/main/res/layout/dialog_verification_code_view.xml
  6. 13
      app/src/main/res/menu/verification_code.xml

@ -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()}")
}
/**

@ -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() {

@ -68,8 +68,9 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
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<ActivityWebViewBinding, WebViewModel>() {
override fun onDestroy() {
super.onDestroy()
runBlocking {
viewModel.saveVerificationResult()
}
binding.webView.destroy()
}

@ -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()
}
}

@ -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" />
<io.legado.app.ui.widget.text.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="3dp">
android:padding="3dp"
android:layout_marginTop="8dp">
<io.legado.app.lib.theme.view.ThemeEditText
android:id="@+id/verification_code"
@ -42,29 +41,4 @@
</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>

@ -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>
Loading…
Cancel
Save