Done with error handling

This commit is contained in:
mohamedkaif356
2023-08-08 15:30:46 +05:30
parent 2bb87c7780
commit f3c292b268
5 changed files with 43 additions and 45 deletions

View File

@@ -39,15 +39,13 @@ android {
dataBinding {
enabled = true
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildFeatures {
viewBinding true
}
lint {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {

View File

@@ -42,7 +42,6 @@
android:name="com.example.hpostesting.presentation.dashboard.DashboardActivity"
android:exported="false"
android:label="@string/title_activity_dashboard"
android:screenOrientation="portrait"
android:theme="@style/Theme.HPOS.NoActionBar" />
<service
@@ -66,7 +65,6 @@
android:exported="false"
android:noHistory="true"
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.HPOS.NoActionBar"
android:windowSoftInputMode="adjustPan">
@@ -82,7 +80,6 @@
<activity
android:name="com.example.hpostesting.presentation.MainActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />

View File

@@ -32,6 +32,7 @@ class HemoCubeFragment : Fragment() {
private var isOnline = false
private var currentDeviceData: DeviceData? = null
private var resultData: String = ""
private var isUsingExistingBuffer = false
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
@@ -107,9 +108,16 @@ class HemoCubeFragment : Fragment() {
}
private fun isBufferValueAvailable(): Boolean {
val buffer1 = sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDouble() ?: 0.0
val buffer2 = sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDouble() ?: 0.0
return buffer1 > 0.0 && buffer2 > 0.0
return if (sharedPreferences.getString(
Constants.BUFFER_VALUE_1, ""
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
) {
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
?.toDouble()!! > 0.0 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
?.toDouble()!! > 0.0
} else {
false
}
}
private fun showBufferAlertDialog() {
@@ -132,6 +140,7 @@ class HemoCubeFragment : Fragment() {
override fun onClickPositiveButton() {
listenToHemoCube()
startSampleProcess()
isUsingExistingBuffer = true
}
})
}
@@ -178,7 +187,7 @@ class HemoCubeFragment : Fragment() {
}
stringData.contains("RESULT") || resultData.contains("REND") -> {
var validString = ""
var validString: String
val results: List<String>
if (stringData.contains("RESULT")) {
validString = isValidResult(stringData)
@@ -230,6 +239,7 @@ class HemoCubeFragment : Fragment() {
}
private fun showStartSampleDialog() {
activity?.runOnUiThread {
UIUtils.createAlertDialog(requireContext(),
"Start Sample",
"Do you want to start sample reading?",
@@ -239,43 +249,36 @@ class HemoCubeFragment : Fragment() {
override fun onClickNegativeButton() {}
override fun onClickPositiveButton() {
listenToHemoCube()
startSampleProcess()
}
})
}
}
private fun handleValidResult(validString: String, fullReadOutput: String) {
val result = validString.split(" ")
if (result.size == 8) {
val deviceSerialNo = result[2]
var led1Buffer = result[3].toDoubleOrNull()
var led2Buffer = result[4].toDoubleOrNull()
val led1BufferForDevice = result[3].toDoubleOrNull()
val led2BufferForDevice = result[4].toDoubleOrNull()
val led1Sample = result[5].toDoubleOrNull()
val led2Sample = result[6].toDoubleOrNull()
val led1Average = log10(led1Buffer?.div(led1Sample!!) ?: 0.0)
val led2Average = log10(led2Buffer?.div(led2Sample!!) ?: 0.0)
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
val deviceRatio = led1Average / led2Average
DataHolder.hemoCubeTestData?.apply {
deviceSerialNumber = deviceSerialNo
led1Buffer = if (sharedPreferences.getInt(
Constants.KIT_COUNT, 0
) < 35 && sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
.isNullOrEmpty()
) {
led1Buffer
} else {
led1Buffer = if (isUsingExistingBuffer) {
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
}
led2Buffer = if (sharedPreferences.getInt(
Constants.KIT_COUNT, 0
) < 35 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
.isNullOrEmpty()
) {
led2Buffer
} else {
led1BufferForDevice
}
led2Buffer = if (isUsingExistingBuffer) {
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
} else {
led2BufferForDevice
}
this.led1Sample = led1Sample
this.led2Sample = led2Sample

View File

@@ -94,7 +94,7 @@ class HemoCubeViewModel @Inject constructor(
is Response.Success -> {
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
with(sharedPreference.edit()) {
putInt(Constants.KIT_COUNT, kitCount?.plus(1) ?: 0)
putInt(Constants.KIT_COUNT, kitCount.plus(1) ?: 0)
apply()
}
Log.i("Testdb", "Data uploaded to Firestore successfully")

View File

@@ -3,7 +3,7 @@ buildscript {
kotlin_version = '1.8.21'
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
classpath 'com.android.tools.build:gradle:8.1.0'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.0'
}