|
|
@ -5,6 +5,8 @@ import android.view.KeyEvent
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import com.common.commonlib.db.DBUtils
|
|
|
|
import com.common.commonlib.db.DBUtils
|
|
|
|
|
|
|
|
import com.common.commonlib.utils.getGasNickName
|
|
|
|
|
|
|
|
import com.common.commonlib.utils.saveGasNickName
|
|
|
|
import com.yinuo.safetywatcher.R
|
|
|
|
import com.yinuo.safetywatcher.R
|
|
|
|
import com.yinuo.safetywatcher.databinding.ActivitySensorSettingBinding
|
|
|
|
import com.yinuo.safetywatcher.databinding.ActivitySensorSettingBinding
|
|
|
|
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
|
|
|
|
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
|
|
|
@ -49,16 +51,15 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
mBinding.rgUnit.visibility = View.GONE
|
|
|
|
mBinding.rgUnit.visibility = View.GONE
|
|
|
|
mBinding.rbLel.visibility = View.GONE
|
|
|
|
mBinding.rbLel.visibility = View.GONE
|
|
|
|
mBinding.rbVol.visibility = View.VISIBLE
|
|
|
|
mBinding.rbVol.visibility = View.VISIBLE
|
|
|
|
} else if (gasName == CH4_H2){
|
|
|
|
} else if (gasName == CH4_H2) {
|
|
|
|
mBinding.rgUnit.visibility = View.GONE
|
|
|
|
mBinding.rgUnit.visibility = View.GONE
|
|
|
|
mBinding.rbVol.visibility = View.GONE
|
|
|
|
mBinding.rbVol.visibility = View.GONE
|
|
|
|
mBinding.rbLel.visibility = View.VISIBLE
|
|
|
|
mBinding.rbLel.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
mBinding.rgUnit.visibility = View.VISIBLE
|
|
|
|
mBinding.rgUnit.visibility = View.VISIBLE
|
|
|
|
mBinding.rbVol.visibility = View.GONE
|
|
|
|
mBinding.rbVol.visibility = View.GONE
|
|
|
|
mBinding.rbLel.visibility = View.GONE
|
|
|
|
mBinding.rbLel.visibility = View.GONE
|
|
|
|
if (gasName == VOCS){
|
|
|
|
if (gasName == VOCS) {
|
|
|
|
mBinding.rbMgm3.visibility = View.GONE
|
|
|
|
mBinding.rbMgm3.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (localGasUnit == UNIT_PPM) {
|
|
|
|
if (localGasUnit == UNIT_PPM) {
|
|
|
@ -72,6 +73,7 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
lifecycleScope.launch(Dispatchers.IO) {
|
|
|
|
lifecycleScope.launch(Dispatchers.IO) {
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
val typeDao = DBUtils.gasTypeDao()
|
|
|
|
val gasType = typeDao.getByName(gasName)
|
|
|
|
val gasType = typeDao.getByName(gasName)
|
|
|
|
|
|
|
|
val gasNickName = getGasNickName(gasName)
|
|
|
|
launch(Dispatchers.Main) {
|
|
|
|
launch(Dispatchers.Main) {
|
|
|
|
if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
|
|
|
|
if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
|
|
|
|
mBinding.etName.setText(gasType.nickName)
|
|
|
|
mBinding.etName.setText(gasType.nickName)
|
|
|
@ -80,6 +82,7 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val gasRange = getGasRange(gasName)
|
|
|
|
val gasRange = getGasRange(gasName)
|
|
|
|
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")
|
|
|
|
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")
|
|
|
|
|
|
|
|
mBinding.etGasName.setText(gasNickName ?: "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -111,7 +114,7 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
|
|
|
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
|
|
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
|
|
mBinding.tvWarnSetting.requestFocus()
|
|
|
|
mBinding.etGasName.requestFocus()
|
|
|
|
return@setOnKeyListener true
|
|
|
|
return@setOnKeyListener true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
|
@ -123,6 +126,26 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
return@setOnKeyListener false
|
|
|
|
return@setOnKeyListener false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mBinding.etGasName.setOnKeyListener { v, keyCode, event ->
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
|
|
|
|
|
|
|
|
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
|
|
|
|
|
|
mBinding.etName.requestFocus()
|
|
|
|
|
|
|
|
return@setOnKeyListener true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
|
|
|
|
|
|
|
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
|
|
|
|
|
|
mBinding.tvWarnSetting.requestFocus()
|
|
|
|
|
|
|
|
return@setOnKeyListener true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
|
|
|
|
|
|
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
|
|
|
|
|
|
mBinding.etGasName.showIme()
|
|
|
|
|
|
|
|
return@setOnKeyListener true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return@setOnKeyListener false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mBinding.etName.setOnFocusChangeListener { _, hasFocus ->
|
|
|
|
mBinding.etName.setOnFocusChangeListener { _, hasFocus ->
|
|
|
|
if (!hasFocus) {
|
|
|
|
if (!hasFocus) {
|
|
|
|
mBinding.etName.hideIme()
|
|
|
|
mBinding.etName.hideIme()
|
|
|
@ -163,6 +186,10 @@ class SensorSettingActivity : NoOptionsActivity() {
|
|
|
|
typeDao.insert(gasType)
|
|
|
|
typeDao.insert(gasType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 气体名称
|
|
|
|
|
|
|
|
val gasNickName = mBinding.etGasName.text.toString()
|
|
|
|
|
|
|
|
saveGasNickName(gasName, gasNickName)
|
|
|
|
|
|
|
|
|
|
|
|
val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId
|
|
|
|
val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId
|
|
|
|
var selectedUnit = UNIT_PPM
|
|
|
|
var selectedUnit = UNIT_PPM
|
|
|
|
if (checkedRadioButtonId == R.id.rb_mgm3) {
|
|
|
|
if (checkedRadioButtonId == R.id.rb_mgm3) {
|
|
|
|