diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index 36acfcdda5..2aa61cda52 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -5,6 +5,8 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.os.IBinder +import android.text.Editable +import android.text.TextWatcher import android.text.format.DateFormat import androidx.preference.EditTextPreference import androidx.preference.ListPreference @@ -127,6 +129,27 @@ import kotlin.math.abs super.preprocessPreferences(preferenceFragment) val serialSetting = preferenceFragment.findPreference(rh.gs(R.string.key_sn_input)) serialSetting?.isEnabled = !isInitialized() + serialSetting?.setOnBindEditTextListener { editText -> + editText.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(newValue: Editable?) { + val newSN = newValue.toString().toLongOrNull(radix = 16) + val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN ?: 0) + if (newDeviceType == MedtrumSnUtil.INVALID) { + editText.error = rh.gs(R.string.sn_input_invalid) + } else { + editText.error = null + } + } + + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { + // Nothing to do here + } + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + // Nothing to do here + } + }) + } serialSetting?.setOnPreferenceChangeListener { _, newValue -> if (newValue is String) { val newSN = newValue.toLongOrNull(radix = 16) diff --git a/pump/medtrum/src/main/res/values/strings.xml b/pump/medtrum/src/main/res/values/strings.xml index 87b854d525..68e2e24eaf 100644 --- a/pump/medtrum/src/main/res/values/strings.xml +++ b/pump/medtrum/src/main/res/values/strings.xml @@ -130,7 +130,7 @@ Serial Number Enter the serial number of your pump base. - Invalid serial number! Check serial number and try again. + Invalid serial number! Pump untested: %1$d! Please contact us at discord or github for support Alarm Settings Select your preferred pump alarm settings.