Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/src/main/assets/captcha.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: visible;
}

form, #html_element {
width: 100%;
height: 100%;
margin: 0;
}
</style>
#gt
<script type="text/javascript">

Expand Down Expand Up @@ -57,4 +71,4 @@
<script src="#src" async defer>
</script>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package one.mixin.android.ui.landing

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -225,6 +223,13 @@ class MnemonicPhraseFragment : BaseFragment(R.layout.fragment_compose) {
}

private var captchaView: CaptchaView? = null

override fun onDestroyView() {
captchaView?.release()
captchaView = null
super.onDestroyView()
}

private fun initAndLoadCaptcha(sessionKey: EdKeyPair, edKey: EdKeyPair, errorDescription: String) =
lifecycleScope.launch {
errorInfo = null
Expand All @@ -237,6 +242,7 @@ class MnemonicPhraseFragment : BaseFragment(R.layout.fragment_compose) {
override fun onStop() {
if (viewDestroyed()) return
binding.mobileCover.isVisible = false
landingViewModel.updateMnemonicPhraseState(MnemonicPhraseState.Failure)
}

override fun onPostToken(value: Pair<CaptchaView.CaptchaType, String>) {
Expand All @@ -245,7 +251,6 @@ class MnemonicPhraseFragment : BaseFragment(R.layout.fragment_compose) {
}
},
)
(view as ViewGroup).addView(captchaView?.webView, MATCH_PARENT, MATCH_PARENT)
}
captchaView?.loadCaptcha(
if (errorDescription.containsIgnoreCase(gtCAPTCHA)) CaptchaView.CaptchaType.GTCaptcha
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/one/mixin/android/ui/landing/MobileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import android.text.Selection
import android.text.TextWatcher
import android.view.View
import android.view.View.AUTOFILL_HINT_PHONE
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.WindowManager
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
Expand Down Expand Up @@ -261,6 +259,12 @@ class MobileFragment: BaseFragment(R.layout.fragment_mobile) {
setupFocusListeners()
}

override fun onDestroyView() {
captchaView?.release()
captchaView = null
super.onDestroyView()
}

private fun applySafeTopPadding(rootView: View) {
val originalPaddingTop: Int = rootView.paddingTop
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v: View, insets: WindowInsetsCompat ->
Expand Down Expand Up @@ -304,10 +308,6 @@ class MobileFragment: BaseFragment(R.layout.fragment_mobile) {
}

override fun onBackPressed(): Boolean {
if (captchaView?.isVisible() == true) {
hideLoading()
return true
}
if (binding.keyboard.translationY == 0f) {
binding.mobileEt.clearFocus()
binding.countryCodeEt.clearFocus()
Expand Down Expand Up @@ -466,7 +466,6 @@ class MobileFragment: BaseFragment(R.layout.fragment_mobile) {
}
},
)
(view as ViewGroup).addView(captchaView?.webView, MATCH_PARENT, MATCH_PARENT)
}
val captchaType = if (errorDescription.containsIgnoreCase(gtCAPTCHA)) {
CaptchaView.CaptchaType.GTCaptcha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.os.Bundle
import android.os.CountDownTimer
import android.view.View
import android.view.View.GONE
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
Expand Down Expand Up @@ -180,15 +178,13 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
}

override fun onDestroyView() {
super.onDestroyView()
captchaView?.release()
captchaView = null
mCountDownTimer?.cancel()
super.onDestroyView()
}

override fun onBackPressed(): Boolean {
if (captchaView?.isVisible() == true) {
hideLoading()
return true
}
return false
}

Expand Down Expand Up @@ -395,7 +391,7 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {

override fun hideLoading() {
super.hideLoading()
captchaView?.webView?.visibility = GONE
captchaView?.hide()
}

private fun sendVerification(captchaResponse: Pair<CaptchaView.CaptchaType, String>? = null) {
Expand Down Expand Up @@ -443,7 +439,7 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
{ t: Throwable ->
handleError(t)
binding.verificationNextFab.visibility = GONE
captchaView?.webView?.visibility = GONE
captchaView?.hide()
},
)
}
Expand All @@ -464,7 +460,6 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
}
},
)
(view as ViewGroup).addView(captchaView?.webView, MATCH_PARENT, MATCH_PARENT)
}
val captchaType = if (errorDescription.containsIgnoreCase(gtCAPTCHA)) {
CaptchaView.CaptchaType.GTCaptcha
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package one.mixin.android.ui.setting

import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.net.toUri
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
Expand All @@ -15,6 +17,7 @@ import kotlinx.coroutines.withContext
import one.mixin.android.Constants
import one.mixin.android.R
import one.mixin.android.databinding.FragmentLogDebugBinding
import one.mixin.android.databinding.ViewCaptchaPreviewBottomBinding
import one.mixin.android.db.DatabaseMonitor
import one.mixin.android.db.property.PropertyHelper.findValueByKey
import one.mixin.android.db.property.PropertyHelper.updateKeyValue
Expand All @@ -39,6 +42,8 @@ import one.mixin.android.ui.wallet.PREF_WALLET_HOME_ADD_WALLET_BANNER_CLOSED
import one.mixin.android.ui.wallet.PREF_WALLET_HOME_REFERRAL_CLOSED
import one.mixin.android.util.debug.FileLogTree
import one.mixin.android.util.viewBinding
import one.mixin.android.widget.BottomSheet
import one.mixin.android.widget.CaptchaView
import javax.inject.Inject

private const val PREF_WALLET_HOME_CASHBACK_BANNER_CLOSED = "pref_wallet_home_cashback_banner_closed"
Expand All @@ -53,6 +58,7 @@ class LogAndDebugFragment : BaseFragment(R.layout.fragment_log_debug) {

private val binding by viewBinding(FragmentLogDebugBinding::bind)
private val viewModel by viewModels<LogAndDebugViewModel>()
private var captchaView: CaptchaView? = null

@Inject
lateinit var jobManager: MixinJobManager
Expand Down Expand Up @@ -132,6 +138,10 @@ class LogAndDebugFragment : BaseFragment(R.layout.fragment_log_debug) {
toast(R.string.New_Update_Reminder_Will_Show_Once)
}

previewCaptcha.setOnClickListener {
showCaptchaPreviewBottom()
}

resetTpslGuide.setOnClickListener {
resetDebugSharedPreferences()
toast(R.string.Reset_TpSl_Guide)
Expand Down Expand Up @@ -177,6 +187,59 @@ class LogAndDebugFragment : BaseFragment(R.layout.fragment_log_debug) {
}
}

override fun onDestroyView() {
captchaView?.release()
captchaView = null
super.onDestroyView()
}

@SuppressLint("InflateParams")
private fun showCaptchaPreviewBottom() {
val builder = BottomSheet.Builder(requireActivity())
val bottomBinding = ViewCaptchaPreviewBottomBinding.bind(
View.inflate(
ContextThemeWrapper(requireActivity(), R.style.Custom),
R.layout.view_captcha_preview_bottom,
null,
),
)
builder.setCustomView(bottomBinding.root)
val bottomSheet = builder.create()
bottomBinding.apply {
gCaptcha.setOnClickListener {
bottomSheet.dismiss()
previewCaptcha(CaptchaView.CaptchaType.GCaptcha)
}
hCaptcha.setOnClickListener {
bottomSheet.dismiss()
previewCaptcha(CaptchaView.CaptchaType.HCaptcha)
}
gtCaptcha.setOnClickListener {
bottomSheet.dismiss()
previewCaptcha(CaptchaView.CaptchaType.GTCaptcha)
}
}
bottomSheet.show()
}

private fun previewCaptcha(captchaType: CaptchaView.CaptchaType) {
val view =
captchaView ?: CaptchaView(
requireContext(),
object : CaptchaView.Callback {
override fun onStop() {
}

override fun onPostToken(value: Pair<CaptchaView.CaptchaType, String>) {
toast(getString(R.string.Captcha_Preview_Token_Received, value.first.name))
}
Comment on lines +233 to +235
},
).also {
captchaView = it
}
view.loadCaptchaWithoutFallback(captchaType)
}

private fun resetDebugSharedPreferences() {
val editor = defaultSharedPreferences.edit()
debugSharedPreferenceKeys().forEach { key ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package one.mixin.android.ui.setting.delete

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -77,11 +76,13 @@ class DeleteAccountFragment : BaseFragment(R.layout.fragment_delete_account) {
}
}

override fun onDestroyView() {
captchaView?.release()
captchaView = null
super.onDestroyView()
}

override fun onBackPressed(): Boolean {
if (captchaView?.isVisible() == true) {
captchaView?.hide()
return true
}
return false
}

Expand Down Expand Up @@ -253,11 +254,6 @@ class DeleteAccountFragment : BaseFragment(R.layout.fragment_delete_account) {
}
},
)
(view as ViewGroup).addView(
captchaView?.webView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
}
captchaView?.loadCaptcha(
if (errorDescription.containsIgnoreCase(gtCAPTCHA)) CaptchaView.CaptchaType.GTCaptcha
Expand Down
Loading