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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,25 +208,44 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="12dp"
|
||||
<TextView
|
||||
android:id="@+id/tv_device_messages"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="414dp"
|
||||
android:layout_height="201dp"
|
||||
android:gravity="center"
|
||||
android:text="#SS1\n#SC1"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="11sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/error_message">
|
||||
app:layout_constraintTop_toBottomOf="@id/error_message" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_device_messages"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="11sp"
|
||||
android:visibility="gone" />
|
||||
</ScrollView>
|
||||
<!-- <Spinner-->
|
||||
<!-- android:id="@+id/spinner_solutions"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="16dp"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
||||
|
||||
<!-- <Spinner-->
|
||||
<!-- android:id="@+id/spinner_concentration"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="16dp"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/spinner_solutions" />-->
|
||||
|
||||
<!-- <Spinner-->
|
||||
<!-- android:id="@+id/spinner_volume"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="16dp"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/spinner_concentration" />-->
|
||||
|
||||
<Button
|
||||
android:visibility="gone"
|
||||
@@ -241,6 +260,19 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/error_message" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_check"
|
||||
android:visibility="gone"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/check"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_device_messages" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user