Merge branch 'Homocube' of https://gitlab.com/sminnovations/hpos into Homocube

This commit is contained in:
Pritimay Sarkar
2023-08-04 22:41:49 +05:30
4 changed files with 33 additions and 34 deletions

View File

@@ -60,8 +60,8 @@ class KitScanActivity : AppCompatActivity() {
with(sharedPreference.edit()) {
putString(Constants.KIT_NUMBER, "")
putInt(Constants.KIT_COUNT, 0)
putInt(Constants.BUFFER_VALUE_1, 0)
putInt(Constants.BUFFER_VALUE_2, 0)
putString(Constants.BUFFER_VALUE_1, "")
putString(Constants.BUFFER_VALUE_2, "")
apply()
}
}
@@ -94,8 +94,8 @@ class KitScanActivity : AppCompatActivity() {
private fun checkHemoCubeKitData(): Boolean {
return sharedPreference.getString(Constants.KIT_NUMBER, "")
?.isNotBlank() == true || sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0
|| sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
?.isNotBlank() == true && sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0
&& sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
}
private fun isSerialValid(s: String): Boolean {

View File

@@ -54,7 +54,7 @@ class MainActivity : AppCompatActivity() {
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) {
locationResult.lastLocation?.let { location ->
DataHolder.selectedTest!!.location =
DataHolder.location =
UserData.Location(location.latitude, location.longitude)
Log.i("Location", DataHolder.location.toString())
}
@@ -222,6 +222,8 @@ class MainActivity : AppCompatActivity() {
location?.let {
DataHolder.selectedTest!!.location =
UserData.Location(location.latitude, location.longitude)
DataHolder.location =
UserData.Location(location.latitude, location.longitude)
} ?: run {
requestLocationUpdates()
}

View File

@@ -3,9 +3,6 @@ package com.example.hpostesting.presentation.hemocube
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbDeviceConnection
import android.hardware.usb.UsbManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -15,7 +12,6 @@ import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.data.constant.HemoCubeCommands
@@ -23,8 +19,6 @@ import com.example.hpostesting.data.model.patient.DeviceData
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
import com.example.hpostesting.presentation.KitScanActivity
import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.dashboard.HomeFragment
import com.example.hpostesting.presentation.testRight.TestRightExpSample
import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils
import `in`.sminnovations.hpostesting.R
@@ -110,8 +104,7 @@ class HemoCubeFragment : Fragment() {
listenToHemoCube()
startSample()
}
}
)
})
} else {
listenToHemoCube()
startBuffer()
@@ -119,8 +112,16 @@ class HemoCubeFragment : Fragment() {
}
private fun checkBufferValue(): Boolean {
return sharedPreference.getInt(Constants.BUFFER_VALUE_1, 0) > 0
|| sharedPreference.getInt(Constants.BUFFER_VALUE_2, 0) > 0
return if (sharedPreference.getString(Constants.BUFFER_VALUE_1, "") != ""
&& sharedPreference.getString(Constants.BUFFER_VALUE_2, "") != ""
) {
sharedPreference.getString(Constants.BUFFER_VALUE_1, "")
?.toInt()!! > 0 && sharedPreference.getString(Constants.BUFFER_VALUE_2, "")
?.toInt()!! > 0
} else {
false
}
}
private fun setupButtonClickListeners() {
@@ -136,7 +137,7 @@ class HemoCubeFragment : Fragment() {
startBuffer()
}
binding.btnKit.setOnClickListener() {
binding.btnKit.setOnClickListener {
with(sharedPreference.edit()) {
putInt(Constants.KIT_COUNT, 0)
apply()
@@ -213,13 +214,16 @@ class HemoCubeFragment : Fragment() {
if (isOnline) {
resultRatio?.let { ratio ->
Log.e("Testdb", "upload")
hemoCubeViewModel.uploadHemoCubeResultToDatabase(isOnline, true, kitSerial
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
isOnline, true, kitSerial
)
}
binding.progressBar.visibility = View.VISIBLE
} else {
resultRatio?.let { ratio ->
hemoCubeViewModel.uploadHemoCubeResultToDatabase(isOnline, true, kitSerial)
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
isOnline, true, kitSerial
)
}
Toast.makeText(
requireContext(),
@@ -240,45 +244,39 @@ class HemoCubeFragment : Fragment() {
private fun startBuffer() {
hemoCubeViewModel.progressBar.postValue(true)
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
HemoCubeCommands.startBuffer,
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false)
}
}
)
})
}
private fun startSample() {
hemoCubeViewModel.progressBar.postValue(true)
val fullReadOutput = StringBuilder()
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
HemoCubeCommands.startSample,
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false)
}
}
)
})
}
private fun getResult() {
hemoCubeViewModel.progressBar.postValue(true)
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
HemoCubeCommands.getSample,
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false)
}
}
)
})
}
private fun calculateRatio(ratio: Double): Double {
@@ -290,8 +288,7 @@ class HemoCubeFragment : Fragment() {
private fun checkAndFindResults(results: List<String>): String {
val reversedResults = results.reversed()
for (line in reversedResults) {
if (isValidFormat(line))
return line
if (isValidFormat(line)) return line
}
return ""
}

View File

@@ -29,7 +29,7 @@ class HemoCubeViewModel @Inject constructor(
) : ViewModel() {
var isServiceConnected = false
val progressBar = MutableLiveData(false)
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
@@ -69,7 +69,7 @@ class HemoCubeViewModel @Inject constructor(
private fun addResultTestToDb() {
testDetails?.deviceRatio = DataHolder.hemocubeResult
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
testDetails?.location = DataHolder.hemoCubeTestData?.location
testDetails?.location = DataHolder.location
testDetails?.testTime = SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
).format(Calendar.getInstance().time)