Updated on 2026-08-14
This commit is contained in:
parent
9c6d9bc6f9
commit
8b5ed4f3e9
2 changed files with 61 additions and 60 deletions
|
|
@ -38,6 +38,7 @@ import com.tangem.tangemcard.android.reader.NfcManager
|
|||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.RootFoundDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialogNew
|
||||
import com.tangem.tangemcard.android.reader.NfcReader
|
||||
import com.tangem.tangemcard.data.TangemCard
|
||||
import com.tangem.tangemcard.data.loadFromBundle
|
||||
|
|
@ -84,6 +85,9 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// val waitSecurityDelayDialogNew = WaitSecurityDelayDialogNew()
|
||||
// waitSecurityDelayDialogNew.show(supportFragmentManager, WaitSecurityDelayDialogNew.TAG)
|
||||
|
||||
App.getNavigatorComponent().inject(this)
|
||||
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package com.tangem.presentation.dialog
|
||||
|
||||
import android.app.Activity
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatDialogFragment
|
||||
import android.widget.ProgressBar
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.dialog_wait_pin2.*
|
||||
import java.util.*
|
||||
|
|
@ -18,27 +19,33 @@ class WaitSecurityDelayDialogNew : AppCompatDialogFragment() {
|
|||
private const val DELAY_BEFORE_SHOW_DIALOG = 5000
|
||||
}
|
||||
|
||||
private lateinit var pb: ProgressBar
|
||||
|
||||
private var msTimeout = 60000
|
||||
private var msProgress = 0
|
||||
private var timer: Timer? = null
|
||||
private var timerToShowDelayDialog: Timer? = null
|
||||
private var instance: WaitSecurityDelayDialogNew? = null
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val inflater = activity!!.layoutInflater
|
||||
val v = inflater.inflate(R.layout.dialog_wait_pin2, null)
|
||||
|
||||
progressBar.max = msTimeout
|
||||
progressBar.progress = msProgress
|
||||
isCancelable = false
|
||||
|
||||
pb = v.findViewById(R.id.progressBar)
|
||||
|
||||
|
||||
pb.max = msTimeout
|
||||
pb.progress = msProgress
|
||||
|
||||
timer = Timer()
|
||||
timer!!.scheduleAtFixedRate(object : TimerTask() {
|
||||
override fun run() {
|
||||
progressBar.post {
|
||||
val progress = this@WaitSecurityDelayDialogNew.progressBar.progress
|
||||
if (progress < this@WaitSecurityDelayDialogNew.progressBar.max) {
|
||||
this@WaitSecurityDelayDialogNew.progressBar.progress = progress + 1000
|
||||
}
|
||||
pb.post {
|
||||
val progress = pb.progress
|
||||
if (progress < pb.max)
|
||||
pb.progress = progress + 1000
|
||||
}
|
||||
}
|
||||
}, 1000, 1000)
|
||||
|
|
@ -51,59 +58,48 @@ class WaitSecurityDelayDialogNew : AppCompatDialogFragment() {
|
|||
.create()
|
||||
}
|
||||
|
||||
fun onReadBeforeRequest(activity: Activity, timeout: Int) {
|
||||
activity.runOnUiThread(Runnable {
|
||||
if (timerToShowDelayDialog != null || timeout < DELAY_BEFORE_SHOW_DIALOG + MIN_REMAINING_DELAY_TO_SHOW_DIALOG)
|
||||
return@Runnable
|
||||
fun onReadBeforeRequest(timeout: Int) {
|
||||
if (timerToShowDelayDialog != null || timeout < DELAY_BEFORE_SHOW_DIALOG + MIN_REMAINING_DELAY_TO_SHOW_DIALOG)
|
||||
return
|
||||
|
||||
timerToShowDelayDialog = Timer()
|
||||
timerToShowDelayDialog!!.schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
setup(timeout, DELAY_BEFORE_SHOW_DIALOG)
|
||||
isCancelable = false
|
||||
show(activity?.supportFragmentManager, TAG)
|
||||
}
|
||||
}, DELAY_BEFORE_SHOW_DIALOG.toLong())
|
||||
|
||||
timerToShowDelayDialog = Timer()
|
||||
timerToShowDelayDialog!!.schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
if (instance != null) return
|
||||
instance = WaitSecurityDelayDialogNew()
|
||||
instance!!.setup(timeout, DELAY_BEFORE_SHOW_DIALOG)
|
||||
instance!!.isCancelable = false
|
||||
// instance.show(activity.fragmentManager, TAG)
|
||||
}
|
||||
}, DELAY_BEFORE_SHOW_DIALOG.toLong())
|
||||
})
|
||||
}
|
||||
|
||||
fun onReadAfterRequest(activity: Activity) {
|
||||
activity.runOnUiThread(Runnable {
|
||||
if (timerToShowDelayDialog == null) return@Runnable
|
||||
fun onReadAfterRequest() {
|
||||
if (timerToShowDelayDialog == null)
|
||||
return
|
||||
|
||||
timerToShowDelayDialog!!.cancel()
|
||||
timerToShowDelayDialog = null
|
||||
}
|
||||
|
||||
fun onReadWait(msec: Int) {
|
||||
if (timerToShowDelayDialog != null) {
|
||||
timerToShowDelayDialog!!.cancel()
|
||||
timerToShowDelayDialog = null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun onReadWait(activity: Activity, msec: Int) {
|
||||
activity.runOnUiThread(Runnable {
|
||||
if (timerToShowDelayDialog != null) {
|
||||
timerToShowDelayDialog!!.cancel()
|
||||
timerToShowDelayDialog = null
|
||||
}
|
||||
if (msec == 0) {
|
||||
dismiss()
|
||||
return
|
||||
}
|
||||
|
||||
if (msec == 0) {
|
||||
if (instance != null) {
|
||||
instance!!.dismiss()
|
||||
instance = null
|
||||
}
|
||||
return@Runnable
|
||||
}
|
||||
if (msec > MIN_REMAINING_DELAY_TO_SHOW_DIALOG) {
|
||||
// 1000ms - card delay notification interval
|
||||
setup(msec + 1000, 1000)
|
||||
isCancelable = false
|
||||
show(activity?.supportFragmentManager, TAG)
|
||||
|
||||
if (instance == null) {
|
||||
if (msec > MIN_REMAINING_DELAY_TO_SHOW_DIALOG) {
|
||||
instance = WaitSecurityDelayDialogNew()
|
||||
// 1000ms - card delay notification interval
|
||||
instance!!.setup(msec + 1000, 1000)
|
||||
instance!!.isCancelable = false
|
||||
// instance.show(activity.fragmentManager, TAG)
|
||||
}
|
||||
} else {
|
||||
instance!!.setRemainingTimeout(msec)
|
||||
}
|
||||
})
|
||||
} else
|
||||
setRemainingTimeout(msec)
|
||||
}
|
||||
|
||||
private fun setup(msTimeout: Int, msProgress: Int) {
|
||||
|
|
@ -112,19 +108,20 @@ class WaitSecurityDelayDialogNew : AppCompatDialogFragment() {
|
|||
}
|
||||
|
||||
private fun setRemainingTimeout(msec: Int) {
|
||||
progressBar.post {
|
||||
val progress = this@WaitSecurityDelayDialogNew.progressBar.progress
|
||||
pb.post {
|
||||
val progress = pb.progress
|
||||
if (timer != null) {
|
||||
|
||||
// we get delay latency from card for first time - don't change progress by timer, only by card answer
|
||||
progressBar.max = progress + msec
|
||||
pb.max = progress + msec
|
||||
timer!!.cancel()
|
||||
timer = null
|
||||
} else {
|
||||
val newProgress = progressBar.max - msec
|
||||
if (newProgress > progress)
|
||||
val newProgress = pb.max - msec
|
||||
if (pb.max > progress)
|
||||
progressBar.progress = newProgress
|
||||
else
|
||||
progressBar.max = progress + msec
|
||||
pb.max = progress + msec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue