Done with error handling
This commit is contained in:
@@ -32,6 +32,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private var isOnline = false
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var resultData: String = ""
|
||||
private var isUsingExistingBuffer = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
@@ -107,9 +108,16 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun isBufferValueAvailable(): Boolean {
|
||||
val buffer1 = sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDouble() ?: 0.0
|
||||
val buffer2 = sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDouble() ?: 0.0
|
||||
return buffer1 > 0.0 && buffer2 > 0.0
|
||||
return if (sharedPreferences.getString(
|
||||
Constants.BUFFER_VALUE_1, ""
|
||||
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
|
||||
) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
||||
?.toDouble()!! > 0.0 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
|
||||
?.toDouble()!! > 0.0
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun showBufferAlertDialog() {
|
||||
@@ -132,6 +140,7 @@ class HemoCubeFragment : Fragment() {
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startSampleProcess()
|
||||
isUsingExistingBuffer = true
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -178,7 +187,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||
var validString = ""
|
||||
var validString: String
|
||||
val results: List<String>
|
||||
if (stringData.contains("RESULT")) {
|
||||
validString = isValidResult(stringData)
|
||||
@@ -230,52 +239,46 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun showStartSampleDialog() {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"Start Sample",
|
||||
"Do you want to start sample reading?",
|
||||
getString(R.string.no),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
activity?.runOnUiThread {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"Start Sample",
|
||||
"Do you want to start sample reading?",
|
||||
getString(R.string.no),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startSampleProcess()
|
||||
}
|
||||
})
|
||||
override fun onClickPositiveButton() {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||
val result = validString.split(" ")
|
||||
if (result.size == 8) {
|
||||
val deviceSerialNo = result[2]
|
||||
var led1Buffer = result[3].toDoubleOrNull()
|
||||
var led2Buffer = result[4].toDoubleOrNull()
|
||||
val led1BufferForDevice = result[3].toDoubleOrNull()
|
||||
val led2BufferForDevice = result[4].toDoubleOrNull()
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
val led2Sample = result[6].toDoubleOrNull()
|
||||
val led1Average = log10(led1Buffer?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2Buffer?.div(led2Sample!!) ?: 0.0)
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
|
||||
DataHolder.hemoCubeTestData?.apply {
|
||||
deviceSerialNumber = deviceSerialNo
|
||||
led1Buffer = if (sharedPreferences.getInt(
|
||||
Constants.KIT_COUNT, 0
|
||||
) < 35 && sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
||||
.isNullOrEmpty()
|
||||
) {
|
||||
led1Buffer
|
||||
} else {
|
||||
led1Buffer = if (isUsingExistingBuffer) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
||||
}
|
||||
led2Buffer = if (sharedPreferences.getInt(
|
||||
Constants.KIT_COUNT, 0
|
||||
) < 35 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
|
||||
.isNullOrEmpty()
|
||||
) {
|
||||
led2Buffer
|
||||
|
||||
} else {
|
||||
led1BufferForDevice
|
||||
}
|
||||
led2Buffer = if (isUsingExistingBuffer) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
|
||||
} else {
|
||||
led2BufferForDevice
|
||||
}
|
||||
this.led1Sample = led1Sample
|
||||
this.led2Sample = led2Sample
|
||||
|
||||
@@ -94,7 +94,7 @@ class HemoCubeViewModel @Inject constructor(
|
||||
is Response.Success -> {
|
||||
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
|
||||
with(sharedPreference.edit()) {
|
||||
putInt(Constants.KIT_COUNT, kitCount?.plus(1) ?: 0)
|
||||
putInt(Constants.KIT_COUNT, kitCount.plus(1) ?: 0)
|
||||
apply()
|
||||
}
|
||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
|
||||
Reference in New Issue
Block a user