SmsCommunicatorOtpActivity -> jetpack

This commit is contained in:
Milos Kozak 2021-02-02 20:32:07 +01:00
parent e7d58a8f84
commit 2078962057
2 changed files with 20 additions and 16 deletions

View file

@ -14,6 +14,7 @@ import com.google.common.primitives.Ints.min
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.databinding.ActivitySmscommunicatorOtpBinding
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword
@ -21,7 +22,6 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePas
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import kotlinx.android.synthetic.main.activity_smscommunicator_otp.*
import net.glxn.qrgen.android.QRCode
import javax.inject.Inject
@ -32,23 +32,27 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
@Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
@Inject lateinit var otp: OneTimePassword
private lateinit var binding: ActivitySmscommunicatorOtpBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
setContentView(R.layout.activity_smscommunicator_otp)
smscommunicator_otp_verify_edit.addTextChangedListener(object : TextWatcher {
binding = ActivitySmscommunicatorOtpBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.otpVerifyEdit.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
val checkResult = otp.checkOTP(s.toString())
smscommunicator_otp_verify_label.text = when (checkResult) {
binding.otpVerifyLabel.text = when (checkResult) {
OneTimePasswordValidationResult.OK -> "OK"
OneTimePasswordValidationResult.ERROR_WRONG_LENGTH -> "INVALID SIZE!"
OneTimePasswordValidationResult.ERROR_WRONG_PIN -> "WRONG PIN"
OneTimePasswordValidationResult.ERROR_WRONG_OTP -> "WRONG OTP"
}
smscommunicator_otp_verify_label.setTextColor(when (checkResult) {
binding.otpVerifyLabel.setTextColor(when (checkResult) {
OneTimePasswordValidationResult.OK -> Color.GREEN
OneTimePasswordValidationResult.ERROR_WRONG_LENGTH -> Color.YELLOW
OneTimePasswordValidationResult.ERROR_WRONG_PIN -> Color.RED
@ -61,7 +65,7 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
})
actions_smscommunicator_otp_reset.setOnClickListener {
binding.otpReset.setOnClickListener {
OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.smscommunicator_otp_reset_title),
resourceHelper.gs(R.string.smscommunicator_otp_reset_prompt),
@ -72,7 +76,7 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
})
}
smscommunicator_otp_provisioning.setOnLongClickListener {
binding.otpProvisioning.setOnLongClickListener {
OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.smscommunicator_otp_export_title),
resourceHelper.gs(R.string.smscommunicator_otp_export_prompt),
@ -104,12 +108,12 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
if (provURI != null) {
val myBitmap = QRCode.from(provURI).withErrorCorrection(ErrorCorrectionLevel.H).withSize(dim, dim).bitmap()
smscommunicator_otp_provisioning.setImageBitmap(myBitmap)
smscommunicator_otp_provisioning.visibility = View.VISIBLE
binding.otpProvisioning.setImageBitmap(myBitmap)
binding.otpProvisioning.visibility = View.VISIBLE
} else {
smscommunicator_otp_provisioning.visibility = View.GONE
binding.otpProvisioning.visibility = View.GONE
}
smscommunicator_otp_verify_edit.text = smscommunicator_otp_verify_edit.text
binding.otpVerifyEdit.text = binding.otpVerifyEdit.text
}
}

View file

@ -9,7 +9,7 @@
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/smscommunicator_otp_layout"
android:id="@+id/otp_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -32,7 +32,7 @@
android:text="@string/smscommunicator_otp_step2_provisioning_header" />
<ImageView
android:id="@+id/smscommunicator_otp_provisioning"
android:id="@+id/otp_provisioning"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
@ -68,7 +68,7 @@
android:text="@string/smscommunicator_code_verify_label" />
<EditText
android:id="@+id/smscommunicator_otp_verify_edit"
android:id="@+id/otp_verify_edit"
android:layout_width="140sp"
android:layout_height="wrap_content"
android:hint="@string/smscommunicator_code_verify_hint"
@ -79,7 +79,7 @@
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/smscommunicator_otp_verify_label"
android:id="@+id/otp_verify_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="15dp"
@ -96,7 +96,7 @@
android:text="@string/smscommunicator_otp_reset_warning" />
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/actions_smscommunicator_otp_reset"
android:id="@+id/otp_reset"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="match_parent"