Added placebuffer and sample buttons for the new feature

This commit is contained in:
smileomi18@gmail.com
2023-09-15 17:03:03 +05:30
parent 1d542f5562
commit f019e1897d
4 changed files with 76 additions and 20 deletions

View File

@@ -91,7 +91,8 @@ class HomeFragment : Fragment() {
}
}
private fun loadUserData() {
val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false).orderBy("createdAt", Query.Direction.DESCENDING)
// val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false).orderBy("createdAt", Query.Direction.DESCENDING)
val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false)
query.get().addOnSuccessListener {
if (it.documents.isEmpty()) {
binding.pendingTest.visibility = View.VISIBLE

View File

@@ -57,7 +57,7 @@ class HemoCubeFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
initViews()
observeViewModel()
checkAndStartProcess()
// checkAndStartProcess()
}
private fun initViews() {
@@ -78,6 +78,17 @@ class HemoCubeFragment : Fragment() {
binding.btnSubmit.isEnabled = false
binding.btnSubmit.isClickable = false
binding.btnSamplestart.setOnClickListener {
startSampleProcess()
it.visibility = View.GONE
}
binding.btnPlacebuffer.setOnClickListener {
checkAndStartProcess()
it.visibility = View.GONE
}
binding.btnKit.setOnClickListener {
if (isTestOngoing) {
val title = "WARNING"
@@ -155,7 +166,7 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
currentDeviceData = it
showToast(calculateRatio(0.17).toString())
// showToast(calculateRatio(0.17).toString())
}
@@ -169,12 +180,12 @@ class HemoCubeFragment : Fragment() {
}
private fun checkAndStartProcess() {
if (isBufferValueAvailable()) {
showBufferAlertDialog()
} else {
listenToHemoCube()
startBufferProcess()
}
// if (isBufferValueAvailable()) {
// showBufferAlertDialog()
// } else {
listenToHemoCube()
startBufferProcess()
// }
}
private fun isBufferValueAvailable(): Boolean {
@@ -249,7 +260,12 @@ class HemoCubeFragment : Fragment() {
when {
stringData.contains("ERROR 500") -> showError500Dialog()
stringData.contains("ERROR 501") -> showError501Dialog()
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
stringData.contains("#Buffer Completed") ->
activity?.runOnUiThread {
binding.btnSamplestart.visibility = View.VISIBLE
binding.btnSamplestart.isClickable = true
}
stringData.contains("#Sample Completed") -> {
activity?.runOnUiThread {
binding.btnSubmit.isEnabled = true
@@ -320,7 +336,7 @@ class HemoCubeFragment : Fragment() {
override fun onClickNegativeButton() {}
override fun onClickPositiveButton() {
startSampleProcess()
}
})
}
@@ -366,7 +382,7 @@ class HemoCubeFragment : Fragment() {
this.led1Average = led1Average
this.led2Average = led2Average
this.deviceRatio = deviceRatio
this.calculatedRatio = calculateRatio(deviceRatio)
// this.calculatedRatio = calculateRatio(deviceRatio)
this.resultData = fullReadOutput
if (!isBufferValueAvailable()) {
with(sharedPreferences.edit()) {
@@ -382,7 +398,11 @@ class HemoCubeFragment : Fragment() {
}
} catch (_: Exception) {
Toast.makeText( requireContext(), "Error while processing device data", Toast.LENGTH_SHORT).show()
Toast.makeText(
requireContext(),
"Error while processing device data",
Toast.LENGTH_SHORT
).show()
}
}
@@ -430,11 +450,11 @@ class HemoCubeFragment : Fragment() {
})
}
private fun calculateRatio(ratio: Double): Double {
val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
return coefficient1 * ratio + coefficient2
}
// private fun calculateRatio(ratio: Double): Double {
// val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
// val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
// return coefficient1 * ratio + coefficient2
// }
private fun parseResult(frames: List<String>): String {
val lines = mutableListOf<String>()