combov2: Validate length of entered pairing PIN
This commit is contained in:
parent
84f4303895
commit
7886dc7e14
2 changed files with 7 additions and 0 deletions
|
@ -17,9 +17,11 @@ import androidx.lifecycle.Lifecycle
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import info.nightscout.comboctl.base.BasicProgressStage
|
||||
import info.nightscout.comboctl.base.PAIRING_PIN_SIZE
|
||||
import info.nightscout.comboctl.base.PairingPIN
|
||||
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
|
||||
import info.nightscout.core.ui.dialogs.OKDialog
|
||||
import info.nightscout.core.ui.toast.ToastUtils
|
||||
import info.nightscout.pump.combov2.ComboV2Plugin
|
||||
import info.nightscout.pump.combov2.R
|
||||
import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding
|
||||
|
@ -334,6 +336,10 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() {
|
|||
// We need to skip whitespaces since the
|
||||
// TextWatcher above inserts some.
|
||||
val pinString = binding.combov2PinEntryEdit.text.replace(whitespaceRemovalRegex, "")
|
||||
if (pinString.length != PAIRING_PIN_SIZE) {
|
||||
ToastUtils.showToastInUiThread(this, rh.gs(R.string.combov2_pairing_invalid_pin_length, PAIRING_PIN_SIZE, pinString.length))
|
||||
return@setOnClickListener
|
||||
}
|
||||
runBlocking {
|
||||
val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray())
|
||||
combov2Plugin.providePairingPIN(PIN)
|
||||
|
|
|
@ -53,6 +53,7 @@ buttons at the same time to cancel pairing)\n
|
|||
<string name="combov2_pairing_combo_scan_timeout_reached">Combo scan timeout reached</string>
|
||||
<string name="combov2_pairing_failed_due_to_error">Pairing failed due to error: %1$s</string>
|
||||
<string name="combov2_pairing_aborted_unknown_reasons">Pairing aborted for unknown reasons</string>
|
||||
<string name="combov2_pairing_invalid_pin_length">"Invalid pairing PIN length: need %1$d digits, got %2$d"</string>
|
||||
<string name="combov2_scanning_for_pump">Scanning for pump</string>
|
||||
<string name="combov2_establishing_bt_connection">Establishing Bluetooth connection (attempt no. %1$d)</string>
|
||||
<string name="combov2_pairing_performing_handshake">Performing handshake with pump</string>
|
||||
|
|
Loading…
Reference in a new issue