diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt index 2f3c12b..25640d7 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt @@ -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 { diff --git a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt index b573edb..9bf68b3 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt @@ -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() } diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index 89fad71..ca55438 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -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 { val reversedResults = results.reversed() for (line in reversedResults) { - if (isValidFormat(line)) - return line + if (isValidFormat(line)) return line } return "" } diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt index 58c0c6f..e731e1c 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt @@ -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)