Compare commits
11 Commits
HposUnitTe
...
CrashIssue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0624a8fb5e | ||
|
|
d5553d9a23 | ||
|
|
a54c720d8f | ||
|
|
f183a1dab3 | ||
|
|
281946ffde | ||
|
|
7e32a10186 | ||
|
|
d823821026 | ||
|
|
61e5fbf4a1 | ||
|
|
e5da37064a | ||
|
|
19289a5c33 | ||
|
|
da3a89245e |
43
.idea/misc.xml
generated
Normal file
43
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_auto_graph_24.xml" value="0.1555" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_cancel_24.xml" value="0.1965" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_check_circle_24.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_dot_24.xml" value="0.1785" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_file_download_24.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_home_24.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_new_label_24.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_usb_24.xml" value="0.157" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_usb_off_24.xml" value="0.157" />
|
||||
<entry key="app/src/main/res/drawable/progressbar_drawable.xml" value="0.1885" />
|
||||
<entry key="app/src/main/res/drawable/result_background_green.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/result_background_red.xml" value="0.1785" />
|
||||
<entry key="app/src/main/res/drawable/result_background_tellow.xml" value="0.1785" />
|
||||
<entry key="app/src/main/res/font/inter_bold.xml" value="0.33487179487179486" />
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.165" />
|
||||
<entry key="app/src/main/res/layout/activity_splash.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/activity_test_right.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/fragment_graph.xml" value="0.19791666666666666" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_reference.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_sample.xml" value="0.24583333333333332" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_scanner.xml" value="0.24583333333333332" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_process.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_results.xml" value="0.30512820512820515" />
|
||||
<entry key="app/src/main/res/layout/table_item.xml" value="0.22407407407407406" />
|
||||
<entry key="app/src/main/res/menu/menu.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/menu/my_menu.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/hpos_icon.xml" value="0.1505" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/hpos_icon_round.xml" value="0.1505" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
2
app/.gitignore
vendored
2
app/.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
/build
|
||||
/google-services*
|
||||
/google-services.json
|
||||
/idea
|
||||
@@ -18,8 +18,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 24
|
||||
versionName "2.1.24"
|
||||
versionCode 7
|
||||
versionName "2.1.7"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -60,7 +60,6 @@ dependencies {
|
||||
|
||||
//firebase
|
||||
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-analytics-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-ads-identifier:18.0.1'
|
||||
implementation 'com.google.android.things:androidthings:1.0'
|
||||
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
|
||||
implementation("com.google.firebase:firebase-appdistribution-api-ktx: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-beta10")
|
||||
|
||||
|
||||
// Testing
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
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 'com.opencsv:opencsv:4.6'
|
||||
@@ -98,17 +96,17 @@ dependencies {
|
||||
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
||||
|
||||
//Room
|
||||
implementation "androidx.room:room-ktx:2.6.0-rc01"
|
||||
implementation "androidx.room:room-runtime:2.6.0-rc01"
|
||||
kapt ("androidx.room:room-compiler:2.6.0-rc01")
|
||||
implementation "androidx.room:room-ktx:2.6.0-beta01"
|
||||
implementation "androidx.room:room-runtime:2.6.0-beta01"
|
||||
kapt ("androidx.room:room-compiler:2.6.0-beta01")
|
||||
|
||||
//image
|
||||
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
||||
|
||||
// Navigation Component
|
||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.3"
|
||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.3"
|
||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.2"
|
||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.2"
|
||||
|
||||
//Dagger - Hilt
|
||||
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_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<uses-feature android:name="android.hardware.usb.host" />
|
||||
|
||||
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
||||
|
||||
<application
|
||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||
android:allowBackup="true"
|
||||
@@ -29,9 +26,6 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.HPOSTesting"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
|
||||
android:exported="false"
|
||||
@@ -39,13 +33,6 @@
|
||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity"
|
||||
android:exported="false"
|
||||
android:noHistory="true"
|
||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.KitScanActivity"
|
||||
android:exported="false"
|
||||
|
||||
@@ -47,20 +47,6 @@ object Constants {
|
||||
"HC-V1-004",
|
||||
"HC-V1-005",
|
||||
"HC-V1-006",
|
||||
"HC-V1-007",
|
||||
"HC-V1-008",
|
||||
"HC-V1-009",
|
||||
"HC-V1-010",
|
||||
"HC-V1-011",
|
||||
"HC-V1-012",
|
||||
"HC-V1-013",
|
||||
"HC-V1-014",
|
||||
"HC-V1-015",
|
||||
"HC-V1-016",
|
||||
"HC-V1-017",
|
||||
"HC-V1-018",
|
||||
"HC-V1-019",
|
||||
"HC-V1-020",
|
||||
)
|
||||
|
||||
const val password = "SMI@12345"
|
||||
@@ -69,5 +55,4 @@ object Constants {
|
||||
const val KIT_COUNT = "KitCount"
|
||||
const val BUFFER_VALUE_1 = "BufferValue1"
|
||||
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) {
|
||||
startBuffer("B\r"),
|
||||
runDiagnostics("D\r"),
|
||||
getBuffer("Q\r"),
|
||||
startSample("S\r"),
|
||||
getSample("P\r"),
|
||||
getDeviceId("I\r"),
|
||||
}
|
||||
@@ -20,7 +20,4 @@ interface HemoCubeDao {
|
||||
|
||||
@Query("DELETE FROM hemo_cube_test_table WHERE _id = :id")
|
||||
suspend fun deleteById(id: String)
|
||||
|
||||
@Query("UPDATE hemo_cube_test_table SET localFlag = :newValue WHERE _id = :id")
|
||||
suspend fun updateFieldById(id: String, newValue: Boolean)
|
||||
}
|
||||
@@ -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 = ""
|
||||
)
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
data class BufferCheckData(
|
||||
var kitno: String = "",
|
||||
var deviceId: String? = "",
|
||||
var appVersion:String? = "",
|
||||
var deviceSerialNumber: String = "",
|
||||
var deviceType: String = "HEMOCUBE",
|
||||
var resultData: String = "",
|
||||
var led1Buffer: Double? = null,
|
||||
var led2Buffer: Double? = null,
|
||||
var led1Sample: Double? = null,
|
||||
var led2Sample: Double? = null,
|
||||
var led1Average: Double? = null,
|
||||
var led2Average: Double? = null,
|
||||
var deviceRatio: Double? = null,
|
||||
var calculatedRatio: Double? = null,
|
||||
var coefficients: String? = "",
|
||||
var classificationResult: String = "",
|
||||
var testTime: String = ""
|
||||
)
|
||||
@@ -29,7 +29,5 @@ data class HemoCubeTestData(
|
||||
var led1Average: Double? = null,
|
||||
var led2Average: Double? = null,
|
||||
var deviceRatio: Double? = null,
|
||||
var calculatedRatio: Double? = null,
|
||||
var coefficients: String? = "",
|
||||
var classificationResult: String = ""
|
||||
var calculatedRatio: Double? = null
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ data class UserData(
|
||||
@PrimaryKey
|
||||
var _id: String = "",
|
||||
var name: String = "",
|
||||
var incubationTime: String = "",
|
||||
var birthYear: String = "",
|
||||
var userImageURL: String = "",
|
||||
var location: Location? = null,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,24 @@
|
||||
package com.example.hpostesting.data.repository
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.room.Room
|
||||
import com.example.hpostesting.data.dao.MyDatabase
|
||||
import com.example.hpostesting.data.model.PendingUploads
|
||||
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.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.android.datatransport.runtime.dagger.Provides
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.firebase.storage.ktx.storage
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import javax.inject.Singleton
|
||||
|
||||
class DatabaseRepository : Repository {
|
||||
|
||||
@@ -36,6 +40,7 @@ class DatabaseRepository : Repository {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
||||
return try {
|
||||
val userdata = db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||
@@ -47,30 +52,13 @@ class DatabaseRepository : Repository {
|
||||
db.collection("testData").add(data!!).await()
|
||||
Response.Success(data!!._id)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
||||
return try {
|
||||
db.collection("buffers").add(data!!).await()
|
||||
Response.Success(data!!.kitno)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
try {
|
||||
@@ -79,8 +67,9 @@ class DatabaseRepository : Repository {
|
||||
val riversRef = storage.reference.child("$patientID/${file.lastPathSegment}")
|
||||
riversRef.putFile(file).await()
|
||||
return Response.Success(true)
|
||||
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
e.printStackTrace()
|
||||
return Response.Error(e)
|
||||
}
|
||||
}
|
||||
@@ -92,7 +81,7 @@ class DatabaseRepository : Repository {
|
||||
|
||||
Response.Success(true)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
e.printStackTrace()
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
@@ -111,7 +100,7 @@ class DatabaseRepository : Repository {
|
||||
pendingList
|
||||
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
e.printStackTrace()
|
||||
pendingList
|
||||
}
|
||||
}
|
||||
@@ -122,7 +111,7 @@ class DatabaseRepository : Repository {
|
||||
|
||||
Response.Success(true)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
e.printStackTrace()
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
@@ -131,6 +120,7 @@ class DatabaseRepository : Repository {
|
||||
return db.collection("devices").get().await().toObjects(DeviceData::class.java)
|
||||
}
|
||||
|
||||
|
||||
suspend fun getDeviceDataById(deviceId: String): DeviceData? {
|
||||
val querySnapshot = db.collection("devices").get().await()
|
||||
val allDeviceDataList = querySnapshot.toObjects(DeviceData::class.java)
|
||||
@@ -139,7 +129,6 @@ class DatabaseRepository : Repository {
|
||||
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
|
||||
|
||||
interface Repository {
|
||||
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
||||
// 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.constant.Constants
|
||||
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.testRight.TestRightActivity
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
@@ -109,33 +108,7 @@ class KitScanActivity : AppCompatActivity() {
|
||||
|
||||
binding.btnGo.setOnClickListener {
|
||||
val serialNumber = binding.nameEditText.text.toString().trim()
|
||||
if (serialNumber.isNotEmpty() && isSerialValid(serialNumber)) {
|
||||
if (DataHolder.selectedTest == null) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(
|
||||
Constants.KIT_NUMBER, binding.nameEditText.text.toString()
|
||||
)
|
||||
putInt(Constants.KIT_COUNT, 1)
|
||||
apply()
|
||||
}
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
"Kit number is updated, Please Select user before starting test",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
val i = Intent(applicationContext, DashboardActivity::class.java)
|
||||
startActivity(i)
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(
|
||||
serialNumber
|
||||
)
|
||||
) {
|
||||
if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) {
|
||||
DataHolder.kitSerial = binding.nameEditText.text.toString()
|
||||
DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString()
|
||||
with(sharedPreference.edit()) {
|
||||
@@ -152,9 +125,8 @@ class KitScanActivity : AppCompatActivity() {
|
||||
|
||||
private fun checkHemoCubeKitData(): Boolean {
|
||||
return sharedPreference.getString(Constants.KIT_NUMBER, "")
|
||||
?.isNotBlank() == true && sharedPreference.getInt(
|
||||
Constants.KIT_COUNT, 0
|
||||
) > 0 && sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
|
||||
?.isNotBlank() == true && sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0
|
||||
&& sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
|
||||
}
|
||||
|
||||
private fun isSerialValid(s: String): Boolean {
|
||||
|
||||
@@ -90,6 +90,18 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivity(Intent(this, DashboardActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
// val crashButton = Button(this)
|
||||
// crashButton.text = "Test Crash"
|
||||
// crashButton.setOnClickListener {
|
||||
// throw RuntimeException("Test Crash") // Force a crash
|
||||
// }
|
||||
//
|
||||
// addContentView(crashButton, ViewGroup.LayoutParams(
|
||||
// ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
// ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
|
||||
}
|
||||
|
||||
private fun checkAndUpdateUsbConnection() {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.example.hpostesting.presentation.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Context.INPUT_METHOD_SERVICE
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -14,30 +10,17 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.UserItemViewBinding
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import android.widget.AutoCompleteTextView
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
|
||||
class UserListAdapter(
|
||||
|
||||
private val context: Context,
|
||||
private val hemoCubeViewModel: HemoCubeViewModel,
|
||||
options: FirestoreRecyclerOptions<UserData>,
|
||||
private val view: View,
|
||||
private val batLevel: Int,
|
||||
private val requireActivity: FragmentActivity
|
||||
) : FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
||||
private val view: View
|
||||
) :
|
||||
FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
||||
|
||||
class OrderItemViewHolder(val binding: UserItemViewBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
@@ -53,21 +36,6 @@ class UserListAdapter(
|
||||
holder.binding.apply {
|
||||
userName.text = "Name: ${model.name}"
|
||||
userId.text = "User ID:${model._id}"
|
||||
if (model.incubationTime == "") {
|
||||
btnBlood.visibility = View.VISIBLE
|
||||
} else {
|
||||
userId.text =
|
||||
"User ID:${model._id} \n Time: ${isBetween15And30Minutes(model.incubationTime)} \n Started at: ${
|
||||
SimpleDateFormat("HH:mm:ss").format(
|
||||
SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).parse(model.incubationTime)!!
|
||||
)
|
||||
}"
|
||||
btnBlood.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
||||
Glide.with(view).load(model.userImageURL).into(userImage)
|
||||
if (model.testStatus!!) {
|
||||
teststatus.text = "Test concluded"
|
||||
@@ -75,129 +43,7 @@ class UserListAdapter(
|
||||
} else {
|
||||
teststatus.text = "Test is Pending"
|
||||
}
|
||||
|
||||
holder.binding.btnBlood.setOnClickListener {
|
||||
val view: View? = requireActivity.currentFocus
|
||||
|
||||
// on below line checking if view is not null.
|
||||
if (view != null) {
|
||||
// on below line we are creating a variable
|
||||
// for input manager and initializing it.
|
||||
val inputMethodManager =
|
||||
context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
// on below line hiding our keyboard.
|
||||
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val dialogView = inflater.inflate(R.layout.dialog_custom, null)
|
||||
|
||||
val builder = AlertDialog.Builder(context)
|
||||
.setView(dialogView)
|
||||
.setTitle("Add Blood Group")
|
||||
|
||||
val etBloodGroup = dialogView.findViewById<AutoCompleteTextView>(R.id.et_blood_group)
|
||||
|
||||
builder.setPositiveButton("OK") { dialog, which ->
|
||||
val bloodGroup = etBloodGroup.text.toString()
|
||||
if (bloodGroup.equals("Select Blood Group") || bloodGroup.isNullOrBlank()) {
|
||||
etBloodGroup.error = "Please enter your blood group"
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Please enter your blood group",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
// Check if hemoCubeViewModel and testDetails are not null
|
||||
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
|
||||
|
||||
db.collection("patientData")
|
||||
.whereEqualTo("_id", model._id)
|
||||
.get()
|
||||
.addOnSuccessListener { userdata ->
|
||||
try {
|
||||
val document = userdata.documents[0]
|
||||
db.collection("patientData")
|
||||
.document(document.id)
|
||||
.update("bloodGroup", bloodGroup,
|
||||
"incubationTime", SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time).toString()
|
||||
)
|
||||
.addOnSuccessListener {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Blood group updated successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
btnBlood.visibility = View.GONE
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Failed to update blood group: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
// Handle the case where no documents are found for the specified ID
|
||||
Toast.makeText(
|
||||
context,
|
||||
"No user data found for the specified ID",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Error fetching user data: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
// Handle the selected blood group here
|
||||
}
|
||||
|
||||
builder.setNegativeButton("Cancel") { dialog, which ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = builder.create()
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
btnStartIncubation.setOnClickListener {
|
||||
// it.visibility = View.GONE
|
||||
// Firebase.firestore.collection("patientData").whereEqualTo("_id", model._id).get()
|
||||
// .addOnSuccessListener { data ->
|
||||
// if (data.documents.isNotEmpty()) {
|
||||
// data.documents.forEach { userData ->
|
||||
// Firebase.firestore.collection("patientData").document(userData.id)
|
||||
// .update(
|
||||
// "incubationTime", SimpleDateFormat(
|
||||
// "yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
// ).format(Calendar.getInstance().time).toString()
|
||||
// ).addOnSuccessListener {
|
||||
// Toast.makeText(
|
||||
// view.context, "Incubation started", Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// startListening()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
userCard.setOnClickListener {
|
||||
if (batLevel < 40) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Battery level is low than 40%, please charge the device to continue testing",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (model.testStatus != null) {
|
||||
if (model.testStatus!!) {
|
||||
Toast.makeText(
|
||||
@@ -206,47 +52,11 @@ class UserListAdapter(
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
if (model.incubationTime != "") {
|
||||
if (isBetween15And30Minutes(model.incubationTime) < 15) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation has not completed 15 minutes",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else if (isBetween15And30Minutes(model.incubationTime) > 30) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation crossed 30 minutes, need to repeat the incubation",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
DataHolder.selectedTest = model
|
||||
view.findNavController()
|
||||
.navigate(R.id.action_nav_home_to_mainActivity)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation not started for this user",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
DataHolder.selectedTest = model
|
||||
view.findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun isBetween15And30Minutes(createdAt: String): Long {
|
||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
val createdAtDate: Date = formatter.parse(createdAt)!!
|
||||
|
||||
val currentTime = Calendar.getInstance().time
|
||||
|
||||
val diffMillis = currentTime.time - createdAtDate.time
|
||||
|
||||
return diffMillis / (60 * 1000)
|
||||
}
|
||||
}
|
||||
@@ -1,354 +0,0 @@
|
||||
package com.example.hpostesting.presentation.buffercheck
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
import kotlin.math.log10
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class HemoCubeBufferCheckFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentHemoCubeReferenceBinding
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var resultData: String = ""
|
||||
private var kitno: String = ""
|
||||
private var isOnline = false
|
||||
private val messages = MutableLiveData<String>()
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData(false)
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
): View {
|
||||
binding = FragmentHemoCubeReferenceBinding.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.nameEditText.setText("SMI/SC/")
|
||||
binding.tvTitle.visibility = View.GONE
|
||||
binding.tvName.visibility = View.GONE
|
||||
|
||||
binding.btnGo.setOnClickListener {
|
||||
val serialNumber = binding.nameEditText.text.toString().trim()
|
||||
if (serialNumber.isNotEmpty() && isSerialValid(serialNumber)) {
|
||||
kitno = serialNumber
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
} else {
|
||||
Toast.makeText(context, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle2.visibility = View.GONE
|
||||
binding.etAbhaId.visibility = View.GONE
|
||||
binding.tvTitle.visibility = View.GONE
|
||||
binding.tvTitle2.visibility = View.GONE
|
||||
binding.btnGo.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
}
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
|
||||
}
|
||||
binding.btnSubmit.isEnabled = false
|
||||
binding.btnSubmit.isClickable = false
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||
currentDeviceData = it
|
||||
}
|
||||
|
||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
if (isNetworkAvailable) {
|
||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(), "No internet connection avaiable", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast("Kit result uploaded successfully")
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast("Kit result uploading failed, note it down manually")
|
||||
}
|
||||
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
messages.observe(viewLifecycleOwner) {
|
||||
binding.tvSubtitle4.text = it
|
||||
}
|
||||
}
|
||||
|
||||
private fun listenToHemoCube() {
|
||||
if (DataHolder.hemoCubeTestData == null) {
|
||||
DataHolder.hemoCubeTestData = DataHolder.selectedTest?.toHemoCubeTestData()
|
||||
}
|
||||
|
||||
val fullReadOutput = StringBuilder()
|
||||
startListening.postValue(true)
|
||||
|
||||
try {
|
||||
(activity as HemocubeBufferCheckActivity).mService.listenToHemoCube(object :
|
||||
UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
data?.let {
|
||||
val stringData = String(it)
|
||||
fullReadOutput.append(stringData)
|
||||
handleUsbData(stringData, fullReadOutput)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
}
|
||||
})
|
||||
} catch (e: Exception) {
|
||||
showToast("test is going on")
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
||||
if (stringData.contains("#")) {
|
||||
messages.postValue(stringData)
|
||||
isTestOngoing = true
|
||||
}
|
||||
|
||||
resultData += fullReadOutput.toString()
|
||||
|
||||
when {
|
||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||
stringData.contains("#Sample Completed") -> {
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
}
|
||||
fetchResult()
|
||||
}
|
||||
|
||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||
var validString: String
|
||||
val results: List<String>
|
||||
if (stringData.contains("RESULT")) {
|
||||
validString = isValidResult(stringData)
|
||||
if (validString.isEmpty()) {
|
||||
results = resultData.split("\n")
|
||||
validString = parseResult(results)
|
||||
}
|
||||
} else {
|
||||
results = resultData.split("\n")
|
||||
validString = parseResult(results)
|
||||
}
|
||||
if (validString.isNotEmpty()) {
|
||||
handleValidResult(validString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showStartSampleDialog() {
|
||||
activity?.runOnUiThread {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"Start Sample",
|
||||
"Do you want to start sample reading?",
|
||||
getString(R.string.no),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startSampleProcess()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleValidResult(validString: String) {
|
||||
try {
|
||||
val result = validString.split(" ")
|
||||
if (result.size == 8) {
|
||||
val deviceId = result[2]
|
||||
val led1BufferForDevice = result[3].toDoubleOrNull()
|
||||
val led2BufferForDevice = result[4].toDoubleOrNull()
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
val led2Sample = result[6].toDoubleOrNull()
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
val calculateRatio = calculateRatio(deviceRatio)
|
||||
val classificationResult = findResult(calculateRatio)
|
||||
messages.postValue(classificationResult)
|
||||
val bufferData = BufferCheckData(
|
||||
deviceId= deviceId,
|
||||
kitno = kitno,
|
||||
led1Buffer = led1BufferForDevice,
|
||||
led2Buffer = led2BufferForDevice,
|
||||
led1Average = led1Average,
|
||||
led2Average = led2Average,
|
||||
led1Sample = led1Sample,
|
||||
led2Sample = led2Sample,
|
||||
deviceRatio = deviceRatio,
|
||||
calculatedRatio = calculateRatio,
|
||||
coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString(),
|
||||
classificationResult = classificationResult,
|
||||
deviceSerialNumber = sharedPreferences.getString(Constants.USER_ID, "").toString(),
|
||||
testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
)
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabaseforbuffercheckN(bufferData)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(
|
||||
requireContext(), "Error while processing device data", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findResult(calculatedRatio: Double?): String {
|
||||
try {
|
||||
if (calculatedRatio != null) {
|
||||
if (calculatedRatio < 0.085) return "Kit Failed"
|
||||
if (calculatedRatio in 0.085..0.155) return "Kit Passed"
|
||||
if (calculatedRatio in 0.155..0.175) return "Kit Failed"
|
||||
if (calculatedRatio in 0.175..0.22) return "Kit Failed"
|
||||
if (calculatedRatio in 0.22..0.25) return "Kit Failed"
|
||||
if (calculatedRatio in 0.25..0.35) return "Kit Failed"
|
||||
if (calculatedRatio > 0.35) return "Kit Failed"
|
||||
} else {
|
||||
return "NULL"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showToast("error while performing classification")
|
||||
Firebase.crashlytics.recordException(e)
|
||||
return "ERROR"
|
||||
}
|
||||
return "NULL"
|
||||
}
|
||||
|
||||
private fun showToast(message: String) {
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun startBufferProcess() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun startSampleProcess() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun fetchResult() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun calculateRatio(ratio: Double): Double {
|
||||
val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
|
||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 1.0
|
||||
return coefficient1 * ratio + coefficient2
|
||||
}
|
||||
|
||||
private fun parseResult(frames: List<String>): String {
|
||||
val lines = mutableListOf<String>()
|
||||
for (frame in frames.reversed()) {
|
||||
if (frame.contains("REND") || frame.contains("RESULT")) lines += frame
|
||||
if (frame.contains("RESULT")) {
|
||||
break
|
||||
}
|
||||
}
|
||||
val line = lines.reversed().joinToString("").trim()
|
||||
if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||
return line
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun isSerialValid(s: String): Boolean {
|
||||
if (s.length != 17) {
|
||||
binding.nameEditText.error = getString(R.string.invalid_kit)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
private fun isValidResult(line: String): String {
|
||||
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||
line
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
package com.example.hpostesting.presentation.buffercheck
|
||||
|
||||
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 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.appcompat.app.AppCompatActivity
|
||||
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.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.ActivityHemocubeBinding
|
||||
|
||||
@AndroidEntryPoint
|
||||
open class HemocubeBufferCheckActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityHemocubeBinding
|
||||
private val viewModel by viewModels<HemoCubeViewModel>()
|
||||
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 {
|
||||
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 = ActivityHemocubeBinding.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()) {
|
||||
Toast.makeText(this, "No device found", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
mDriver = availableDrivers[0]
|
||||
mConnection = manager.openDevice(mDriver.device)
|
||||
|
||||
if (mConnection == null) {
|
||||
requestUserPermission(manager, mDriver.device)
|
||||
} else {
|
||||
setupService()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
||||
private fun setupService() {
|
||||
val intent = Intent(this, UsbService::class.java)
|
||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
|
||||
private fun moveToNext() {
|
||||
if (supportFragmentManager.isDestroyed) return
|
||||
|
||||
supportFragmentManager.beginTransaction().replace(binding.fghemocube.id, HemoCubeBufferCheckFragment())
|
||||
.commit()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,6 @@ import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.firebase.appdistribution.FirebaseAppDistribution
|
||||
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
//import com.google.firebase.appdistribution.FirebaseAppDistribution
|
||||
//import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||
@@ -62,18 +58,12 @@ class DashboardActivity : AppCompatActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Copy and paste this into any part of your app - for example, in your main
|
||||
// activity's onResume method.
|
||||
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
|
||||
firebaseAppDistribution.updateIfNewReleaseAvailable()
|
||||
.addOnProgressListener { updateProgress ->
|
||||
|
||||
if (updateProgress.apkBytesDownloaded > 0) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
"${updateProgress.updateStatus}. ${updateProgress.apkBytesDownloaded / 1048576} /${updateProgress.apkFileTotalBytes / 1048576} MB",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
Toast.makeText(this, "Updating", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
// (Optional) Handle errors.
|
||||
@@ -85,18 +75,11 @@ class DashboardActivity : AppCompatActivity() {
|
||||
|
||||
else -> {
|
||||
// Handle other errors.
|
||||
Toast.makeText(
|
||||
this,
|
||||
"AppDistribution error, status: ${e.errorCode}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
FirebaseCrashlytics.getInstance().recordException(e)
|
||||
}
|
||||
}
|
||||
.addOnSuccessListener {
|
||||
// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity
|
||||
import com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
//import com.example.hpostesting.presentation.dashboard.ui.gallery.GalleryViewModel
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding
|
||||
|
||||
class GalleryFragment : Fragment() {
|
||||
@@ -33,15 +32,6 @@ class GalleryFragment : Fragment() {
|
||||
// galleryViewModel.text.observe(viewLifecycleOwner) {
|
||||
//// textView.text = it
|
||||
// }
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
|
||||
}
|
||||
|
||||
binding.btnDiagnostics.setOnClickListener {
|
||||
startActivity(Intent(requireContext(), DiagnosticsActivity::class.java))
|
||||
}
|
||||
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@ package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Context.BATTERY_SERVICE
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.BatteryManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -19,33 +16,25 @@ 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 com.example.hpostesting.presentation.KitScanActivity
|
||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.firestore.Query
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.firebase.perf.ktx.performance
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : Fragment() {
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
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 lateinit var rvAdapter: UserListAdapter
|
||||
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
@@ -59,16 +48,17 @@ class HomeFragment : Fragment() {
|
||||
return super.onCreateView(inflater, container, savedInstanceState)
|
||||
}
|
||||
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
DataHolder.selectedTest = null
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
if (userData.isNotEmpty()) {
|
||||
|
||||
}
|
||||
deleteIncompleteRegistrations(userData)
|
||||
}
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
@@ -87,36 +77,13 @@ class HomeFragment : Fragment() {
|
||||
setUserId()
|
||||
}
|
||||
}
|
||||
hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Test Results Uploaded Successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
if (result == "Error") {
|
||||
Toast.makeText(requireContext(), "Test Results Upload Failed", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
binding.btnLogout.setOnClickListener {
|
||||
logoutUser(requireContext())
|
||||
}
|
||||
binding.uploadData.setOnClickListener {
|
||||
showUploadDialog(requireContext())
|
||||
}
|
||||
binding.btnNewKit.setOnClickListener {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.KIT_NUMBER, "")
|
||||
putInt(Constants.KIT_COUNT, 0)
|
||||
apply()
|
||||
}
|
||||
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUserId() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val userId = binding.userId.text.toString()
|
||||
@@ -131,49 +98,29 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadUserData() {
|
||||
try {
|
||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
||||
val currentDate = Date()
|
||||
val formattedDate = dateFormat.format(currentDate)
|
||||
val query = Firebase.firestore.collection("patientData")
|
||||
.whereGreaterThanOrEqualTo("createdAt", formattedDate)
|
||||
.orderBy("createdAt", Query.Direction.DESCENDING)
|
||||
// val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false)
|
||||
query.get().addOnSuccessListener {
|
||||
if (it.documents.isEmpty()) {
|
||||
binding.pendingTest.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.pendingTest.visibility = View.GONE
|
||||
}
|
||||
// val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false).orderBy("createdAt", Query.Direction.DESCENDING)
|
||||
val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false)
|
||||
query.get().addOnSuccessListener {
|
||||
if (it.documents.isEmpty()) {
|
||||
binding.pendingTest.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.pendingTest.visibility = View.GONE
|
||||
}
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||
it, batLevel, requireActivity())
|
||||
}!!
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
|
||||
rvAdapter.startListening()
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
}
|
||||
|
||||
private fun saveUserId(userId: String) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.USER_ID, userId)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
private fun logoutUser(context: Context) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle("Log Out")
|
||||
@@ -190,42 +137,22 @@ class HomeFragment : Fragment() {
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun getData(search: String?, field: String) {
|
||||
val userSearchTrace = Firebase.performance.newTrace("user_search_trace")
|
||||
userSearchTrace.start()
|
||||
|
||||
search?.replaceFirstChar {
|
||||
val capitalizedSearch = search?.replaceFirstChar {
|
||||
if (search.lowercase()
|
||||
.startsWith(it.lowercase())
|
||||
) it.titlecase(Locale.getDefault()) else it.toString()
|
||||
|
||||
}
|
||||
val currentDate = Date()
|
||||
val dateFormat = SimpleDateFormat("yyyyMMdd")
|
||||
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 query = Firebase.firestore.collection("patientData").orderBy(field).startAt(search)
|
||||
.endAt(search + "\uf8ff")
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel, requireActivity())
|
||||
}!!
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
|
||||
userSearchTrace.stop()
|
||||
}
|
||||
|
||||
private fun setSearch() {
|
||||
binding.searchProduct.setOnQueryTextListener(object :
|
||||
androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||
@@ -246,7 +173,6 @@ class HomeFragment : Fragment() {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(query: String?): Boolean {
|
||||
return if (!query.isNullOrEmpty()) {
|
||||
val field = when {
|
||||
@@ -264,7 +190,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun checkForLocalDBData() {
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility = if (userDataList.isEmpty()) View.GONE else View.VISIBLE
|
||||
@@ -272,11 +197,10 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility = if (userDataList.any { !it.localFlag }) View.VISIBLE else View.GONE
|
||||
val uploadDataVisibility = if (userDataList.isEmpty()) View.GONE else View.VISIBLE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
}
|
||||
|
||||
private fun showUploadDialog(context: Context) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.upload_db_registration_title)
|
||||
@@ -305,19 +229,28 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
dialog.dismiss()
|
||||
Toast.makeText(
|
||||
requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT
|
||||
requireContext(),
|
||||
R.string.upload_success_message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.localFlag) {
|
||||
if (userDataList.isEmpty()) {
|
||||
dialog.dismiss()
|
||||
} else {
|
||||
userDataList.forEach { userData ->
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
dialog.dismiss()
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.upload_success_message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,9 +3,7 @@ package com.example.hpostesting.presentation.hemocube
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -13,20 +11,28 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.KitScanActivity
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
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.perf.ktx.performance
|
||||
import `in`.sminnovations.hpostesting.BuildConfig
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.log10
|
||||
|
||||
class HemoCubeFragment : Fragment() {
|
||||
@@ -34,17 +40,14 @@ class HemoCubeFragment : Fragment() {
|
||||
private lateinit var binding: FragmentHemoCubeReferenceBinding
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
||||
private var isOnline = false
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var resultData: String = ""
|
||||
private var isUsingExistingBuffer = false
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData<Boolean>(false)
|
||||
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = FragmentHemoCubeReferenceBinding.inflate(inflater, container, false)
|
||||
sharedPreferences =
|
||||
@@ -56,55 +59,108 @@ class HemoCubeFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initViews()
|
||||
observeViewModel()
|
||||
checkAndStartProcess()
|
||||
// checkAndStartProcess()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
activity?.runOnUiThread {
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||
if (bloodGroupText.isEmpty()) {
|
||||
binding.etBloodGroup.error = "Please enter your blood group"
|
||||
} else {
|
||||
fetchResult()
|
||||
}
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||
)
|
||||
}
|
||||
if (isTestOngoing) {
|
||||
// binding.btnKit.visibility = View.GONE
|
||||
// binding.btnKit.isEnabled = false
|
||||
// binding.btnKit.isClickable = false
|
||||
}
|
||||
binding.btnKit.visibility = View.GONE
|
||||
binding.btnKit.isEnabled = 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.isClickable = false
|
||||
|
||||
|
||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||
Log.e("nametext", binding.tvName.text.toString())
|
||||
binding.btnSamplestart.setOnClickListener {
|
||||
startSampleProcess()
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
|
||||
binding.btnPlacebuffer.setOnClickListener {
|
||||
checkAndStartProcess()
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
|
||||
binding.btnKit.setOnClickListener {
|
||||
if (isTestOngoing) {
|
||||
val title = "WARNING"
|
||||
val message =
|
||||
"There is a on going test, do you want to stop it. if Yes please disconnect the device and connect it again, once you reached to kitDetails Screen"
|
||||
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() {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast("Test Results Uploaded Successfully")
|
||||
val i = Intent(
|
||||
requireContext().applicationContext, DashboardActivity::class.java
|
||||
)
|
||||
startActivity(i)
|
||||
(activity as HemocubeActivity).finish()
|
||||
lifecycleScope.launch {
|
||||
checkBloodGroup()
|
||||
}
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast("Internet not available, test details stored locally")
|
||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||
}
|
||||
if (result == "Error") {
|
||||
showToast("Error uploading data, test details stored locally")
|
||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||
}
|
||||
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
@@ -113,49 +169,42 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||
currentDeviceData = it
|
||||
// showToast(calculateRatio(0.17).toString())
|
||||
|
||||
}
|
||||
|
||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
apply {
|
||||
DataHolder.hemoCubeTestData?.let {
|
||||
currentDeviceData?.coefficients?.let { coefficients ->
|
||||
val coefficient1 = coefficients[0]
|
||||
val coefficient2 = coefficients[1]
|
||||
val result = coefficient1 * coefficient2
|
||||
}
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
|
||||
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
||||
binding.tvSubtitle4.text = it
|
||||
}
|
||||
// startListening.observe(viewLifecycleOwner) {
|
||||
// if (it) {
|
||||
// lifecycleScope.launch {
|
||||
// delay(1000)
|
||||
// if (binding.tvSubtitle4.text.toString().isEmpty()) {
|
||||
// (activity as HemocubeActivity).reconnectDevice()
|
||||
// if (isBufferValueAvailable()) {
|
||||
// showBufferAlertDialog()
|
||||
// } else {
|
||||
// listenToHemoCube()
|
||||
// startBufferProcess()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
startListening.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
lifecycleScope.launch {
|
||||
delay(1000)
|
||||
if (binding.tvSubtitle4.text.toString().isEmpty()) {
|
||||
(activity as HemocubeActivity).reconnectDevice()
|
||||
if (isBufferValueAvailable()) {
|
||||
showBufferAlertDialog()
|
||||
} else {
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAndStartProcess() {
|
||||
if (isBufferValueAvailable()) {
|
||||
showBufferAlertDialog()
|
||||
} else {
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
}
|
||||
// if (isBufferValueAvailable()) {
|
||||
// showBufferAlertDialog()
|
||||
// } else {
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun isBufferValueAvailable(): Boolean {
|
||||
@@ -222,7 +271,6 @@ class HemoCubeFragment : Fragment() {
|
||||
})
|
||||
} catch (e: Exception) {
|
||||
showToast("test is going on")
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,13 +280,22 @@ class HemoCubeFragment : Fragment() {
|
||||
isTestOngoing = true
|
||||
}
|
||||
|
||||
resultData += stringData
|
||||
resultData += fullReadOutput.toString()
|
||||
|
||||
when {
|
||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||
stringData.contains("ERROR 500") -> showError500Dialog()
|
||||
stringData.contains("ERROR 501") -> showError501Dialog()
|
||||
stringData.contains("#Buffer Completed") ->
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSamplestart.visibility = View.VISIBLE
|
||||
binding.btnSamplestart.isClickable = true
|
||||
}
|
||||
|
||||
stringData.contains("#Sample Completed") -> {
|
||||
fetchResult()
|
||||
testingTrace.stop()
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
}
|
||||
}
|
||||
|
||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||
@@ -279,6 +336,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() {
|
||||
if (isTestOngoing) {
|
||||
// If the test is ongoing, don't allow the back button action
|
||||
@@ -291,6 +365,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() {
|
||||
activity?.runOnUiThread {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
@@ -302,30 +393,17 @@ class HemoCubeFragment : Fragment() {
|
||||
override fun onClickNegativeButton() {}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startSampleProcess()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||
try {
|
||||
val result = validString.split(" ")
|
||||
val deviceLog = resultData
|
||||
if (result.size == 8) {
|
||||
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) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
||||
} else {
|
||||
@@ -336,10 +414,7 @@ class HemoCubeFragment : Fragment() {
|
||||
} else {
|
||||
result[4].toDoubleOrNull()
|
||||
}
|
||||
val pInfo = requireActivity().packageManager.getPackageInfo(
|
||||
requireActivity().packageName, 0
|
||||
)
|
||||
val version = pInfo.versionName
|
||||
val version = BuildConfig.VERSION_NAME
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
val led2Sample = result[6].toDoubleOrNull()
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
@@ -354,14 +429,6 @@ 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 {
|
||||
deviceId = deviceSerialNo
|
||||
led1Buffer = led1BufferForDevice
|
||||
@@ -372,12 +439,9 @@ class HemoCubeFragment : Fragment() {
|
||||
this.led1Average = led1Average
|
||||
this.led2Average = led2Average
|
||||
this.deviceRatio = deviceRatio
|
||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||
this.classificationResult = findResult(calculatedRatio)
|
||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||
this.resultData = deviceLog
|
||||
if (!isUsingExistingBuffer) {
|
||||
// this.calculatedRatio = calculateRatio(deviceRatio)
|
||||
this.resultData = fullReadOutput
|
||||
if (!isBufferValueAvailable()) {
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
||||
putString(Constants.BUFFER_VALUE_2, led2Buffer.toString())
|
||||
@@ -385,49 +449,22 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
} catch (_: Exception) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Error while processing device data",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findResult(calculatedRatio: Double?): String {
|
||||
try {
|
||||
if (calculatedRatio != null) {
|
||||
if (calculatedRatio < 0.05)
|
||||
return "Inconclusive. Very low Absorbance - Repeat test with Higher Blood Volume"
|
||||
if (calculatedRatio in 0.05..0.155)
|
||||
return "Normal"
|
||||
if (calculatedRatio in 0.155..0.175)
|
||||
return "Negative Borderline. Repeat Test"
|
||||
if (calculatedRatio in 0.175..0.22)
|
||||
return "Sickle Cell Trait"
|
||||
if (calculatedRatio in 0.22..0.25)
|
||||
return "Positive for Sickle Cell. HPLC for Confirmation"
|
||||
if (calculatedRatio in 0.25..0.35)
|
||||
return "Sickle Cell Disease"
|
||||
if (calculatedRatio > 0.35)
|
||||
return "Inconclusive. Repeat with test with lower volume of blood"
|
||||
} else {
|
||||
return "NULL"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showToast("error while performing classification")
|
||||
Firebase.crashlytics.recordException(e)
|
||||
return "ERROR"
|
||||
}
|
||||
return "NULL"
|
||||
}
|
||||
|
||||
private fun showToast(message: String) {
|
||||
@@ -448,7 +485,6 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun startSampleProcess() {
|
||||
testingTrace.start()
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||
@@ -474,11 +510,11 @@ class HemoCubeFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun calculateRatio(ratio: Double): Double {
|
||||
val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
|
||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
||||
return coefficient1 * ratio + coefficient2
|
||||
}
|
||||
// private fun calculateRatio(ratio: Double): Double {
|
||||
// val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
|
||||
// val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
||||
// return coefficient1 * ratio + coefficient2
|
||||
// }
|
||||
|
||||
private fun parseResult(frames: List<String>): String {
|
||||
val lines = mutableListOf<String>()
|
||||
@@ -503,9 +539,11 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
||||
return true
|
||||
return false
|
||||
private fun resetKitCount() {
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.KIT_NUMBER, "")
|
||||
putInt(Constants.KIT_COUNT, 0)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ 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.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
@@ -45,7 +44,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
val networkStatusLiveData: LiveData<Boolean>
|
||||
get() = _networkStatusLiveData
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
val fireBaseBulkUpload = MutableLiveData<String>()
|
||||
fun uploadHemoCubeResultToDatabase(isOnline: Boolean, testStatus: Boolean, kitSerial: String?) =
|
||||
viewModelScope.launch {
|
||||
if (kitSerial != null) {
|
||||
@@ -70,13 +68,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun uploadHemoCubeResultToDatabaseforbuffercheckN(bufferCheckData: BufferCheckData) =
|
||||
viewModelScope.launch {
|
||||
addResultTestToDbforbuffercheck(bufferCheckData)
|
||||
}
|
||||
|
||||
fun getDeviceData(deviceId: String?) = viewModelScope.launch {
|
||||
deviceData.postValue(deviceId?.let { repository.getDeviceDataById(it) })
|
||||
}
|
||||
@@ -101,8 +92,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
||||
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
||||
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
||||
}
|
||||
|
||||
private fun addResultTestToDb() {
|
||||
@@ -121,32 +110,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Success")
|
||||
testDetails.localFlag = true
|
||||
hemoCubeDao.insertAll(testDetails)
|
||||
}
|
||||
|
||||
is Response.Error -> {
|
||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||
fireBaseUpload.postValue("Error")
|
||||
hemoCubeDao.insertAll(testDetails)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun addResultTestToDbforbuffercheck(bufferCheckData: BufferCheckData) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
||||
when (val response = repository.addTestToDatabaseforBufferCheck(bufferCheckData)) {
|
||||
is Response.Success -> {
|
||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
|
||||
is Response.Error -> {
|
||||
@@ -168,21 +131,15 @@ class HemoCubeViewModel @Inject constructor(
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(userData)) {
|
||||
is Response.Success -> {
|
||||
fireBaseBulkUpload.postValue("Success")
|
||||
updateLocalFlag(userData._id)
|
||||
fireBaseUpload.postValue("Success")
|
||||
deleteById(userData._id)
|
||||
}
|
||||
|
||||
else -> {
|
||||
fireBaseBulkUpload.postValue("Error")
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateLocalFlag(userId: String) = viewModelScope.launch {
|
||||
hemoCubeDao.updateFieldById(id = userId, true)
|
||||
}
|
||||
|
||||
fun deleteById(userId: String) = viewModelScope.launch {
|
||||
hemoCubeDao.deleteById(id = userId)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import `in`.sminnovations.hpostesting.databinding.ActivityTestRightBinding
|
||||
class TestRightActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityTestRightBinding
|
||||
private val viewModel by viewModels<TestRightViewModel<Any?>>()
|
||||
private val viewModel by viewModels<TestRightViewModel>()
|
||||
private var myMenu: Menu? = null
|
||||
|
||||
private lateinit var mDriver: UsbSerialDriver
|
||||
|
||||
@@ -25,7 +25,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpReferenceB
|
||||
@AndroidEntryPoint
|
||||
class TestRightExpReference : Fragment() {
|
||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private val TAG = "TestRightExpReference"
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
|
||||
@@ -27,7 +27,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpSampleBind
|
||||
class TestRightExpSample : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpSampleBinding
|
||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
private val TAG = "TestRightExpSample"
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext
|
||||
class TestRightResults : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightResultsBinding
|
||||
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
|
||||
override fun onCreateView(
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.example.hpostesting.presentation.testRight
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -26,7 +27,6 @@ import com.example.hpostesting.domain.TestRightResultCalculation
|
||||
import com.example.hpostesting.util.MyUtils
|
||||
import com.google.firebase.storage.FirebaseStorage
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.scopes.ViewModelScoped
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import java.io.File
|
||||
@@ -39,16 +39,14 @@ import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
@HiltViewModel
|
||||
@ViewModelScoped
|
||||
class TestRightViewModel @Inject constructor(
|
||||
private val saveRawData: SaveRawData,
|
||||
private val saveRawDataTest: SaveRawDataTest,
|
||||
private val repository: DatabaseRepository,
|
||||
private val userDao: UserDao,
|
||||
context: Context?
|
||||
context: Context
|
||||
) : ViewModel() {
|
||||
|
||||
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
|
||||
@@ -57,10 +55,10 @@ class TestRightViewModel @Inject constructor(
|
||||
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
|
||||
var testDetails = DataHolder.selectedTest
|
||||
val testDetails = DataHolder.selectedTest
|
||||
|
||||
private val _networkStatusLiveData = context?.let { NetworkStatusLiveData(it) }
|
||||
val networkStatusLiveData: NetworkStatusLiveData?
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
val networkStatusLiveData: LiveData<Boolean>
|
||||
get() = _networkStatusLiveData
|
||||
|
||||
val allUserData = userDao.getAll()
|
||||
@@ -442,7 +440,7 @@ class TestRightViewModel @Inject constructor(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(testDetails)) {
|
||||
is Response.Success<*> -> {
|
||||
is Response.Success -> {
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
|
||||
@@ -451,45 +449,43 @@ class TestRightViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean, deviceSerialNumber: String) =
|
||||
viewModelScope.launch {
|
||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||
testDetails?.csvPath = csvFilePath
|
||||
testDetails?.reportPath = logTxtFilePath
|
||||
testDetails?.deviceSerialNumber = deviceSerialNumber
|
||||
if (isOnline) {
|
||||
val storageRef = FirebaseStorage.getInstance().reference
|
||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean,deviceSerialNumber: String) = viewModelScope.launch {
|
||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||
testDetails?.csvPath = csvFilePath
|
||||
testDetails?.reportPath = logTxtFilePath
|
||||
testDetails?.deviceSerialNumber = deviceSerialNumber
|
||||
if (isOnline) {
|
||||
val storageRef = FirebaseStorage.getInstance().reference
|
||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||
|
||||
try {
|
||||
val csvFileUri = Uri.fromFile(File(csvFilePath))
|
||||
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
||||
try {
|
||||
val csvFileUri = Uri.fromFile(File(csvFilePath))
|
||||
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
||||
|
||||
val csvUploadTask =
|
||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!)
|
||||
.putFile(csvFileUri)
|
||||
.await()
|
||||
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
||||
.putFile(logTxtFileUri).await()
|
||||
val csvUploadTask =
|
||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!).putFile(csvFileUri)
|
||||
.await()
|
||||
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
||||
.putFile(logTxtFileUri).await()
|
||||
|
||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
||||
testDetails?.csvPath = csvUri
|
||||
testDetails?.reportPath = logUri
|
||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
||||
testDetails?.csvPath = csvUri
|
||||
testDetails?.reportPath = logUri
|
||||
|
||||
addResultTestToDb()
|
||||
} catch (exception: Exception) {
|
||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||
}
|
||||
} else {
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
userDao.insertAll(testDetails!!)
|
||||
addResultTestToDb()
|
||||
} catch (exception: Exception) {
|
||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||
}
|
||||
} else {
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
userDao.insertAll(testDetails!!)
|
||||
}
|
||||
}
|
||||
|
||||
fun bulkUploadResultToDatabase(userData: UserData) = viewModelScope.launch {
|
||||
val storageRef = FirebaseStorage.getInstance().reference
|
||||
@@ -524,7 +520,7 @@ class TestRightViewModel @Inject constructor(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(userData)) {
|
||||
is Response.Success<*> -> {
|
||||
is Response.Success -> {
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@color/black" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
@@ -1,41 +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_hc_buffer_check"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/my_toolbar"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:context=".presentation.buffercheck.HemocubeBufferCheckActivity">
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@@ -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,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/til_blood_group"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/et_blood_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/select_blood_group"
|
||||
android:inputType="none"
|
||||
android:labelFor="@id/til_blood_group"
|
||||
app:simpleItems="@array/blood_group" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
@@ -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>
|
||||
@@ -4,33 +4,19 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.hpostesting.presentation.dashboard.GalleryFragment">
|
||||
tools:context=".presentation.dashboard.GalleryFragment">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_submit"
|
||||
android:layout_width="wrap_content"
|
||||
<TextView
|
||||
android:id="@+id/text_gallery"
|
||||
style="@style/title1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:clickable="false"
|
||||
android:text="@string/check_buffer"
|
||||
android:textColor="@color/white"
|
||||
android:layout_margin="24dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/to_be_launched_in_next_version_of_the_app"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="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>
|
||||
@@ -1,187 +0,0 @@
|
||||
<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"
|
||||
tools:context="com.example.hpostesting.presentation.buffercheck.HemoCubeBufferCheckFragment">
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/cl_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
style="@style/title1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/Instructions"
|
||||
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/step4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title" />
|
||||
|
||||
<!-- <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"-->
|
||||
<!-- android:text="@string/step5"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_name"
|
||||
style="@style/title2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn_submit" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_subtitle4"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
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/tv_subtitle2" />
|
||||
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:visibility="gone"-->
|
||||
<!-- android:id="@+id/btn_samplestart"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginHorizontal="16dp"-->
|
||||
<!-- android:layout_marginTop="24dp"-->
|
||||
<!-- android:clickable="false"-->
|
||||
<!-- android:text="@string/Start_Sample"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/til_blood_group" />-->
|
||||
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_placebuffer"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginHorizontal="16dp"-->
|
||||
<!-- android:layout_marginTop="24dp"-->
|
||||
<!-- android:clickable="false"-->
|
||||
<!-- android:text="@string/place_buffer"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/btn_submit" />-->
|
||||
|
||||
|
||||
<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:text="@string/submit"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
||||
|
||||
<!-- <com.google.android.material.textfield.TextInputLayout-->
|
||||
<!-- android:id="@+id/til_blood_group"-->
|
||||
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- 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_subtitle4">-->
|
||||
|
||||
<!-- <AutoCompleteTextView-->
|
||||
<!-- android:id="@+id/et_blood_group"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:hint="@string/select_blood_group"-->
|
||||
<!-- android:inputType="none"-->
|
||||
<!-- android:labelFor="@id/til_blood_group"-->
|
||||
<!-- app:simpleItems="@array/blood_group" />-->
|
||||
|
||||
<!-- </com.google.android.material.textfield.TextInputLayout>-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_kit"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- android:text="@string/new_kit"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_buffer"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/new_buffer"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toStartOf="@id/btn_kit"/>-->
|
||||
|
||||
<!-- <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>
|
||||
|
||||
</layout>
|
||||
@@ -27,36 +27,22 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/step4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title" />
|
||||
|
||||
<!-- <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"-->
|
||||
<!-- android:text="@string/step5"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_name"
|
||||
android:id="@+id/tv_subtitle3"
|
||||
style="@style/title2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:gravity="center"
|
||||
android:padding="12dp"
|
||||
android:layout_marginTop="26dp"
|
||||
android:textFontWeight="700"
|
||||
android:text="Name: SMI\n ID: 1672282828"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/step5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:ignore="MissingConstraints" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_subtitle4"
|
||||
@@ -64,93 +50,49 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="72dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/red"
|
||||
android:textSize="18sp"
|
||||
android:textSize="22sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/et_abha_id" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle3" />
|
||||
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:visibility="gone"-->
|
||||
<!-- android:id="@+id/btn_samplestart"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginHorizontal="16dp"-->
|
||||
<!-- android:layout_marginTop="24dp"-->
|
||||
<!-- android:clickable="false"-->
|
||||
<!-- android:text="@string/Start_Sample"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/til_blood_group" />-->
|
||||
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_placebuffer"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginHorizontal="16dp"-->
|
||||
<!-- android:layout_marginTop="24dp"-->
|
||||
<!-- android:clickable="false"-->
|
||||
<!-- android:text="@string/place_buffer"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/btn_submit" />-->
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title2"
|
||||
style="@style/title1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:text="@string/enter_kit_serial_number_manually"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/et_abha_id"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintEnd_toStartOf="@id/btn_go"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title2">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/name_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLength="17"
|
||||
android:inputType="text"
|
||||
android:hint="@string/serial_number" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_go"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="24dp"
|
||||
android:text="@string/go"
|
||||
app:cornerRadius="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/et_abha_id"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toEndOf="@id/et_abha_id"
|
||||
app:layout_constraintTop_toTopOf="@id/et_abha_id" />
|
||||
|
||||
|
||||
<Button
|
||||
android:visibility="gone"
|
||||
android:id="@+id/btn_samplestart"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:clickable="false"
|
||||
android:text="@string/Start_Sample"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/til_blood_group" />
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_placebuffer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:clickable="false"
|
||||
android:text="@string/place_buffer"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -161,66 +103,51 @@
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_samplestart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/error_message"
|
||||
style="@style/title1_1"
|
||||
android:visibility="gone"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/til_blood_group"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="172dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/red"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4">
|
||||
|
||||
<!-- <com.google.android.material.textfield.TextInputLayout-->
|
||||
<!-- android:id="@+id/til_blood_group"-->
|
||||
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- 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_subtitle4">-->
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/et_blood_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/select_blood_group"
|
||||
android:inputType="none"
|
||||
android:labelFor="@id/til_blood_group"
|
||||
app:simpleItems="@array/blood_group" />
|
||||
|
||||
<!-- <AutoCompleteTextView-->
|
||||
<!-- android:id="@+id/et_blood_group"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:hint="@string/select_blood_group"-->
|
||||
<!-- android:inputType="none"-->
|
||||
<!-- android:labelFor="@id/til_blood_group"-->
|
||||
<!-- app:simpleItems="@array/blood_group" />-->
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- </com.google.android.material.textfield.TextInputLayout>-->
|
||||
<Button
|
||||
android:id="@+id/btn_kit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/new_kit"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_kit"-->
|
||||
<!-- android:id="@+id/btn_buffer"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- android:text="@string/new_kit"-->
|
||||
<!-- android:text="@string/new_buffer"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_buffer"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/new_buffer"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toStartOf="@id/btn_kit"/>-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toStartOf="@id/btn_kit"/>-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_read"-->
|
||||
@@ -248,6 +175,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
@@ -194,27 +194,6 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
|
||||
tools:listitem="@layout/user_item_view"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_kit"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btnNewKit"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/btnNewKit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:backgroundTint="@color/primary"
|
||||
android:contentDescription="@string/new_kit"
|
||||
android:src="@drawable/ic_add"
|
||||
app:elevation="1dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
@@ -72,25 +72,6 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/userId"
|
||||
tools:text="Test Status: Completed"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_startIncubation"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/start_incubation"
|
||||
android:visibility="gone"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintStart_toEndOf="@+id/btn_blood"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/btn_blood" />
|
||||
<Button
|
||||
android:id="@+id/btn_blood"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/blood_group"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btn_startIncubation"
|
||||
app:layout_constraintTop_toBottomOf="@id/teststatus" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
@@ -112,7 +112,6 @@
|
||||
<string name="sickle_cert">Sickle Cert</string>
|
||||
<string name="sickle_find">Sickle Find</string>
|
||||
<string name="submit">Submit</string>
|
||||
<string name="diagnostics">Device Diagnostics</string>
|
||||
<string name="place_buffer">Start Buffer</string>
|
||||
<string name="Start_Sample">Start Sample</string>
|
||||
<string name="new_kit">New Kit</string>
|
||||
@@ -193,7 +192,5 @@
|
||||
<string name="test_completed">Test Completed</string>
|
||||
<string name="select_blood_group">Select Blood Group</string>
|
||||
<string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string>
|
||||
<string name="start_incubation">Incubate</string>
|
||||
<string name="check_buffer">Check Buffer</string>
|
||||
|
||||
</resources>
|
||||
@@ -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
|
||||
|
||||
import android.content.Context
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.dao.UserDao
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||
import com.example.hpostesting.domain.SaveRawData
|
||||
import com.example.hpostesting.domain.SaveRawDataTest
|
||||
import com.example.hpostesting.data.model.PatientData
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class TestRightViewModelTest {
|
||||
|
||||
@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 viewModel = TestRightViewModel()
|
||||
private val data = InputData()
|
||||
|
||||
@Test
|
||||
@@ -95,11 +63,8 @@ class TestRightViewModelTest {
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||
val mapIntensityValues = viewModel.mapIntensityValues(
|
||||
TestDataGenerator().getInputSampleMapIntensityValues(),
|
||||
false
|
||||
)
|
||||
viewModel.testDetails = UserData("Surya", "2", "Male")
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
|
||||
viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED)
|
||||
viewModel.mapWavelengthToAbsorbance()
|
||||
|
||||
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
||||
|
||||
@@ -4,8 +4,8 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.0.2'
|
||||
classpath 'com.google.gms:google-services:4.4.0'
|
||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
||||
classpath 'com.google.gms:google-services:4.3.15'
|
||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.0'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
Reference in New Issue
Block a user