Medtrum: Add invalid warning during serial number input
This commit is contained in:
parent
cfc529531f
commit
bedce0c05c
2 changed files with 24 additions and 1 deletions
|
@ -5,6 +5,8 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
|
@ -127,6 +129,27 @@ import kotlin.math.abs
|
||||||
super.preprocessPreferences(preferenceFragment)
|
super.preprocessPreferences(preferenceFragment)
|
||||||
val serialSetting = preferenceFragment.findPreference<EditTextPreference>(rh.gs(R.string.key_sn_input))
|
val serialSetting = preferenceFragment.findPreference<EditTextPreference>(rh.gs(R.string.key_sn_input))
|
||||||
serialSetting?.isEnabled = !isInitialized()
|
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 ->
|
serialSetting?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
if (newValue is String) {
|
if (newValue is String) {
|
||||||
val newSN = newValue.toLongOrNull(radix = 16)
|
val newSN = newValue.toLongOrNull(radix = 16)
|
||||||
|
|
|
@ -130,7 +130,7 @@
|
||||||
<!-- settings-->
|
<!-- settings-->
|
||||||
<string name="sn_input_title">Serial Number</string>
|
<string name="sn_input_title">Serial Number</string>
|
||||||
<string name="sn_input_summary">Enter the serial number of your pump base.</string>
|
<string name="sn_input_summary">Enter the serial number of your pump base.</string>
|
||||||
<string name="sn_input_invalid">Invalid serial number! Check serial number and try again.</string>
|
<string name="sn_input_invalid">Invalid serial number!</string>
|
||||||
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string>
|
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string>
|
||||||
<string name="alarm_setting_title">Alarm Settings</string>
|
<string name="alarm_setting_title">Alarm Settings</string>
|
||||||
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
|
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
|
||||||
|
|
Loading…
Reference in a new issue