support multiple readings automatically
This commit is contained in:
@@ -254,6 +254,7 @@ object Constants {
|
||||
const val INCUBATION_TIME_MIN = 0
|
||||
const val INCUBATION_TIME_MAX = 1400
|
||||
const val BATTERY_LEVEL_MIN = 0
|
||||
const val READINGS_PER_SAMPLE = 3
|
||||
|
||||
val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>(
|
||||
"HCV-000-3001" to listOf(
|
||||
|
||||
@@ -8,6 +8,9 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
@@ -61,13 +64,15 @@ class HemoCubeFragment : Fragment() {
|
||||
private var deviceHardwareId = ""
|
||||
private var allErrorMessages = ""
|
||||
private var testStatusCode = 0.0
|
||||
private var repeatReadingCount = 0
|
||||
private var readingsPerSample = Constants.READINGS_PER_SAMPLE
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
): View {
|
||||
binding = FragmentHemoCubeReferenceBinding.inflate(inflater, container, false)
|
||||
sharedPreferences =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -130,25 +135,36 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.tvDeviceMessages.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
// val spinner: Spinner = binding.spinnerSolutions
|
||||
// val options = arrayOf("KMnO4", "Tartrazine", "AR", "HB", "Blood")
|
||||
// val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, options)
|
||||
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
// spinner.adapter = adapter
|
||||
// spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
// override fun onItemSelected(
|
||||
// parent: AdapterView<*>?,
|
||||
// view: View?,
|
||||
// position: Int,
|
||||
// id: Long
|
||||
// ) {
|
||||
// val selectedValue: String = options[position]
|
||||
// }
|
||||
//
|
||||
// override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast(R.string.test_upload)
|
||||
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.visibility = View.GONE
|
||||
val i = Intent(
|
||||
requireContext().applicationContext, DashboardActivity::class.java
|
||||
)
|
||||
startActivity(i)
|
||||
|
||||
}
|
||||
handleReadingFinish()
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast(R.string.internt_not_local)
|
||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||
handleReadingFinish()
|
||||
}
|
||||
if (result == "Error") {
|
||||
showToast(R.string.error_local)
|
||||
@@ -186,6 +202,34 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleReadingFinish() {
|
||||
if (allReadingsComplete()) {
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.visibility = View.GONE
|
||||
val i = Intent(
|
||||
requireContext().applicationContext, DashboardActivity::class.java
|
||||
)
|
||||
startActivity(i)
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.messages.postValue("Reading $repeatReadingCount completed")
|
||||
resetTest()
|
||||
startSampleProcess()
|
||||
}
|
||||
}
|
||||
|
||||
private fun allReadingsComplete(): Boolean {
|
||||
return repeatReadingCount >= readingsPerSample
|
||||
}
|
||||
|
||||
private fun resetTest() {
|
||||
testStatusCode = 0.0
|
||||
allErrorMessages = ""
|
||||
validationError = false
|
||||
resultData = ""
|
||||
currentResultData = ""
|
||||
}
|
||||
|
||||
private fun checkAndStartProcess() {
|
||||
startBufferProcess()
|
||||
}
|
||||
@@ -486,11 +530,20 @@ class HemoCubeFragment : Fragment() {
|
||||
led4Gain4 = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
||||
}
|
||||
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
||||
repeatReadingCount += 1
|
||||
|
||||
if (readingsPerSample == 1) {
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
// binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
||||
binding.ivCheck.visibility = View.VISIBLE
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -917,10 +970,4 @@ class HemoCubeFragment : Fragment() {
|
||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
||||
return coefficient1 * ratio + coefficient2
|
||||
}
|
||||
|
||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
||||
return true
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user