Compare commits
1 Commits
HposUnitTe
...
logoutAuto
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
583a94d42a |
@@ -18,8 +18,8 @@ android {
|
|||||||
applicationId "in.sminnovations.hpostesting"
|
applicationId "in.sminnovations.hpostesting"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 24
|
versionCode 20
|
||||||
versionName "2.1.24"
|
versionName "2.1.21"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,6 @@ dependencies {
|
|||||||
|
|
||||||
//firebase
|
//firebase
|
||||||
implementation platform('com.google.firebase:firebase-bom:32.1.0')
|
implementation platform('com.google.firebase:firebase-bom:32.1.0')
|
||||||
implementation("com.google.firebase:firebase-perf-ktx")
|
|
||||||
implementation("com.google.firebase:firebase-crashlytics-ktx")
|
implementation("com.google.firebase:firebase-crashlytics-ktx")
|
||||||
implementation("com.google.firebase:firebase-analytics-ktx")
|
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||||
implementation 'com.google.firebase:firebase-firestore-ktx'
|
implementation 'com.google.firebase:firebase-firestore-ktx'
|
||||||
@@ -71,16 +70,15 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
||||||
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
||||||
implementation 'com.google.android.things:androidthings:1.0'
|
implementation 'com.google.android.things:androidthings:1.0'
|
||||||
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
|
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta10'
|
||||||
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
|
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta10")
|
||||||
|
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
testImplementation 'org.mockito:mockito-core:3.12.0'
|
|
||||||
testImplementation "androidx.arch.core:core-testing:2.2.0"
|
|
||||||
|
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
||||||
implementation 'com.opencsv:opencsv:4.6'
|
implementation 'com.opencsv:opencsv:4.6'
|
||||||
@@ -98,17 +96,17 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
||||||
|
|
||||||
//Room
|
//Room
|
||||||
implementation "androidx.room:room-ktx:2.6.0-rc01"
|
implementation "androidx.room:room-ktx:2.6.0-beta01"
|
||||||
implementation "androidx.room:room-runtime:2.6.0-rc01"
|
implementation "androidx.room:room-runtime:2.6.0-beta01"
|
||||||
kapt ("androidx.room:room-compiler:2.6.0-rc01")
|
kapt ("androidx.room:room-compiler:2.6.0-beta01")
|
||||||
|
|
||||||
//image
|
//image
|
||||||
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
||||||
|
|
||||||
// Navigation Component
|
// Navigation Component
|
||||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.3"
|
implementation "androidx.navigation:navigation-fragment-ktx:2.7.2"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.3"
|
implementation "androidx.navigation:navigation-ui-ktx:2.7.2"
|
||||||
|
|
||||||
//Dagger - Hilt
|
//Dagger - Hilt
|
||||||
implementation "com.google.dagger:hilt-android:2.46"
|
implementation "com.google.dagger:hilt-android:2.46"
|
||||||
|
|||||||
@@ -13,11 +13,8 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.usb.host" />
|
<uses-feature android:name="android.hardware.usb.host" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -29,9 +26,6 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.HPOSTesting"
|
android:theme="@style/Theme.HPOSTesting"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
|
||||||
android:name="com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity"
|
|
||||||
android:exported="false" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
|
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
@@ -107,6 +101,7 @@
|
|||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
tools:replace="android:screenOrientation" />
|
tools:replace="android:screenOrientation" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -69,5 +69,4 @@ object Constants {
|
|||||||
const val KIT_COUNT = "KitCount"
|
const val KIT_COUNT = "KitCount"
|
||||||
const val BUFFER_VALUE_1 = "BufferValue1"
|
const val BUFFER_VALUE_1 = "BufferValue1"
|
||||||
const val BUFFER_VALUE_2 = "BufferValue2"
|
const val BUFFER_VALUE_2 = "BufferValue2"
|
||||||
const val DEVICE_ID = "DEVICE_ID"
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,7 @@ package com.example.hpostesting.data.constant
|
|||||||
|
|
||||||
enum class HemoCubeCommands(val command: String) {
|
enum class HemoCubeCommands(val command: String) {
|
||||||
startBuffer("B\r"),
|
startBuffer("B\r"),
|
||||||
runDiagnostics("D\r"),
|
getBuffer("Q\r"),
|
||||||
startSample("S\r"),
|
startSample("S\r"),
|
||||||
getSample("P\r"),
|
getSample("P\r"),
|
||||||
getDeviceId("I\r"),
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.diagnostics
|
|
||||||
|
|
||||||
data class DiagnosticsData (
|
|
||||||
var deviceId: String = "",
|
|
||||||
var appVersion: String? = "",
|
|
||||||
var deviceType: String = "HEMOCUBE",
|
|
||||||
var deviceData: String = "",
|
|
||||||
var runTime: String = ""
|
|
||||||
)
|
|
||||||
@@ -15,7 +15,5 @@ data class BufferCheckData(
|
|||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null,
|
||||||
var coefficients: String? = "",
|
var classificationResult: String = ""
|
||||||
var classificationResult: String = "",
|
|
||||||
var testTime: String = ""
|
|
||||||
)
|
)
|
||||||
@@ -30,6 +30,5 @@ data class HemoCubeTestData(
|
|||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null,
|
||||||
var coefficients: String? = "",
|
|
||||||
var classificationResult: String = ""
|
var classificationResult: String = ""
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.example.hpostesting.di
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.components.ViewModelComponent
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(ViewModelComponent::class)
|
|
||||||
object ViewModelModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
fun provideTestRightViewModel(
|
|
||||||
saveRawData: SaveRawData,
|
|
||||||
saveRawDataTest: SaveRawDataTest,
|
|
||||||
databaseRepository: DatabaseRepository,
|
|
||||||
userDao: UserDao,
|
|
||||||
context: Context
|
|
||||||
): TestRightViewModel {
|
|
||||||
return TestRightViewModel(saveRawData, saveRawDataTest, databaseRepository, userDao, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package com.example.hpostesting.data.repository
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.example.hpostesting.data.model.PendingUploads
|
import com.example.hpostesting.data.model.PendingUploads
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
|
||||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
@@ -62,16 +61,6 @@ class DatabaseRepository : Repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addDiagnostics(data: DiagnosticsData?): Response<String> {
|
|
||||||
return try {
|
|
||||||
db.collection("diagnostics").add(data!!).await()
|
|
||||||
Response.Success(data!!.deviceId)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Firebase.crashlytics.recordException(e)
|
|
||||||
Response.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -138,8 +127,4 @@ class DatabaseRepository : Repository {
|
|||||||
// Find the DeviceData object with the specified deviceId
|
// Find the DeviceData object with the specified deviceId
|
||||||
return allDeviceDataList.find { it.deviceId == deviceId }
|
return allDeviceDataList.find { it.deviceId == deviceId }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
interface Repository {
|
interface Repository {
|
||||||
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
|
||||||
// suspend fun addToDatabase(data: PatientDetails)
|
// suspend fun addToDatabase(data: PatientDetails)
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ import com.google.firebase.ktx.Firebase
|
|||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class HemoCubeBufferCheckFragment : Fragment() {
|
class HemoCubeBufferCheckFragment : Fragment() {
|
||||||
|
|
||||||
@@ -63,8 +60,6 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
|
|
||||||
binding.nameEditText.setText("SMI/SC/")
|
binding.nameEditText.setText("SMI/SC/")
|
||||||
binding.tvTitle.visibility = View.GONE
|
|
||||||
binding.tvName.visibility = View.GONE
|
|
||||||
|
|
||||||
binding.btnGo.setOnClickListener {
|
binding.btnGo.setOnClickListener {
|
||||||
val serialNumber = binding.nameEditText.text.toString().trim()
|
val serialNumber = binding.nameEditText.text.toString().trim()
|
||||||
@@ -217,7 +212,7 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
try {
|
try {
|
||||||
val result = validString.split(" ")
|
val result = validString.split(" ")
|
||||||
if (result.size == 8) {
|
if (result.size == 8) {
|
||||||
val deviceId = result[2]
|
val deviceSerialNo = result[2]
|
||||||
val led1BufferForDevice = result[3].toDoubleOrNull()
|
val led1BufferForDevice = result[3].toDoubleOrNull()
|
||||||
val led2BufferForDevice = result[4].toDoubleOrNull()
|
val led2BufferForDevice = result[4].toDoubleOrNull()
|
||||||
val led1Sample = result[5].toDoubleOrNull()
|
val led1Sample = result[5].toDoubleOrNull()
|
||||||
@@ -225,11 +220,10 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||||
val deviceRatio = led1Average / led2Average
|
val deviceRatio = led1Average / led2Average
|
||||||
val calculateRatio = calculateRatio(deviceRatio)
|
val calculatedRatio = 0.14
|
||||||
val classificationResult = findResult(calculateRatio)
|
val classificationResult = findResult(calculatedRatio)
|
||||||
messages.postValue(classificationResult)
|
messages.postValue(classificationResult)
|
||||||
val bufferData = BufferCheckData(
|
val bufferData = BufferCheckData(
|
||||||
deviceId= deviceId,
|
|
||||||
kitno = kitno,
|
kitno = kitno,
|
||||||
led1Buffer = led1BufferForDevice,
|
led1Buffer = led1BufferForDevice,
|
||||||
led2Buffer = led2BufferForDevice,
|
led2Buffer = led2BufferForDevice,
|
||||||
@@ -238,13 +232,9 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
led1Sample = led1Sample,
|
led1Sample = led1Sample,
|
||||||
led2Sample = led2Sample,
|
led2Sample = led2Sample,
|
||||||
deviceRatio = deviceRatio,
|
deviceRatio = deviceRatio,
|
||||||
calculatedRatio = calculateRatio,
|
calculatedRatio = calculatedRatio,
|
||||||
coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString(),
|
|
||||||
classificationResult = classificationResult,
|
classificationResult = classificationResult,
|
||||||
deviceSerialNumber = sharedPreferences.getString(Constants.USER_ID, "").toString(),
|
deviceSerialNumber = deviceSerialNo
|
||||||
testTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
)
|
)
|
||||||
hemoCubeViewModel.uploadHemoCubeResultToDatabaseforbuffercheckN(bufferData)
|
hemoCubeViewModel.uploadHemoCubeResultToDatabaseforbuffercheckN(bufferData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,15 +66,12 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
|
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
|
||||||
firebaseAppDistribution.updateIfNewReleaseAvailable()
|
firebaseAppDistribution.updateIfNewReleaseAvailable()
|
||||||
.addOnProgressListener { updateProgress ->
|
.addOnProgressListener { updateProgress ->
|
||||||
|
|
||||||
if (updateProgress.apkBytesDownloaded > 0) {
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this,
|
this,
|
||||||
"${updateProgress.updateStatus}. ${updateProgress.apkBytesDownloaded / 1048576} /${updateProgress.apkFileTotalBytes / 1048576} MB",
|
"${updateProgress.updateStatus}. ${updateProgress.apkBytesDownloaded / 1048576} /${updateProgress.apkFileTotalBytes / 1048576} MB",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.addOnFailureListener { e ->
|
.addOnFailureListener { e ->
|
||||||
// (Optional) Handle errors.
|
// (Optional) Handle errors.
|
||||||
if (e is FirebaseAppDistributionException) {
|
if (e is FirebaseAppDistributionException) {
|
||||||
@@ -85,18 +82,14 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Handle other errors.
|
// Handle other errors.
|
||||||
Toast.makeText(
|
Toast.makeText(this, "AppDistribution error, status: ${e.errorCode}", Toast.LENGTH_SHORT).show()
|
||||||
this,
|
|
||||||
"AppDistribution error, status: ${e.errorCode}",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FirebaseCrashlytics.getInstance().recordException(e)
|
FirebaseCrashlytics.getInstance().recordException(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.addOnSuccessListener {
|
.addOnSuccessListener {
|
||||||
// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity
|
import com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity
|
||||||
import com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding
|
||||||
|
|
||||||
class GalleryFragment : Fragment() {
|
class GalleryFragment : Fragment() {
|
||||||
@@ -36,12 +35,6 @@ class GalleryFragment : Fragment() {
|
|||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
|
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnDiagnostics.setOnClickListener {
|
|
||||||
startActivity(Intent(requireContext(), DiagnosticsActivity::class.java))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.google.firebase.crashlytics.ktx.crashlytics
|
|||||||
import com.google.firebase.firestore.Query
|
import com.google.firebase.firestore.Query
|
||||||
import com.google.firebase.firestore.ktx.firestore
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import com.google.firebase.perf.ktx.performance
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||||
@@ -40,7 +39,7 @@ import java.util.Locale
|
|||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
private var _binding: FragmentHomeBinding? = null
|
private var _binding: FragmentHomeBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
private lateinit var rvAdapter: UserListAdapter
|
private lateinit var rvAdapter: UserListAdapter
|
||||||
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||||
@@ -192,25 +191,14 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getData(search: String?, field: String) {
|
private fun getData(search: String?, field: String) {
|
||||||
val userSearchTrace = Firebase.performance.newTrace("user_search_trace")
|
|
||||||
userSearchTrace.start()
|
|
||||||
|
|
||||||
search?.replaceFirstChar {
|
search?.replaceFirstChar {
|
||||||
if (search.lowercase()
|
if (search.lowercase()
|
||||||
.startsWith(it.lowercase())
|
.startsWith(it.lowercase())
|
||||||
) it.titlecase(Locale.getDefault()) else it.toString()
|
) it.titlecase(Locale.getDefault()) else it.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
val currentDate = Date()
|
val query = Firebase.firestore.collection("patientData").orderBy(field).startAt(search)
|
||||||
val dateFormat = SimpleDateFormat("yyyyMMdd")
|
.endAt(search + "\uf8ff")
|
||||||
val partition = dateFormat.format(currentDate)
|
|
||||||
val searchTerm = partition + search
|
|
||||||
val searchField = field + "Search"
|
|
||||||
val query = Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm)
|
|
||||||
.endAt(searchTerm + "\uf8ff")
|
|
||||||
query.get().addOnSuccessListener {
|
|
||||||
userSearchTrace.stop()
|
|
||||||
}
|
|
||||||
val recyclerViewOptions =
|
val recyclerViewOptions =
|
||||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||||
.build()
|
.build()
|
||||||
@@ -222,8 +210,6 @@ class HomeFragment : Fragment() {
|
|||||||
}!!
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
|
|
||||||
userSearchTrace.stop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSearch() {
|
private fun setSearch() {
|
||||||
|
|||||||
@@ -1,176 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.diagnostics
|
|
||||||
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.content.ServiceConnection
|
|
||||||
import android.hardware.usb.UsbDevice
|
|
||||||
import android.hardware.usb.UsbDeviceConnection
|
|
||||||
import android.hardware.usb.UsbManager
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.os.IBinder
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.view.get
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityDiagnosticsBinding
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class DiagnosticsActivity : AppCompatActivity() {
|
|
||||||
private lateinit var binding: ActivityDiagnosticsBinding
|
|
||||||
val viewModel: DiagnosticsViewModel by viewModels()
|
|
||||||
private var myMenu: Menu? = null
|
|
||||||
|
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
|
||||||
private var mConnection: UsbDeviceConnection? = null
|
|
||||||
lateinit var mService: UsbService
|
|
||||||
|
|
||||||
private val TAG = "HemoCube"
|
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
|
|
||||||
synchronized(this) {
|
|
||||||
val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
|
|
||||||
|
|
||||||
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
|
||||||
device?.apply {
|
|
||||||
connectUsb(true)
|
|
||||||
DataHolder.usbConnected.postValue(true)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onErrorReported("permission denied for device")
|
|
||||||
DataHolder.usbConnected.postValue(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private val connection = object : ServiceConnection {
|
|
||||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
|
||||||
val binder = service as UsbService.UsbServiceBinder
|
|
||||||
mService = binder.getService()
|
|
||||||
viewModel.isServiceConnected = true
|
|
||||||
mConnection.let { mService.connect(mDriver, mConnection!!) }
|
|
||||||
moveToNext()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
|
||||||
viewModel.isServiceConnected = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
binding = ActivityDiagnosticsBinding.inflate(layoutInflater)
|
|
||||||
setContentView(binding.root)
|
|
||||||
// setSupportActionBar(binding.myToolbar)
|
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
||||||
setupListener()
|
|
||||||
connectUsb(false)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupListener() {
|
|
||||||
DataHolder.usbConnected.observe(this) {
|
|
||||||
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
|
||||||
if (it) {
|
|
||||||
myMenu?.get(0)?.icon =
|
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
|
||||||
} else {
|
|
||||||
myMenu?.get(0)?.icon =
|
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
|
||||||
Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
open fun connectUsb(permissionGranted: Boolean) {
|
|
||||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
|
||||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
|
||||||
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
|
|
||||||
|
|
||||||
if (availableDrivers.isEmpty()) {
|
|
||||||
onErrorReported("No Device is Connected")
|
|
||||||
} else {
|
|
||||||
mDriver = availableDrivers[0]
|
|
||||||
mConnection = manager.openDevice(mDriver.device)
|
|
||||||
|
|
||||||
if (mConnection == null) {
|
|
||||||
requestUserPermission(manager, mDriver.device)
|
|
||||||
} else {
|
|
||||||
setupService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun onErrorReported(msg: String) {
|
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
|
||||||
if (!isFinishing) onBackPressed()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun moveToNext() {
|
|
||||||
if (supportFragmentManager.isDestroyed) return
|
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction().replace(binding.fgDiagnostics.id, DiagnosticsFragment())
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
|
||||||
val mPendingIntent: PendingIntent
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
|
||||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
|
||||||
this,
|
|
||||||
0,
|
|
||||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
|
||||||
registerReceiver(broadcastReceiver, filter)
|
|
||||||
manager.requestPermission(device, mPendingIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun setupService() {
|
|
||||||
val intent = Intent(this, UsbService::class.java)
|
|
||||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
|
||||||
menuInflater.inflate(R.menu.my_menu, menu)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
if (viewModel.isServiceConnected) {
|
|
||||||
mService.disconnect()
|
|
||||||
unbindService(connection)
|
|
||||||
viewModel.isServiceConnected = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.diagnostics
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.Toast
|
|
||||||
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.HemoCubeCommands
|
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
|
||||||
import com.google.firebase.ktx.Firebase
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDiagnosticsBinding
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class DiagnosticsFragment : Fragment() {
|
|
||||||
|
|
||||||
private lateinit var binding: FragmentDiagnosticsBinding
|
|
||||||
private val diagnosticsViewModel: DiagnosticsViewModel by activityViewModels()
|
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
|
||||||
private var currentDeviceData: DeviceData? = null
|
|
||||||
private var resultData: String = ""
|
|
||||||
private val messages = MutableLiveData<String>()
|
|
||||||
private var startListening = MutableLiveData(false)
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
|
||||||
): View {
|
|
||||||
binding = FragmentDiagnosticsBinding.inflate(inflater, container, false)
|
|
||||||
sharedPreferences =
|
|
||||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
initViews()
|
|
||||||
observeViewModel()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun initViews() {
|
|
||||||
binding.btnSubmit.visibility = View.GONE
|
|
||||||
listenToHemoCube()
|
|
||||||
getDeviceId()
|
|
||||||
binding.btnSubmit.setOnClickListener {
|
|
||||||
binding.btnSubmit.visibility = View.GONE
|
|
||||||
runDeviceDiagnostics()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun observeViewModel() {
|
|
||||||
|
|
||||||
diagnosticsViewModel.deviceData.observe(viewLifecycleOwner) {
|
|
||||||
currentDeviceData = it
|
|
||||||
}
|
|
||||||
|
|
||||||
messages.observe(viewLifecycleOwner) {
|
|
||||||
binding.tvSubtitle4.text = it
|
|
||||||
Log.e("diagnostics",binding.tvSubtitle4.text.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
diagnosticsViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
|
||||||
if (result == "Success") {
|
|
||||||
showToast("Diagnostics data uploaded successfully")
|
|
||||||
}
|
|
||||||
if (result == "Local") {
|
|
||||||
showToast("Diagnostics uploading failed, note it down manually")
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDeviceId() {
|
|
||||||
diagnosticsViewModel.progressBar.postValue(true)
|
|
||||||
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
|
||||||
HemoCubeCommands.getDeviceId,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
data?.let {
|
|
||||||
val stringData = String(it)
|
|
||||||
diagnosticsViewModel.messages.postValue(stringData)
|
|
||||||
binding.tvSubtitle4.text = stringData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
diagnosticsViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runDeviceDiagnostics() {
|
|
||||||
diagnosticsViewModel.progressBar.postValue(true)
|
|
||||||
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
|
||||||
HemoCubeCommands.runDiagnostics,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
diagnosticsViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun listenToHemoCube() {
|
|
||||||
|
|
||||||
val fullReadOutput = StringBuilder()
|
|
||||||
startListening.postValue(true)
|
|
||||||
|
|
||||||
try {
|
|
||||||
(activity as DiagnosticsActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
data?.let {
|
|
||||||
val stringData = String(it)
|
|
||||||
diagnosticsViewModel.messages.postValue(stringData)
|
|
||||||
fullReadOutput.append(stringData)
|
|
||||||
resultData += stringData
|
|
||||||
binding.tvSubtitle4.text = resultData
|
|
||||||
if (stringData.contains("SN")) {
|
|
||||||
val slData = stringData.split(" ")
|
|
||||||
if (slData.size > 1) {
|
|
||||||
val hardwareId = slData[1].trim()
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.DEVICE_ID, hardwareId)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultData.contains("END") || fullReadOutput.contains("END")) {
|
|
||||||
diagnosticsViewModel.addDiagnosticsDataToDb(DiagnosticsData(
|
|
||||||
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString(),
|
|
||||||
deviceData = resultData,
|
|
||||||
runTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
// val inputData = mutableListOf<String>()
|
|
||||||
// while (true) {
|
|
||||||
// if (fullReadOutput.toString().lowercase() == "end") {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// inputData.add(fullReadOutput.toString())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// val parsedData = parseData(inputData)
|
|
||||||
// Log.i("D-Data", parsedData.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
diagnosticsViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Firebase.crashlytics.recordException(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun parseData(inputData: List<String>): List<Pair<String, String>> {
|
|
||||||
val pattern = Regex("([A-Z]+)\\s(\\d+)")
|
|
||||||
val parsedData = mutableListOf<Pair<String, String>>()
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.diagnostics
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
|
||||||
import com.example.hpostesting.data.model.Response
|
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Locale
|
|
||||||
import javax.inject.Inject
|
|
||||||
@HiltViewModel
|
|
||||||
class DiagnosticsViewModel @Inject constructor(
|
|
||||||
private val hemoCubeDao: HemoCubeDao,
|
|
||||||
private val repository: DatabaseRepository,
|
|
||||||
context: Context
|
|
||||||
) : ViewModel() {
|
|
||||||
var isServiceConnected = false
|
|
||||||
val progressBar = MutableLiveData(false)
|
|
||||||
val messages = MutableLiveData<String>()
|
|
||||||
private val sharedPreference: SharedPreferences =
|
|
||||||
context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
|
||||||
val allUserData = hemoCubeDao.getAll()
|
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
|
||||||
get() = _networkStatusLiveData
|
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
|
||||||
|
|
||||||
fun addDiagnosticsDataToDb(data: DiagnosticsData) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
when (val response = repository.addDiagnostics(data)) {
|
|
||||||
is Response.Success -> {
|
|
||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
|
||||||
fireBaseUpload.postValue("Success")
|
|
||||||
}
|
|
||||||
|
|
||||||
is Response.Error -> {
|
|
||||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
|
||||||
fireBaseUpload.postValue("Error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
|
||||||
fireBaseUpload.postValue("Error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package com.example.hpostesting.presentation.hemocube
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.graphics.Color
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -13,20 +12,27 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
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.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
import com.example.hpostesting.presentation.utils.UIUtils
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import com.google.firebase.perf.ktx.performance
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.tasks.await
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
|
|
||||||
class HemoCubeFragment : Fragment() {
|
class HemoCubeFragment : Fragment() {
|
||||||
@@ -41,8 +47,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private var isUsingExistingBuffer = false
|
private var isUsingExistingBuffer = false
|
||||||
private var isTestOngoing = false
|
private var isTestOngoing = false
|
||||||
private var startListening = MutableLiveData<Boolean>(false)
|
private var startListening = MutableLiveData<Boolean>(false)
|
||||||
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
@@ -61,32 +65,88 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
|
// val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||||
|
// if (bloodGroupText.isEmpty()) {
|
||||||
|
// binding.etBloodGroup.error = "Please enter your blood group"
|
||||||
|
// } else {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||||
)
|
)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
if (isTestOngoing) {
|
if (isTestOngoing) {
|
||||||
// binding.btnKit.visibility = View.GONE
|
// binding.btnKit.visibility = View.GONE
|
||||||
// binding.btnKit.isEnabled = false
|
// binding.btnKit.isEnabled = false
|
||||||
// binding.btnKit.isClickable = false
|
// binding.btnKit.isClickable = false
|
||||||
}
|
|
||||||
|
|
||||||
binding.tvTitle2.visibility = View.GONE
|
}
|
||||||
binding.etAbhaId.visibility = View.GONE
|
|
||||||
binding.nameEditText.visibility = View.GONE
|
|
||||||
binding.tvTitle.visibility = View.GONE
|
|
||||||
binding.btnGo.visibility = View.GONE
|
|
||||||
binding.btnSubmit.isEnabled = false
|
binding.btnSubmit.isEnabled = false
|
||||||
binding.btnSubmit.isClickable = false
|
binding.btnSubmit.isClickable = false
|
||||||
|
|
||||||
|
|
||||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||||
Log.e("nametext", binding.tvName.text.toString())
|
Log.e("nametext",binding.tvName.text.toString())
|
||||||
|
|
||||||
|
// binding.btnKit.setOnClickListener {
|
||||||
|
// if (isTestOngoing) {
|
||||||
|
// val title = "WARNING"
|
||||||
|
// val message = "There is a on going test, do you want to stop it"
|
||||||
|
// val negativeText = getString(R.string.no)
|
||||||
|
// val positiveText = "Yes"
|
||||||
|
//
|
||||||
|
// UIUtils.createAlertDialog(requireContext(),
|
||||||
|
// title,
|
||||||
|
// message,
|
||||||
|
// negativeText,
|
||||||
|
// positiveText,
|
||||||
|
// object : MyDialogListener {
|
||||||
|
// override fun onClickNegativeButton() {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onClickPositiveButton() {
|
||||||
|
// resetKitCount()
|
||||||
|
// val intent = Intent(context, KitScanActivity::class.java)
|
||||||
|
// startActivity(intent)
|
||||||
|
// (activity as HemocubeActivity).finish()
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// } else {
|
||||||
|
// resetKitCount()
|
||||||
|
// val intent = Intent(context, KitScanActivity::class.java)
|
||||||
|
// startActivity(intent)
|
||||||
|
// (activity as HemocubeActivity).finish()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private suspend fun checkBloodGroup() {
|
||||||
|
// binding.apply {
|
||||||
|
// val bloodGroup = etBloodGroup.text.toString()
|
||||||
|
// if (bloodGroup.isEmpty()) {
|
||||||
|
// etBloodGroup.error = "Please enter your blood group"
|
||||||
|
// } else {
|
||||||
|
// val db: FirebaseFirestore = Firebase.firestore
|
||||||
|
// val userdata = db.collection("patientData")
|
||||||
|
// .whereEqualTo("_id", hemoCubeViewModel.testDetails?._id).get().await()
|
||||||
|
// if (userdata.documents.isNotEmpty()) {
|
||||||
|
// db.collection("patientData").document(userdata.documents[0].id)
|
||||||
|
// .update("bloodGroup", bloodGroup)
|
||||||
|
// withContext(Dispatchers.Main) {
|
||||||
|
// val i = Intent(
|
||||||
|
// requireContext().applicationContext, DashboardActivity::class.java
|
||||||
|
// )
|
||||||
|
// startActivity(i)
|
||||||
|
// (activity as HemocubeActivity).finish()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private fun observeViewModel() {
|
private fun observeViewModel() {
|
||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
@@ -122,6 +182,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
val coefficient1 = coefficients[0]
|
val coefficient1 = coefficients[0]
|
||||||
val coefficient2 = coefficients[1]
|
val coefficient2 = coefficients[1]
|
||||||
val result = coefficient1 * coefficient2
|
val result = coefficient1 * coefficient2
|
||||||
|
// showToast("coefficients: $coefficient1, $coefficient2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isOnline = isNetworkAvailable
|
isOnline = isNetworkAvailable
|
||||||
@@ -232,13 +293,18 @@ class HemoCubeFragment : Fragment() {
|
|||||||
isTestOngoing = true
|
isTestOngoing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resultData += stringData
|
resultData += fullReadOutput.toString()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
|
stringData.contains("ERROR 500") -> showError500Dialog()
|
||||||
|
stringData.contains("ERROR 501") -> showError501Dialog()
|
||||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||||
stringData.contains("#Sample Completed") -> {
|
stringData.contains("#Sample Completed") -> {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.btnSubmit.isEnabled = true
|
||||||
|
binding.btnSubmit.isClickable = true
|
||||||
|
}
|
||||||
fetchResult()
|
fetchResult()
|
||||||
testingTrace.stop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||||
@@ -279,6 +345,23 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun showError500Dialog() {
|
||||||
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
|
"BUFFER ERROR",
|
||||||
|
"Do you want to continue with existing buffer?",
|
||||||
|
getString(R.string.noo),
|
||||||
|
"Yes",
|
||||||
|
object : MyDialogListener {
|
||||||
|
override fun onClickNegativeButton() {}
|
||||||
|
|
||||||
|
override fun onClickPositiveButton() {
|
||||||
|
listenToHemoCube()
|
||||||
|
startBufferProcess()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fun handleBackButtonPress() {
|
fun handleBackButtonPress() {
|
||||||
if (isTestOngoing) {
|
if (isTestOngoing) {
|
||||||
// If the test is ongoing, don't allow the back button action
|
// If the test is ongoing, don't allow the back button action
|
||||||
@@ -291,6 +374,23 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun showError501Dialog() {
|
||||||
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
|
"SAMPLE ERROR",
|
||||||
|
"Do you want to continue with Sample?",
|
||||||
|
getString(R.string.noo),
|
||||||
|
"Yes",
|
||||||
|
object : MyDialogListener {
|
||||||
|
override fun onClickNegativeButton() {}
|
||||||
|
|
||||||
|
override fun onClickPositiveButton() {
|
||||||
|
listenToHemoCube()
|
||||||
|
startSampleProcess()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun showStartSampleDialog() {
|
private fun showStartSampleDialog() {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
@@ -309,23 +409,11 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleValidResult(validString: String, fullReadOutput: String) {
|
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||||
try {
|
try {
|
||||||
val result = validString.split(" ")
|
val result = validString.split(" ")
|
||||||
val deviceLog = resultData
|
|
||||||
if (result.size == 8) {
|
if (result.size == 8) {
|
||||||
val deviceSerialNo = result[2]
|
val deviceSerialNo = result[2]
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.DEVICE_ID, deviceSerialNo)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
val loginId = sharedPreferences.getString(Constants.USER_ID, "").toString()
|
|
||||||
if (checkDeviceIdMismatch(deviceSerialNo, loginId)) {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.errorMessage.text = "Warning: Login Id is different"
|
|
||||||
binding.errorMessage.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
||||||
} else {
|
} else {
|
||||||
@@ -354,15 +442,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (led1Average < 0 || led2Average < 0) {
|
|
||||||
activity?.runOnUiThread{
|
|
||||||
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
|
||||||
binding.errorMessage.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHolder.hemoCubeTestData?.apply {
|
DataHolder.hemoCubeTestData?.apply {
|
||||||
|
|
||||||
|
|
||||||
deviceId = deviceSerialNo
|
deviceId = deviceSerialNo
|
||||||
led1Buffer = led1BufferForDevice
|
led1Buffer = led1BufferForDevice
|
||||||
led2Buffer = led2BufferForDevice
|
led2Buffer = led2BufferForDevice
|
||||||
@@ -373,10 +455,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
this.led2Average = led2Average
|
this.led2Average = led2Average
|
||||||
this.deviceRatio = deviceRatio
|
this.deviceRatio = deviceRatio
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||||
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
|
||||||
this.classificationResult = findResult(calculatedRatio)
|
this.classificationResult = findResult(calculatedRatio)
|
||||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||||
this.resultData = deviceLog
|
this.resultData = fullReadOutput
|
||||||
if (!isUsingExistingBuffer) {
|
if (!isUsingExistingBuffer) {
|
||||||
with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
||||||
@@ -384,12 +465,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
|
||||||
binding.btnSubmit.isEnabled = true
|
|
||||||
binding.btnSubmit.isClickable = true
|
|
||||||
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -448,7 +523,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startSampleProcess() {
|
private fun startSampleProcess() {
|
||||||
testingTrace.start()
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||||
@@ -503,9 +577,11 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
private fun resetKitCount() {
|
||||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
with(sharedPreferences.edit()) {
|
||||||
return true
|
putString(Constants.KIT_NUMBER, "")
|
||||||
return false
|
putInt(Constants.KIT_COUNT, 0)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
||||||
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
||||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||||
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
|
||||||
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube
|
package com.example.hpostesting.presentation.hemocube
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
@@ -7,6 +8,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.hardware.usb.UsbDevice
|
import android.hardware.usb.UsbDevice
|
||||||
import android.hardware.usb.UsbDeviceConnection
|
import android.hardware.usb.UsbDeviceConnection
|
||||||
import android.hardware.usb.UsbManager
|
import android.hardware.usb.UsbManager
|
||||||
@@ -17,10 +19,14 @@ import android.view.Menu
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContentProviderCompat.requireContext
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
|
import com.example.hpostesting.presentation.dashboard.ui.LoginFragment
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||||
@@ -33,7 +39,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
private lateinit var binding: ActivityHemocubeBinding
|
private lateinit var binding: ActivityHemocubeBinding
|
||||||
private val viewModel by viewModels<HemoCubeViewModel>()
|
private val viewModel by viewModels<HemoCubeViewModel>()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
private lateinit var mDriver: UsbSerialDriver
|
||||||
private var mConnection: UsbDeviceConnection? = null
|
private var mConnection: UsbDeviceConnection? = null
|
||||||
lateinit var mService: UsbService
|
lateinit var mService: UsbService
|
||||||
@@ -81,8 +87,11 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
setupListener()
|
setupListener()
|
||||||
connectUsb(false)
|
connectUsb(false)
|
||||||
|
applicationContext.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SuspiciousIndentation")
|
||||||
private fun setupListener() {
|
private fun setupListener() {
|
||||||
DataHolder.usbConnected.observe(this) {
|
DataHolder.usbConnected.observe(this) {
|
||||||
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
||||||
@@ -92,6 +101,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
myMenu?.get(0)?.icon =
|
myMenu?.get(0)?.icon =
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
||||||
|
logoutUser()
|
||||||
Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,4 +195,16 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
viewModel.isServiceConnected = false
|
viewModel.isServiceConnected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun logoutUser() {
|
||||||
|
val intent = Intent(this, DashboardActivity::class.java)
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ import `in`.sminnovations.hpostesting.databinding.ActivityTestRightBinding
|
|||||||
class TestRightActivity : AppCompatActivity() {
|
class TestRightActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityTestRightBinding
|
private lateinit var binding: ActivityTestRightBinding
|
||||||
private val viewModel by viewModels<TestRightViewModel<Any?>>()
|
private val viewModel by viewModels<TestRightViewModel>()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
|
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
private lateinit var mDriver: UsbSerialDriver
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpReferenceB
|
|||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class TestRightExpReference : Fragment() {
|
class TestRightExpReference : Fragment() {
|
||||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private val TAG = "TestRightExpReference"
|
private val TAG = "TestRightExpReference"
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpSampleBind
|
|||||||
class TestRightExpSample : Fragment() {
|
class TestRightExpSample : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTestRightExpSampleBinding
|
private lateinit var binding: FragmentTestRightExpSampleBinding
|
||||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
|
|
||||||
private val TAG = "TestRightExpSample"
|
private val TAG = "TestRightExpSample"
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext
|
|||||||
class TestRightResults : Fragment() {
|
class TestRightResults : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTestRightResultsBinding
|
private lateinit var binding: FragmentTestRightResultsBinding
|
||||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.example.hpostesting.presentation.testRight
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
@@ -26,7 +27,6 @@ import com.example.hpostesting.domain.TestRightResultCalculation
|
|||||||
import com.example.hpostesting.util.MyUtils
|
import com.example.hpostesting.util.MyUtils
|
||||||
import com.google.firebase.storage.FirebaseStorage
|
import com.google.firebase.storage.FirebaseStorage
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.scopes.ViewModelScoped
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -39,16 +39,14 @@ import kotlin.math.log10
|
|||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@ViewModelScoped
|
|
||||||
class TestRightViewModel @Inject constructor(
|
class TestRightViewModel @Inject constructor(
|
||||||
private val saveRawData: SaveRawData,
|
private val saveRawData: SaveRawData,
|
||||||
private val saveRawDataTest: SaveRawDataTest,
|
private val saveRawDataTest: SaveRawDataTest,
|
||||||
private val repository: DatabaseRepository,
|
private val repository: DatabaseRepository,
|
||||||
private val userDao: UserDao,
|
private val userDao: UserDao,
|
||||||
context: Context?
|
context: Context
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
|
|
||||||
@@ -57,10 +55,10 @@ class TestRightViewModel @Inject constructor(
|
|||||||
|
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
|
|
||||||
var testDetails = DataHolder.selectedTest
|
val testDetails = DataHolder.selectedTest
|
||||||
|
|
||||||
private val _networkStatusLiveData = context?.let { NetworkStatusLiveData(it) }
|
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
val networkStatusLiveData: NetworkStatusLiveData?
|
val networkStatusLiveData: LiveData<Boolean>
|
||||||
get() = _networkStatusLiveData
|
get() = _networkStatusLiveData
|
||||||
|
|
||||||
val allUserData = userDao.getAll()
|
val allUserData = userDao.getAll()
|
||||||
@@ -442,7 +440,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
).format(Calendar.getInstance().time)
|
).format(Calendar.getInstance().time)
|
||||||
when (repository.addTestToDatabase(testDetails)) {
|
when (repository.addTestToDatabase(testDetails)) {
|
||||||
is Response.Success<*> -> {
|
is Response.Success -> {
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,8 +449,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean, deviceSerialNumber: String) =
|
fun uploadResultToDatabase(context: Context, isOnline: Boolean,deviceSerialNumber: String) = viewModelScope.launch {
|
||||||
viewModelScope.launch {
|
|
||||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||||
testDetails?.csvPath = csvFilePath
|
testDetails?.csvPath = csvFilePath
|
||||||
@@ -467,8 +464,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
||||||
|
|
||||||
val csvUploadTask =
|
val csvUploadTask =
|
||||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!)
|
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!).putFile(csvFileUri)
|
||||||
.putFile(csvFileUri)
|
|
||||||
.await()
|
.await()
|
||||||
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
||||||
.putFile(logTxtFileUri).await()
|
.putFile(logTxtFileUri).await()
|
||||||
@@ -524,7 +520,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
).format(Calendar.getInstance().time)
|
).format(Calendar.getInstance().time)
|
||||||
when (repository.addTestToDatabase(userData)) {
|
when (repository.addTestToDatabase(userData)) {
|
||||||
is Response.Success<*> -> {
|
is Response.Success -> {
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/cl_parent"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.Toolbar-->
|
|
||||||
<!-- android:id="@+id/my_toolbar"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="?attr/actionBarSize"-->
|
|
||||||
<!-- android:background="?attr/colorPrimary"-->
|
|
||||||
<!-- app:titleTextColor="#FFFFFF"-->
|
|
||||||
<!-- android:elevation="4dp"-->
|
|
||||||
<!-- app:menu="@menu/my_menu"-->
|
|
||||||
<!-- android:theme="@style/ToolbarTheme"-->
|
|
||||||
<!-- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"-->
|
|
||||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
|
||||||
<!-- app:layout_constraintTop_toTopOf="parent"/>-->
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/fg_diagnostics"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
tools:context=".presentation.diagnostics.DiagnosticsActivity">
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</layout>
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context="com.example.hpostesting.presentation.diagnostics.DiagnosticsFragment">
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <TextView-->
|
|
||||||
<!-- android:id="@+id/tv_title"-->
|
|
||||||
<!-- style="@style/title1"-->
|
|
||||||
<!-- android:layout_width="wrap_content"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:layout_marginHorizontal="24dp"-->
|
|
||||||
<!-- android:text="@string/diagnostics"-->
|
|
||||||
<!-- android:layout_marginTop="16dp"-->
|
|
||||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
|
||||||
<!-- app:layout_constraintTop_toTopOf="parent" />-->
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_subtitle2"
|
|
||||||
style="@style/title2"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/diagnostics"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_subtitle3"
|
|
||||||
style="@style/title2"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_subtitle4"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="380dp"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="Start"
|
|
||||||
android:textColor="@color/red"
|
|
||||||
android:textSize="22sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle3" />
|
|
||||||
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btn_submit"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:clickable="false"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="Start"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
|
||||||
|
|
||||||
<!-- <Button-->
|
|
||||||
<!-- android:id="@+id/btn_read"-->
|
|
||||||
<!-- android:layout_width="wrap_content"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:text="@string/read"-->
|
|
||||||
<!-- android:layout_margin="16dp"-->
|
|
||||||
<!-- android:clickable="false"-->
|
|
||||||
<!-- app:layout_constraintTop_toBottomOf="@id/btn_set_reference"-->
|
|
||||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
|
||||||
|
|
||||||
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progressBar"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:elevation="12dp"
|
|
||||||
android:indeterminate="true"
|
|
||||||
android:indeterminateDrawable="@drawable/progressbar_drawable"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -21,16 +21,4 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btn_diagnostics"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:clickable="false"
|
|
||||||
android:text="@string/diagnostics"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -44,16 +44,12 @@
|
|||||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:visibility="gone"
|
||||||
android:id="@+id/tv_name"
|
android:id="@+id/tv_name"
|
||||||
style="@style/title2"
|
style="@style/title2"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="24dp"
|
android:layout_marginHorizontal="24dp"
|
||||||
android:gravity="center"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:layout_marginTop="26dp"
|
|
||||||
android:textFontWeight="700"
|
|
||||||
android:text="Name: SMI\n ID: 1672282828"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
tools:ignore="MissingConstraints" />
|
tools:ignore="MissingConstraints" />
|
||||||
@@ -64,7 +60,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="80dp"
|
android:layout_height="80dp"
|
||||||
android:layout_marginHorizontal="24dp"
|
android:layout_marginHorizontal="24dp"
|
||||||
android:layout_marginTop="72dp"
|
android:layout_marginTop="16dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="@color/red"
|
android:textColor="@color/red"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
@@ -163,21 +159,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/error_message"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
android:layout_marginTop="172dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="@color/red"
|
|
||||||
android:textSize="18sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
|
||||||
|
|
||||||
<!-- <com.google.android.material.textfield.TextInputLayout-->
|
<!-- <com.google.android.material.textfield.TextInputLayout-->
|
||||||
<!-- android:id="@+id/til_blood_group"-->
|
<!-- android:id="@+id/til_blood_group"-->
|
||||||
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"-->
|
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"-->
|
||||||
|
|||||||
@@ -112,7 +112,6 @@
|
|||||||
<string name="sickle_cert">Sickle Cert</string>
|
<string name="sickle_cert">Sickle Cert</string>
|
||||||
<string name="sickle_find">Sickle Find</string>
|
<string name="sickle_find">Sickle Find</string>
|
||||||
<string name="submit">Submit</string>
|
<string name="submit">Submit</string>
|
||||||
<string name="diagnostics">Device Diagnostics</string>
|
|
||||||
<string name="place_buffer">Start Buffer</string>
|
<string name="place_buffer">Start Buffer</string>
|
||||||
<string name="Start_Sample">Start Sample</string>
|
<string name="Start_Sample">Start Sample</string>
|
||||||
<string name="new_kit">New Kit</string>
|
<string name="new_kit">New Kit</string>
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.view.View
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
import org.mockito.ArgumentMatchers.any
|
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito.verify
|
|
||||||
import org.mockito.Mockito.`when`
|
|
||||||
import org.mockito.MockitoAnnotations
|
|
||||||
|
|
||||||
class HemocubeViewModelTest {
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockSharedPreferences: SharedPreferences
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
|
||||||
|
|
||||||
private lateinit var hemoCubeFragment: HemoCubeFragment
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this)
|
|
||||||
hemoCubeFragment = HemoCubeFragment()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `handleValidResult with valid input`() {
|
|
||||||
|
|
||||||
val validString = "valid string"
|
|
||||||
val fullReadOutput = "full read output"
|
|
||||||
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
|
||||||
`when`(mockActivity.runOnUiThread(any())).thenAnswer {
|
|
||||||
val runnable = it.getArgument(0, Runnable::class.java)
|
|
||||||
runnable.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Act
|
|
||||||
hemoCubeFragment.handleValidResult(validString, fullReadOutput)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// Add appropriate assertions based on the behavior you expect
|
|
||||||
verify(mockSharedPreferences).edit()
|
|
||||||
verify(mockBinding).btnSubmit.visibility = View.VISIBLE
|
|
||||||
verify(mockBinding).btnSubmit.isEnabled = true
|
|
||||||
// Add more verifications as needed
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Add more test cases for different scenarios if needed
|
|
||||||
}
|
|
||||||
@@ -1,49 +1,17 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.model.PatientData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
import junit.framework.Assert.assertEquals
|
import junit.framework.Assert.assertEquals
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.MockitoAnnotations
|
|
||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
class TestRightViewModelTest {
|
class TestRightViewModelTest {
|
||||||
|
private val viewModel = TestRightViewModel()
|
||||||
@Mock
|
|
||||||
lateinit var mockContext: Context
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
lateinit var mockRepository: DatabaseRepository
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
lateinit var mockSaveRawData: SaveRawData
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
lateinit var mockSaveRawDataTest: SaveRawDataTest
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
lateinit var mockUserDao: UserDao
|
|
||||||
|
|
||||||
lateinit var viewModel: TestRightViewModel<Any?>
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
// Initialize mocks
|
|
||||||
MockitoAnnotations.initMocks(this)
|
|
||||||
|
|
||||||
// Create the ViewModel with mock dependencies
|
|
||||||
viewModel = TestRightViewModel(mockSaveRawData,mockSaveRawDataTest,mockRepository,mockUserDao,mockContext)
|
|
||||||
}
|
|
||||||
private val data = InputData()
|
private val data = InputData()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -95,11 +63,8 @@ class TestRightViewModelTest {
|
|||||||
viewModel.mapDeviceConstants(data.inputRead)
|
viewModel.mapDeviceConstants(data.inputRead)
|
||||||
viewModel.mapPixelNumberToWavelength()
|
viewModel.mapPixelNumberToWavelength()
|
||||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||||
val mapIntensityValues = viewModel.mapIntensityValues(
|
viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
|
||||||
TestDataGenerator().getInputSampleMapIntensityValues(),
|
viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED)
|
||||||
false
|
|
||||||
)
|
|
||||||
viewModel.testDetails = UserData("Surya", "2", "Male")
|
|
||||||
viewModel.mapWavelengthToAbsorbance()
|
viewModel.mapWavelengthToAbsorbance()
|
||||||
|
|
||||||
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.0.2'
|
classpath 'com.android.tools.build:gradle:8.0.2'
|
||||||
classpath 'com.google.gms:google-services:4.4.0'
|
classpath 'com.google.gms:google-services:4.3.15'
|
||||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.0'
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
Reference in New Issue
Block a user