diff --git a/app/build.gradle b/app/build.gradle
index 4fae05b..4ce47d7 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -19,8 +19,8 @@ android {
applicationId "in.sminnovations.hpostesting"
minSdk 21
targetSdk 34
- versionCode 28
- versionName "2.1.28"
+ versionCode 30
+ versionName "2.1.30"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 98c18c5..c2f6365 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,9 @@
+
+
diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt
index df6acee..bf12655 100644
--- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt
+++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt
@@ -80,16 +80,16 @@ object Constants {
val DEVICE_CONFIGURATION: Map>> = mapOf>>(
"HCV-000-3001" to listOf(
- listOf(1.264817, -0.85965), // LED1
- listOf(0.581462456, -0.58502), // LED2
- listOf(0.184991, 0.184991), // LED3
+ listOf(1.264817, -0.85965), // LED1, 435nm
+ listOf(0.581462456, -0.58502), // LED2, 415nm
+ listOf(0.184991, 0.001704), // LED3, 555nm
listOf(1.0, 0.0) // LED4
),
"HCV-000-3002" to listOf(
- listOf(1.264817, -0.85965), // LED1
- listOf(0.581462456, -0.58502), // LED2
- listOf(0.184991, 0.184991), // LED3
- listOf(1.0, 0.0) // LED4
+ listOf(1.264817, -0.85965),
+ listOf(0.581462456, -0.58502),
+ listOf(0.184991, 0.001704),
+ listOf(1.0, 0.0)
),
)
diff --git a/app/src/main/java/com/example/hpostesting/data/dao/MyDataBase.kt b/app/src/main/java/com/example/hpostesting/data/dao/MyDataBase.kt
index 05de1a3..62cbda1 100644
--- a/app/src/main/java/com/example/hpostesting/data/dao/MyDataBase.kt
+++ b/app/src/main/java/com/example/hpostesting/data/dao/MyDataBase.kt
@@ -11,7 +11,7 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
import com.google.android.datatransport.runtime.dagger.Provides
import javax.inject.Singleton
-@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 8, exportSchema = false)
+@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 10, exportSchema = false)
@TypeConverters(Converters::class)
abstract class MyDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt
index ca9c9ad..f410705 100644
--- a/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt
+++ b/app/src/main/java/com/example/hpostesting/data/model/patient/HemoCubeTestData.kt
@@ -46,4 +46,9 @@ data class HemoCubeTestData(
var coefficients: String? = "",
var classificationResult: String = "",
var prdClassification: String = "",
+ var batteryLevel: String = "",
+ var batteryCapacity: String = "",
+ var batteryMaxCapacity: String = "",
+ var batteryTemperature: String = "",
+ var batteryVoltage: String = "",
)
diff --git a/app/src/main/java/com/example/hpostesting/presentation/adapter/OfflineUserListAdapter.kt b/app/src/main/java/com/example/hpostesting/presentation/adapter/OfflineUserListAdapter.kt
index 59dc423..6acd933 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/adapter/OfflineUserListAdapter.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/adapter/OfflineUserListAdapter.kt
@@ -9,6 +9,7 @@ import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.hpostesting.data.DataHolder
+import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.data.model.patient.HemoCubeTestData
import com.example.hpostesting.data.model.patient.UserData
import `in`.sminnovations.hpostesting.R
@@ -74,13 +75,13 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
).show()
} else {
if (userList.incubationTime != "") {
- if (isBetween15And30Minutes(userList.incubationTime) < 15) {
+ if (isBetween15And30Minutes(userList.incubationTime) < Constants.INCUBATION_TIME_MIN) {
Toast.makeText(
view.context,
"Incubation has not completed 15 minutes",
Toast.LENGTH_SHORT
).show()
- } else if (isBetween15And30Minutes(userList.incubationTime) > 30) {
+ } else if (isBetween15And30Minutes(userList.incubationTime) > Constants.INCUBATION_TIME_MAX) {
Toast.makeText(
view.context,
"Incubation crossed 30 minutes, need to repeat the incubation",
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 a673e16..f8c9f51 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
@@ -468,7 +468,7 @@ class HemoCubeFragment : Fragment() {
}
}
- if (led1Average < 0 || led2Average < 0 || led3Average < 0 || led4Average < 0) {
+ if (fittedAbs1 < 0 || fittedAbs2 < 0 || fittedAbs3 < 0 || fittedAbs4 < 0) {
validationError = true
activity?.runOnUiThread {
binding.errorMessage.text = "Error: Negative Abs. Retake Blank Reading"
@@ -502,24 +502,31 @@ class HemoCubeFragment : Fragment() {
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
this.classificationResult = findResult(calculatedRatio)
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
- hemoCubeViewModel.messages.postValue(this.classificationResult)
+ hemoCubeViewModel.messages.postValue(this.prdClassification)
this.resultData = deviceLog
- 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()
- }
+ this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()
+ this.batteryCapacity = hemoCubeViewModel.getBatteryCapacity(requireContext()).toString()
+ this.batteryMaxCapacity = hemoCubeViewModel.getBatteryMaxCapacity(requireContext()).toString()
+ this.batteryTemperature = hemoCubeViewModel.getBatteryTemperature().toString()
+ this.batteryVoltage = hemoCubeViewModel.getBatteryVoltage(requireContext()).toString()
+ }
+
+ 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()
}
- if (!validationError) {
- activity?.runOnUiThread {
- binding.btnSubmit.visibility = View.VISIBLE
- binding.btnSubmit.isEnabled = true
- binding.btnSubmit.isClickable = true
- binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
- }
+ }
+
+ if (!validationError) {
+ activity?.runOnUiThread {
+ binding.btnSubmit.visibility = View.VISIBLE
+ binding.btnSubmit.isEnabled = true
+ binding.btnSubmit.isClickable = true
+ binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
}
}
} catch (e: Exception) {
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 7b9679f..10fd645 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
@@ -1,7 +1,10 @@
package com.example.hpostesting.presentation.hemocube
import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
import android.content.SharedPreferences
+import android.os.BatteryManager
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
@@ -47,6 +50,11 @@ class HemoCubeViewModel @Inject constructor(
get() = _networkStatusLiveData
val fireBaseUpload = MutableLiveData()
val fireBaseBulkUpload = MutableLiveData()
+
+ private val batteryStatus: Intent? = IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter ->
+ context.registerReceiver(null, ifilter)
+ }
+
fun uploadHemoCubeResultToDatabase(isOnline: Boolean, testStatus: Boolean, kitSerial: String?) =
viewModelScope.launch {
if (kitSerial != null) {
@@ -116,6 +124,11 @@ class HemoCubeViewModel @Inject constructor(
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
testDetails?.prdClassification = DataHolder.hemoCubeTestData?.prdClassification.toString()
+ testDetails?.batteryLevel = DataHolder.hemoCubeTestData?.batteryLevel.toString()
+ testDetails?.batteryCapacity = DataHolder.hemoCubeTestData?.batteryCapacity.toString()
+ testDetails?.batteryMaxCapacity = DataHolder.hemoCubeTestData?.batteryMaxCapacity.toString()
+ testDetails?.batteryTemperature = DataHolder.hemoCubeTestData?.batteryTemperature.toString()
+ testDetails?.batteryVoltage = DataHolder.hemoCubeTestData?.batteryVoltage.toString()
}
private fun addResultTestToDb() {
@@ -203,4 +216,49 @@ class HemoCubeViewModel @Inject constructor(
fun deleteById(userId: String) = viewModelScope.launch {
hemoCubeDao.deleteById(id = userId)
}
+
+ fun getBatteryLevel(): Float? {
+ val batteryPct: Float? = batteryStatus?.let { intent ->
+ val level: Int = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
+ val scale: Int = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
+ level * 100 / scale.toFloat()
+ }
+
+ return batteryPct
+ }
+
+ fun getBatteryTemperature(): Float? {
+ val batteryTemp: Float? = batteryStatus?.let { intent ->
+ val temperature = intent?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) ?: 0
+ temperature.toFloat() / 10
+ }
+
+ return batteryTemp
+ }
+
+ fun getBatteryVoltage(context: Context): Float {
+ val batteryIntent = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
+ val voltage = batteryIntent?.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0) ?: 0
+
+ // milli-volts to volts
+ return voltage.toFloat() / 1000
+ }
+
+ fun getBatteryCapacity(context: Context): Int {
+ val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
+ val currentCapacity = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
+
+ return currentCapacity
+ }
+
+ fun getBatteryMaxCapacity(context: Context): Float {
+ val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
+ val designCapacity = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
+ val currentCapacity = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
+
+ // Calculate the estimated maximum battery capacity in mAh
+ val maxCapacity = currentCapacity.toFloat() / designCapacity.toFloat() * 100
+
+ return maxCapacity
+ }
}
\ No newline at end of file