Skip to content

Commit

Permalink
Merge pull request #78 from simple-login/fix/totp-from-clipboard-with…
Browse files Browse the repository at this point in the history
…-existing-content

Fix TOTP from clipboard with existing content
  • Loading branch information
ntnhon committed Jul 4, 2022
2 parents 0684545 + a6a96a2 commit e7352a9
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.Window
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand All @@ -29,6 +31,8 @@ class VerificationActivity : BaseAppCompatActivity(), Window.Callback {
const val ACCOUNT = "account"
}

private val DELAY_AFTER_RESET_MS = 100L

private lateinit var binding: ActivityVerificationBinding
private lateinit var verificationMode: VerificationMode
private val dash = "-"
Expand Down Expand Up @@ -122,14 +126,17 @@ class VerificationActivity : BaseAppCompatActivity(), Window.Callback {
}

private fun pasteAndVerify(code: String) {
code.asIterable().forEach { char ->
addNumber(char.toString())
}
reset()
Handler(Looper.getMainLooper()).postDelayed({
code.asIterable().forEach { char ->
addNumber(char.toString(), false)
}

verify(code)
verify(code)
}, DELAY_AFTER_RESET_MS)
}

private fun addNumber(number: String) {
private fun addNumber(number: String, launchVerify: Boolean = true) {
when {
binding.firstNumberTextView.text == dash -> {
binding.firstNumberTextView.text = number
Expand All @@ -149,7 +156,9 @@ class VerificationActivity : BaseAppCompatActivity(), Window.Callback {
code += binding.fifthNumberTextView.text
code += binding.sixthNumberTextView.text

verify(code)
if (launchVerify) {
verify(code)
}
}
}
}
Expand Down

0 comments on commit e7352a9

Please sign in to comment.