hemocube alert Dialogue

This commit is contained in:
smileomi18@gmail.com
2023-08-02 16:33:46 +05:30
parent f6613b3b69
commit ece2cec4c0
4 changed files with 54 additions and 58 deletions

View File

@@ -23,9 +23,7 @@ object DataHolder {
val intensityReferenceArray = ArrayList<Double>()
var selectedTest: UserData? = null
var hemoCubeTestData: HemoCubeTestData? = null
var kitSerial: String = ""
var location: UserData.Location? = null
var testExp: Boolean = true
var hemocubeResult: Double? = null

View File

@@ -1,6 +1,7 @@
package com.example.hpostesting.data.dao
import androidx.room.TypeConverter
import com.example.hpostesting.data.model.patient.HemoCubeTestData
import com.example.hpostesting.data.model.patient.UserData
import com.google.gson.Gson
@@ -15,7 +16,6 @@ class Converters {
null
}
}
@TypeConverter
fun toString(location: UserData.Location?): String? {
return if (location != null) {
@@ -24,4 +24,24 @@ class Converters {
null
}
}
@TypeConverter
fun fromLocation(value: String?): HemoCubeTestData.Location? {
return if (value != null) {
gson.fromJson(value, HemoCubeTestData.Location::class.java)
} else {
null
}
}
@TypeConverter
fun toLocation(location: HemoCubeTestData.Location?): String? {
return if (location != null) {
gson.toJson(location)
} else {
null
}
}
}

View File

@@ -20,8 +20,14 @@ data class HemoCubeTestData(
var deviceSerialNumber: String = "",
var kitSerial: String = "",
var reportPath: String = "",
var locationhemo: Location? = null,
var resultRatio: Double? = null,
var resultData: String = "",
var led1: Double? = null,
var led2: Double? = null
)
){
data class Location(
var latitude: Double? = null,
var longitude: Double? = null
)
}

View File

@@ -10,13 +10,14 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils
import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
@@ -76,8 +77,30 @@ class HemoCubeFragment : Fragment() {
private fun setupButtonClickListeners() {
binding.btnShowResult.setOnClickListener {
// readUsbData()
fetchHemoCubeResult()
UIUtils.createAlertDialog(
requireContext(),
"WARNING",
"Please check if you have placed the sample of this person",
getString(R.string.no),
"Yes",
object : MyDialogListener {
override fun onClickNegativeButton() {}
override fun onClickPositiveButton() {
UIUtils.createAlertDialog(
requireContext(),
getString(R.string.have_you_placed_sample),
getString(R.string.please_place_sample),
getString(R.string.no),
getString(R.string.yes_and_run),
object : MyDialogListener {
override fun onClickNegativeButton() {}
override fun onClickPositiveButton() {
fetchHemoCubeResult()
}
})
}
})
}
binding.btnSubmit.setOnClickListener {
@@ -164,20 +187,6 @@ class HemoCubeFragment : Fragment() {
Log.d("greenBuffer", blueIntensity.toString())
Log.d("greenBuffer", blueBIntensity.toString())
}
private fun displayValuesOnTextView(parsedData: Map<String, String>) {
val fullReadOutput = StringBuilder()
val textView: TextView = requireView().findViewById(R.id.tv_subtitle4)
val resultText = buildString {
for ((label, value) in parsedData) {
append("$label: $value\n")
}
}
fullReadOutput.append(resultText)
textView.text = fullReadOutput.toString()
}
private fun fetchHemoCubeResult() {
if (DataHolder.hemoCubeTestData == null) {
DataHolder.hemoCubeTestData = DataHolder.selectedTest?.toHemoCubeTestData()
@@ -207,41 +216,4 @@ class HemoCubeFragment : Fragment() {
}
})
}
private fun fetchHemoCubeResultNew() {
hemoCubeViewModel.progressBar.postValue(true)
val fullReadOutput = StringBuilder()
(activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(object :
UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {
data?.let {
val stringData = String(it)
fullReadOutput.append(stringData)
// Split the data into lines
val lines = fullReadOutput.toString().split("\n")
// Filter and get only the lines starting with "#"
val bufferLines = lines.filter { it.startsWith("#") }
// Create a new text with the filtered lines and join them with line breaks
val newText = bufferLines.joinToString("\n")
// Update the TextView with the new text
binding.tvSubtitle4.text = newText
// Get the result data
val data = parseUsbData(fullReadOutput.toString())
Log.d("Result", data.toString())
// Update the view model with progress bar state
hemoCubeViewModel.progressBar.postValue(false)
}
}
override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false)
}
})
}
}