From e77b4d9a239b9b607462e8620d1cb44cd39558fc Mon Sep 17 00:00:00 2001 From: chandrashekhar reddy Date: Tue, 17 Sep 2024 12:47:53 +0530 Subject: [PATCH] Changes in 127, added HBTest screen option --- app/build.gradle | 2 +- app/google-services.json | 177 +++++++++++++-- app/release/output-metadata.json | 2 +- .../hpostesting/data/constant/DataHolder.kt | 3 + .../data/repository/DatabaseRepository.kt | 11 +- .../presentation/dashboard/HomeFragment.kt | 4 + .../presentation/hb_test/HBTestFragment.kt | 207 ++++++++++++------ .../presentation/hb_test/HBTestViewModel.kt | 30 +-- app/src/main/res/layout/fragment_hb_test.xml | 4 +- 9 files changed, 330 insertions(+), 110 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 581a71f..b28b990 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { // dev -> development, quality -> qc, uat -> User Acceptance Testing, preprod -> preproduction, prod -> production, iocl -> iocl-iisc production defaultConfig { - applicationId "in.sminnovations.hpostesting.iocl" + applicationId "in.sminnovations.hpostesting.dev" minSdk 21 targetSdk 34 versionCode 127 diff --git a/app/google-services.json b/app/google-services.json index 1ddf40e..a73fe1e 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -1,64 +1,205 @@ { "project_info": { - "project_number": "243503501547", - "project_id": "iocl-iisc-hpos", - "storage_bucket": "iocl-iisc-hpos.appspot.com" + "project_number": "650071678820", + "project_id": "hpos-af3cc", + "storage_bucket": "hpos-af3cc.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:243503501547:android:f17de652a3524d047feeae", + "mobilesdk_app_id": "1:650071678820:android:f1435a1c07f710036c6471", "android_client_info": { - "package_name": "com.iocl_iisc.hposqc" + "package_name": "com.example.hposconsentform" } }, - "oauth_client": [], + "oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], "api_key": [ { - "current_key": "AIzaSyBPxgcDkZfZMr8cFrkMWkVf1a-MstzWC1k" + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" } ], "services": { "appinvite_service": { - "other_platform_oauth_client": [] + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] } } }, { "client_info": { - "mobilesdk_app_id": "1:243503501547:android:e1bb0f338c8448dd7feeae", + "mobilesdk_app_id": "1:650071678820:android:7865bef608cdee6f6c6471", "android_client_info": { - "package_name": "in.sminnovations.hposregistration.iocl" + "package_name": "com.smi.counselling" } }, - "oauth_client": [], + "oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], "api_key": [ { - "current_key": "AIzaSyBPxgcDkZfZMr8cFrkMWkVf1a-MstzWC1k" + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" } ], "services": { "appinvite_service": { - "other_platform_oauth_client": [] + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] } } }, { "client_info": { - "mobilesdk_app_id": "1:243503501547:android:18b8b33b2dc3776d7feeae", + "mobilesdk_app_id": "1:650071678820:android:2925e9ce3417d2386c6471", "android_client_info": { - "package_name": "in.sminnovations.hpostesting.iocl" + "package_name": "in.sminnovations.hemocube" } }, - "oauth_client": [], + "oauth_client": [ + { + "client_id": "650071678820-srhm9spm9hjn4frcd3r6o02gdhdbtd15.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "in.sminnovations.hemocube", + "certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a" + } + }, + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], "api_key": [ { - "current_key": "AIzaSyBPxgcDkZfZMr8cFrkMWkVf1a-MstzWC1k" + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" } ], "services": { "appinvite_service": { - "other_platform_oauth_client": [] + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:650071678820:android:7569c1cad4fc99916c6471", + "android_client_info": { + "package_name": "in.sminnovations.hposregistration" + } + }, + "oauth_client": [ + { + "client_id": "650071678820-70kp5jvjda4r5diqch2kn4lc40p4f42g.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "in.sminnovations.hposregistration", + "certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a" + } + }, + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:650071678820:android:f96be19e5d43102b6c6471", + "android_client_info": { + "package_name": "in.sminnovations.hpostesting" + } + }, + "oauth_client": [ + { + "client_id": "650071678820-l87dnr0bdj95get0khgnvfv2an1k6ogq.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "in.sminnovations.hpostesting", + "certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a" + } + }, + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:650071678820:android:a53292637abb7c0d6c6471", + "android_client_info": { + "package_name": "in.sminnovations.hpostesting.dev" + } + }, + "oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com", + "client_type": 3 + } + ] } } } diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 0750472..7b820b1 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -4,7 +4,7 @@ "type": "APK", "kind": "Directory" }, - "applicationId": "in.sminnovations.hpostesting.iocl", + "applicationId": "in.sminnovations.hpostesting.dev", "variantName": "release", "elements": [ { diff --git a/app/src/main/java/com/example/hpostesting/data/constant/DataHolder.kt b/app/src/main/java/com/example/hpostesting/data/constant/DataHolder.kt index 7dbfa27..247ddcc 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/DataHolder.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/DataHolder.kt @@ -21,6 +21,7 @@ import com.example.hpostesting.data.model.test.TestType object DataHolder { + var sampleId: String = "sampleId" var selectedTestType: TestType = TestType.SICKLECERT val usbConnected = MutableLiveData(true) var mobileUniqueId: String? = null @@ -37,6 +38,8 @@ object DataHolder { val intensityReferenceArray = ArrayList() var selectedTest: UserData? = null var hemoCubeTestData: HemoCubeTestData? = null + var bloodGroup: String = "Unknown" + var age = "0" var kitSerial: String = "" var centerName: String = "" var district: String = "" diff --git a/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt b/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt index cc673ab..d17eee3 100644 --- a/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt +++ b/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt @@ -122,15 +122,10 @@ class DatabaseRepository @Inject constructor( } override suspend fun addQcTestToDatabase(data: HemoCubeTestData?): Response { return try { - val userdata = - db.collection("patientData").whereEqualTo("_id", data!!._id).get().await() - if (userdata.documents.isNotEmpty()) { - userdata.documents.forEach { - db.collection("patientData").document(it.id).update("testStatus", true) - } - } - db.collection("qcData").add(data).await() + + db.collection("qcData").add(data!!).await() Response.Success(data._id) + } catch (e: Exception) { Response.Error(e) } diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt index 9f924a7..9e24a50 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt @@ -31,6 +31,7 @@ import android.os.BatteryManager import android.os.Build import android.os.Bundle import android.os.Environment +import android.provider.ContactsContract.Data import android.provider.Settings import android.util.Base64 import android.util.Log @@ -798,8 +799,11 @@ class HomeFragment : Fragment() { private fun setUserId() { binding.btnSubmit.setOnClickListener { val userId = binding.userId.text.toString() + DataHolder.sampleId = userId val age = binding.age.text.toString() + DataHolder.age = age val bloodGroup = binding.etBloodGroup.text.toString() + DataHolder.bloodGroup = bloodGroup // if (userId.length >= 5 && bloodGroup != "Select Blood Group") { // DataHolder.selectedTest = UserData( diff --git a/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestFragment.kt index ffdc477..7c579cf 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestFragment.kt @@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.MutableLiveData import com.example.hpostesting.data.constant.Constants +import com.example.hpostesting.data.constant.DataHolder import com.example.hpostesting.data.constant.HemoCubeCommands import com.example.hpostesting.data.model.diagnostics.DiagnosticsData import com.example.hpostesting.data.model.patient.DeviceData @@ -41,7 +42,21 @@ import java.util.Locale import kotlin.math.log10 class HBTestFragment : Fragment() { - private var readClick = false + private var isUsingExistingBuffer = false + private var led1Average = 0.0 + private var led3Average = 0.0 + private var led2Average = 0.0 + private var led4Average = 0.0 + private var led1SampleForDevice = 0.0 + private var led2SampleForDevice = 0.0 + private var led3SampleForDevice = 0.0 + private var led4SampleForDevice = 0.0 + private var led1BufferForDevice = 0.0 + private var led2BufferForDevice = 0.0 + private var led3BufferForDevice = 0.0 + private var led4BufferForDevice = 0.0 + private var x = 0.0 + private var deviceId = "" private var hbEst = 0.0 private var testStatusCode = 0.0 private var testDetails: HemoCubeTestData = HemoCubeTestData() @@ -76,20 +91,54 @@ class HBTestFragment : Fragment() { binding.btnSubmit.setOnClickListener { hBTestViewModel.messages.postValue(resultData) binding.btnSubmit.visibility = View.GONE - + testDetails.localFlag = false + testDetails.testStatus = true + testDetails.deviceId = deviceId + testDetails._id = DataHolder.sampleId + testDetails.kitSerial = DataHolder.kitSerial + testDetails.classificationResult = "HB: $hbEst" + testDetails.hb3 = x + testDetails.hb4 = hbEst + testDetails.age = DataHolder.age + testDetails.bloodGroup = DataHolder.bloodGroup + testDetails.led1Buffer = led1BufferForDevice + testDetails.led2Buffer = led2BufferForDevice + testDetails.led3Buffer = led3BufferForDevice + testDetails.led4Buffer = led4BufferForDevice + testDetails.led1Sample = led1SampleForDevice + testDetails.led2Sample = led2SampleForDevice + testDetails.led3Sample = led3SampleForDevice + testDetails.led4Sample = led4SampleForDevice + testDetails.led1Average = led1Average + testDetails.led2Average = led2Average + testDetails.led3Average = led3Average + testDetails.led4Average = led4Average + testDetails.testType = "HB Est" + testDetails.testTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time) hBTestViewModel.uploadFirebaseQc(testDetails) } binding.btnBuffer.setOnClickListener { binding.btnBuffer.visibility = View.GONE + hBTestViewModel.messages.postValue("Buffer Started") runBCommand() } binding.btnSample.setOnClickListener { + hBTestViewModel.messages.postValue("Sample Started") binding.btnSample.visibility = View.GONE + binding.btnBuffer.visibility = View.GONE runSCommand() } - binding.btnSubmit.setOnClickListener { - binding.btnSubmit.visibility = View.GONE - + if (isBufferValueAvailable()) { + isUsingExistingBuffer = true + binding.btnBuffer.text = "Refresh Buffer" + binding.btnSample.isEnabled = true + binding.btnSample.isClickable = true + }else{ + binding.btnBuffer.text = "Start Buffer" + binding.btnSample.isEnabled = false + binding.btnSample.isClickable = false } } @@ -106,10 +155,11 @@ class HBTestFragment : Fragment() { hBTestViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result -> if (result == "Success") { - showToast("Auto Dac data uploaded successfully") + showToast("Data uploaded successfully") + requireActivity().finish() } if (result == "Local") { - showToast("Auto Dac uploading failed, note it down manually") + showToast("Data uploading failed, note it down manually") } binding.progressBar.visibility = View.GONE @@ -124,6 +174,7 @@ class HBTestFragment : Fragment() { override fun onUsbRead(data: ByteArray?) { data?.let { val stringData = String(it) + deviceId = stringData hBTestViewModel.messages.postValue(stringData) binding.tvSubtitle4.text = stringData } @@ -187,14 +238,13 @@ class HBTestFragment : Fragment() { val stringData = String(it) fullReadOutput.append(stringData) resultData += stringData - if (sharedPreferences.getString(Constants.USER_ID, "").toString() == "ADMIN") { - hBTestViewModel.messages.postValue(resultData) - } + hBTestViewModel.messages.postValue(resultData) // binding.tvSubtitle4.text = resultData if (stringData.contains("SN")) { val slData = stringData.split(" ") if (slData.size > 1) { val hardwareId = slData[1].trim() + hBTestViewModel.messages.postValue("Place buffer and click below button to start test") // with(sharedPreferences.edit()) { // putString(Constants.DEVICE_ID, hardwareId) // apply() @@ -207,27 +257,27 @@ class HBTestFragment : Fragment() { } if (resultData.contains("#BC") && testStatusCode < 1.0) { testStatusCode = 1.1 - hBTestViewModel.messages.postValue( - getString(R.string.buffer_completed) + "\n" + getString(R.string.gathering_data) - ) + resultData += getString(R.string.buffer_completed) + hBTestViewModel.messages.postValue(resultData) activity?.runOnUiThread { binding.btnSample.visibility = View.VISIBLE + binding.btnSample.isEnabled = true + binding.btnSample.isClickable = true } } if (resultData.contains("#SC") && testStatusCode < 1.3) { testStatusCode = 1.4 - hBTestViewModel.messages.postValue( - getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data) - ) + resultData +=getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data) + hBTestViewModel.messages.postValue(resultData) activity?.runOnUiThread { binding.btnSubmit.visibility = View.VISIBLE + runPCommand() } - runPCommand() } - if (resultData.contains("REND") && readClick && testStatusCode < 2.1) { - testStatusCode = 2.2 + if (resultData.contains("REND") && testStatusCode < 1.5) { + testStatusCode = 1.6 runResult() } } @@ -242,76 +292,99 @@ class HBTestFragment : Fragment() { } private fun runResult() { - hBTestViewModel.messages.postValue("Fetching results...") + resultData += "\nFetching results...\n" + hBTestViewModel.messages.postValue(resultData) + val resultLines = resultData.split("\\s+(?=LB|LS)".toRegex()) var bufferIntensity = resultLines[1].split(' ')[1].trim() - val led1BufferForDevice = bufferIntensity.toDoubleOrNull()!! + led1BufferForDevice = if (isUsingExistingBuffer) { + sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()!! + } else { + bufferIntensity.toDoubleOrNull()!! + } bufferIntensity = resultLines[2].split(' ')[1].trim() - val led2BufferForDevice = bufferIntensity.toDoubleOrNull()!! + led2BufferForDevice = if (isUsingExistingBuffer) { + sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()!! + } else { + bufferIntensity.toDoubleOrNull()!! + } bufferIntensity = resultLines[3].split(' ')[1].trim() - val led3BufferForDevice = bufferIntensity.toDoubleOrNull()!! + led3BufferForDevice = if (isUsingExistingBuffer) { + sharedPreferences.getString(Constants.BUFFER_VALUE_3, "")?.toDoubleOrNull()!! + } else { + bufferIntensity.toDoubleOrNull()!! + } bufferIntensity = resultLines[4].split(' ')[1].trim() - val led4BufferForDevice = bufferIntensity.toDoubleOrNull()!! + led4BufferForDevice = if (isUsingExistingBuffer) { + sharedPreferences.getString(Constants.BUFFER_VALUE_4, "")?.toDoubleOrNull()!! + } else { + bufferIntensity.toDoubleOrNull()!! + } - val led1SampleForDevice = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!! - val led2SampleForDevice = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!! - val led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!! - val led4SampleForDevice = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!! + led1SampleForDevice = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!! + led2SampleForDevice = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!! + led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!! + led4SampleForDevice = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!! - val led1Average = log10(led1BufferForDevice.div(led1SampleForDevice)) - val led2Average = log10(led2BufferForDevice.div(led2SampleForDevice)) - val led3Average = log10(led3BufferForDevice.div(led3SampleForDevice)) - val led4Average = log10(led4BufferForDevice.div(led4SampleForDevice)) + led1Average = log10(led1BufferForDevice.div(led1SampleForDevice)) + led2Average = log10(led2BufferForDevice.div(led2SampleForDevice)) + led3Average = log10(led3BufferForDevice.div(led3SampleForDevice)) + led4Average = log10(led4BufferForDevice.div(led4SampleForDevice)) - val x = led1Average - led3Average + x = led1Average - led3Average hbEst = (7.347 * x * x) + (12.704 * x) + 0.9033 - hBTestViewModel.messages.postValue("Result: HB EST: $hbEst") - } - - fun extractSubstring(input: String): String { - val regex = "#CS(.*?)#CC".toRegex() - val matchResult = regex.find(input) - return matchResult?.groups?.get(1)?.value?.trim() ?: "" - } - private fun validateDacValues(): Boolean { - val pattern = Regex("(LED:\\d+)__DAC:(\\d+)__ADC:(\\d+)") - val matches = pattern.findAll(resultData) - for (match in matches) { - val ledName = match.groupValues[1] - val xValue = match.groupValues[2].toDouble() - val yValue = match.groupValues[3].toDouble() - - if(xValue == 3200.0){ - if(yValue < 500.0){ - return false - } + resultData +="\n Result: HB EST: $hbEst" + if (!isUsingExistingBuffer) { + with(sharedPreferences.edit()) { + putString(Constants.BUFFER_VALUE_1, led1BufferForDevice.toString()) + putString(Constants.BUFFER_VALUE_2, led2BufferForDevice.toString()) + putString(Constants.BUFFER_VALUE_3, led3BufferForDevice.toString()) + putString(Constants.BUFFER_VALUE_4, led4BufferForDevice.toString()) + apply() } } - return true + hBTestViewModel.messages.postValue(resultData) } - fun parseData(inputData: List): List> { - val pattern = Regex("([A-Z]+)\\s(\\d+)") - val parsedData = mutableListOf>() - for (item in inputData) { - val matchResult = pattern.find(item) - if (matchResult != null) { - val (letters, numbers) = matchResult.destructured - parsedData.add(Pair(letters, numbers)) - } - } - - return parsedData - } private fun showToast(message: String) { Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() } + private fun isBufferValueAvailable(): Boolean { + return try { + if (sharedPreferences.getString( + Constants.BUFFER_VALUE_1, "" + ) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != "" + && sharedPreferences.getString(Constants.BUFFER_VALUE_3, "") != "" + && sharedPreferences.getString(Constants.BUFFER_VALUE_4, "") != "" + ) { + sharedPreferences.getString(Constants.BUFFER_VALUE_1, "") + ?.toDouble()!! > 0.0 && sharedPreferences.getString( + Constants.BUFFER_VALUE_2, + "" + ) + ?.toDouble()!! > 0.0 && sharedPreferences.getString( + Constants.BUFFER_VALUE_3, + "" + ) + ?.toDouble()!! > 0.0 && sharedPreferences.getString( + Constants.BUFFER_VALUE_4, + "" + ) + ?.toDouble()!! > 0.0 + } else { + false + } + } catch (e: Exception) { + showToast("error_exist") + false + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestViewModel.kt index 8be379d..bf8b04b 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hb_test/HBTestViewModel.kt @@ -45,21 +45,25 @@ class HBTestViewModel @Inject constructor( val fireBaseUpload = MutableLiveData() fun uploadFirebaseQc(testDetails: HemoCubeTestData){ viewModelScope.launch { - when (val response = repository.addQcTestToDatabase(testDetails)) { - is Response.Success -> { - Log.i("Testdb", "Data uploaded to Firestore successfully") - fireBaseUpload.postValue("Success") - testDetails.localFlag = true - hemoCubeDao.updateTest(testDetails) - } + try { + when (val response = repository.addTestToDatabase(testDetails)) { + is Response.Success -> { + Log.i("Testdb", "Data uploaded to Firestore successfully") + fireBaseUpload.postValue("Success") + testDetails.localFlag = true + hemoCubeDao.updateTest(testDetails) + } - is Response.Error -> { - Log.e("Testdb", "Error uploading data to Firestore: $response") - fireBaseUpload.postValue("Error") - hemoCubeDao.updateTest(testDetails) - } + is Response.Error -> { + Log.e("Testdb", "Error uploading data to Firestore: $response") + fireBaseUpload.postValue("Error") + hemoCubeDao.updateTest(testDetails) + } - else -> {} + else -> {} + } + } catch (e: Exception) { + fireBaseUpload.postValue("Error") } } } diff --git a/app/src/main/res/layout/fragment_hb_test.xml b/app/src/main/res/layout/fragment_hb_test.xml index ac7f0f0..e19a3cd 100644 --- a/app/src/main/res/layout/fragment_hb_test.xml +++ b/app/src/main/res/layout/fragment_hb_test.xml @@ -92,10 +92,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" - android:layout_marginTop="24dp" + android:layout_marginTop="15dp" android:clickable="false" android:gravity="center" - android:visibility="gone" + android:visibility="visible" android:text="Sample Start" android:textColor="@color/white" app:layout_constraintEnd_toEndOf="parent"