Compare commits
2 Commits
preprod-te
...
release-v1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f264c299b | ||
|
|
19fcc13b2a |
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -4,7 +4,6 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="testRunner" value="GRADLE" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="jbr-17" />
|
<option name="gradleJvm" value="jbr-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ android {
|
|||||||
|
|
||||||
// prod - production, preprod - preproduction, quality - qc
|
// prod - production, preprod - preproduction, quality - qc
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "in.sminnovations.hpostesting"
|
applicationId "in.sminnovations.hpostesting.dev"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 26
|
versionCode 76
|
||||||
versionName "2.1.26"
|
versionName "2.1.76"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.12.0'
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.11.0'
|
implementation 'com.google.android.material:material:1.10.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.6.2'
|
implementation 'androidx.fragment:fragment-ktx:1.6.2'
|
||||||
@@ -82,9 +82,6 @@ dependencies {
|
|||||||
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
|
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'com.google.android.play:core:1.10.3'
|
|
||||||
implementation 'io.nats:jnats:2.11.2'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
@@ -100,13 +97,13 @@ dependencies {
|
|||||||
|
|
||||||
|
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
||||||
implementation 'com.opencsv:opencsv:5.5'
|
implementation 'com.opencsv:opencsv:4.6'
|
||||||
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
||||||
|
|
||||||
implementation "androidx.fragment:fragment-ktx:1.6.2"
|
implementation "androidx.fragment:fragment-ktx:1.6.2"
|
||||||
|
|
||||||
// CSV read, write
|
// CSV read, write
|
||||||
implementation 'com.opencsv:opencsv:5.5'
|
implementation 'com.opencsv:opencsv:4.6'
|
||||||
|
|
||||||
// Barcode scanner
|
// Barcode scanner
|
||||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||||
@@ -115,17 +112,17 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
||||||
|
|
||||||
//Room
|
//Room
|
||||||
implementation "androidx.room:room-ktx:2.6.1"
|
implementation "androidx.room:room-ktx:2.6.0"
|
||||||
implementation "androidx.room:room-runtime:2.6.1"
|
implementation "androidx.room:room-runtime:2.6.0"
|
||||||
kapt ("androidx.room:room-compiler:2.6.1")
|
kapt ("androidx.room:room-compiler:2.6.0")
|
||||||
|
|
||||||
//image
|
//image
|
||||||
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
||||||
|
|
||||||
// Navigation Component
|
// Navigation Component
|
||||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.6"
|
implementation "androidx.navigation:navigation-fragment-ktx:2.7.5"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.6"
|
implementation "androidx.navigation:navigation-ui-ktx:2.7.5"
|
||||||
|
|
||||||
//Dagger - Hilt
|
//Dagger - Hilt
|
||||||
implementation "com.google.dagger:hilt-android:2.46"
|
implementation "com.google.dagger:hilt-android:2.46"
|
||||||
@@ -135,10 +132,7 @@ dependencies {
|
|||||||
// Retrofit + GSON
|
// Retrofit + GSON
|
||||||
implementation "com.squareup.retrofit2:retrofit:2.9.0"
|
implementation "com.squareup.retrofit2:retrofit:2.9.0"
|
||||||
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
|
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.9.3")
|
|
||||||
|
|
||||||
implementation "androidx.preference:preference-ktx:1.2.1"
|
implementation "androidx.preference:preference-ktx:1.2.1"
|
||||||
implementation 'io.nats:jnats:2.11.2'
|
|
||||||
implementation 'com.google.android.play:core:1.10.3'
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
|
||||||
|
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.BATTERY_STATS"
|
android:name="android.permission.BATTERY_STATS"
|
||||||
tools:ignore="ProtectedPermissions" />
|
tools:ignore="ProtectedPermissions" />
|
||||||
@@ -64,17 +62,7 @@
|
|||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/title_activity_dashboard"
|
android:label="@string/title_activity_dashboard"
|
||||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||||
tools:ignore="AppLinkUrlError,MissingClass">
|
tools:ignore="MissingClass" />
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<data android:scheme="content" />
|
|
||||||
<data android:scheme="file" />
|
|
||||||
<data android:mimeType="application/vnd.android.package-archive" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
||||||
@@ -126,17 +114,6 @@
|
|||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
tools:replace="android:screenOrientation" />
|
tools:replace="android:screenOrientation" />
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name="androidx.core.content.FileProvider"
|
|
||||||
android:authorities="com.example.hpostesting.fileprovider"
|
|
||||||
android:exported="false"
|
|
||||||
android:grantUriPermissions="true">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
||||||
android:resource="@xml/file_paths" />
|
|
||||||
</provider>
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1 +0,0 @@
|
|||||||
BASE_URL= https://datacollection.micropcr.com/api/
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import com.example.hpostesting.data.model.Response
|
||||||
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
|
import com.example.hpostesting.util.MyUtils
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class FileUploader {
|
||||||
|
|
||||||
|
private val TAG = "FileUploader"
|
||||||
|
val repository = DatabaseRepository()
|
||||||
|
|
||||||
|
suspend fun start() {
|
||||||
|
|
||||||
|
val listOfFiles = repository.getAllFromPendingQueue()
|
||||||
|
|
||||||
|
for (each in listOfFiles){
|
||||||
|
// Checking internet connectivity & mobile as same or not
|
||||||
|
if (MyUtils.isInternetConnected() && each.mobileId == DataHolder.mobileUniqueId) {
|
||||||
|
|
||||||
|
Log.d(TAG, "uploading file ${each.pendingId}")
|
||||||
|
GlobalScope.launch {
|
||||||
|
val response = repository.uploadFileToStorage(each.patientId, each.filePath)
|
||||||
|
|
||||||
|
when (response) {
|
||||||
|
is Response.Success -> {
|
||||||
|
Log.d(TAG, "File Uploaded ${each.pendingId}")
|
||||||
|
repository.removeFromPendingQueue(each.pendingId)
|
||||||
|
}
|
||||||
|
|
||||||
|
is Response.Error -> {
|
||||||
|
Log.d(TAG, response.exception.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.example.hpostesting.data
|
|
||||||
|
|
||||||
sealed class Result<out T : Any> {
|
|
||||||
data class Success<out T : Any>(val data: T) : Result<T>()
|
|
||||||
data class Error(val exception: Exception) : Result<Nothing>()
|
|
||||||
class Loading<T : Any> : Result<T>()
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.example.hpostesting.data.api
|
|
||||||
|
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
|
||||||
import retrofit2.http.Body
|
|
||||||
import retrofit2.http.POST
|
|
||||||
|
|
||||||
interface MolbioAuthApi {
|
|
||||||
|
|
||||||
@POST("deviceManagement/device/provision")
|
|
||||||
suspend fun deviceProvision(
|
|
||||||
@Body deviceProvisionRequest: DeviceProvisionRequest
|
|
||||||
): DeviceProvisionResponse
|
|
||||||
|
|
||||||
@POST("deviceService/device/login")
|
|
||||||
suspend fun login(
|
|
||||||
@Body loginRequest: LoginRequest
|
|
||||||
): LoginResponse
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.example.hpostesting.data.api
|
|
||||||
|
|
||||||
import com.example.hpostesting.data.model.log.UploadLogsResponse
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultResponse
|
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
|
||||||
import okhttp3.MultipartBody
|
|
||||||
import okhttp3.ResponseBody
|
|
||||||
import retrofit2.http.Body
|
|
||||||
import retrofit2.http.Multipart
|
|
||||||
import retrofit2.http.POST
|
|
||||||
import retrofit2.http.PUT
|
|
||||||
import retrofit2.http.Part
|
|
||||||
|
|
||||||
interface MolbioResultApi {
|
|
||||||
|
|
||||||
@PUT("deviceService/results/HPOS")
|
|
||||||
suspend fun uploadResults(
|
|
||||||
@Body molbioV2ResultRequest: MolbioV2ResultRequest
|
|
||||||
): MolbioV2ResultResponse
|
|
||||||
|
|
||||||
@POST("deviceService/device/checkUpdate")
|
|
||||||
suspend fun checkUpdate(
|
|
||||||
@Body checkUpdateRequest: CheckUpdateRequest
|
|
||||||
): CheckUpdateResponse
|
|
||||||
|
|
||||||
@POST("deviceService/device/getUpdate")
|
|
||||||
suspend fun deviceUpdate(
|
|
||||||
@Body deviceUpdateRequest: DeviceUpdateRequest
|
|
||||||
): ResponseBody
|
|
||||||
|
|
||||||
@Multipart
|
|
||||||
@POST("deviceService/device/uploadLogs")
|
|
||||||
suspend fun uploadLogs(
|
|
||||||
@Part logFile: MultipartBody.Part
|
|
||||||
): UploadLogsResponse
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.example.hpostesting.data.api
|
|
||||||
|
|
||||||
interface PropertyProvider {
|
|
||||||
|
|
||||||
fun getProperty(key: String): String
|
|
||||||
}
|
|
||||||
@@ -4,21 +4,8 @@ object Constants {
|
|||||||
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
||||||
const val HOMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
const val HOMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
||||||
|
|
||||||
const val BASE_URL = "www.google.com"
|
|
||||||
|
|
||||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||||
|
|
||||||
const val serialNumber = "NKH5555AH"
|
|
||||||
const val deviceTypeName = "HPOS"
|
|
||||||
const val uid = "NKH5555AH"
|
|
||||||
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
|
||||||
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
|
||||||
const val deviceID = "HCV-000-3001"
|
|
||||||
const val devicePassword = "810516d8f4c7"
|
|
||||||
|
|
||||||
const val ACCESS_TOKEN = "accessToken"
|
|
||||||
const val NATS_TOKEN = "natsToken"
|
|
||||||
|
|
||||||
const val WRITE_TIMEOUT_MILLIS = 30000 // 30 sec
|
const val WRITE_TIMEOUT_MILLIS = 30000 // 30 sec
|
||||||
const val READ_TIMEOUT_MILLIS = 60000 // 1 min
|
const val READ_TIMEOUT_MILLIS = 60000 // 1 min
|
||||||
const val DELAY_BETWEEN_COMMANDS: Long = 1000
|
const val DELAY_BETWEEN_COMMANDS: Long = 1000
|
||||||
@@ -86,7 +73,8 @@ object Constants {
|
|||||||
"HCV-000-3007",
|
"HCV-000-3007",
|
||||||
"HCV-000-3008",
|
"HCV-000-3008",
|
||||||
"HCV-000-3009",
|
"HCV-000-3009",
|
||||||
"HCV-000-3010"
|
"HCV-000-3010",
|
||||||
|
"HPP1-0124-0001"
|
||||||
)
|
)
|
||||||
|
|
||||||
const val password = "SMI@12345"
|
const val password = "SMI@12345"
|
||||||
@@ -116,7 +104,7 @@ object Constants {
|
|||||||
const val TEST_STATUS_CODE_TEST_COMPLETED = 12.0
|
const val TEST_STATUS_CODE_TEST_COMPLETED = 12.0
|
||||||
|
|
||||||
val DEVICE_CONFIGURATION: Map<String, List<List<Double>>> = mapOf<String, List<List<Double>>>(
|
val DEVICE_CONFIGURATION: Map<String, List<List<Double>>> = mapOf<String, List<List<Double>>>(
|
||||||
"HCV-000-3001" to listOf(
|
"HPP1-0124-0001" to listOf(
|
||||||
listOf(1.313, -0.89), // LED1, 435nm
|
listOf(1.313, -0.89), // LED1, 435nm
|
||||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||||
listOf(0.2012, 0.0092), // LED3, 555nm
|
listOf(0.2012, 0.0092), // LED3, 555nm
|
||||||
@@ -141,21 +129,21 @@ object Constants {
|
|||||||
listOf(1.0, 0.0) // LED4
|
listOf(1.0, 0.0) // LED4
|
||||||
),
|
),
|
||||||
"HCV-000-3005" to listOf(
|
"HCV-000-3005" to listOf(
|
||||||
listOf(1.7272, -1.1977), // LED1, 435nm
|
listOf(1.3801, -0.372), // LED1, 435nm
|
||||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
listOf(0.4565, -0.0371), // LED3, 555nm
|
||||||
listOf(1.0, 0.0) // LED4
|
listOf(1.0, 0.0) // LED4
|
||||||
),
|
),
|
||||||
"HCV-000-3006" to listOf(
|
"HCV-000-3006" to listOf(
|
||||||
listOf(1.7272, -1.1977), // LED1, 435nm
|
listOf(1.3801, -0.372), // LED1, 435nm
|
||||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
listOf(0.4565, -0.0371), // LED3, 555nm
|
||||||
listOf(1.0, 0.0) // LED4
|
listOf(1.0, 0.0) // LED4
|
||||||
),
|
),
|
||||||
"HCV-000-3007" to listOf(
|
"HCV-000-3007" to listOf(
|
||||||
listOf(1.7272, -1.1977), // LED1, 435nm
|
listOf(1.8445, -0.8213), // LED1, 435nm
|
||||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
listOf(0.4613, -0.0831), // LED3, 555nm
|
||||||
listOf(1.0, 0.0) // LED4
|
listOf(1.0, 0.0) // LED4
|
||||||
),
|
),
|
||||||
"HCV-000-3008" to listOf(
|
"HCV-000-3008" to listOf(
|
||||||
@@ -183,7 +171,7 @@ object Constants {
|
|||||||
const val BATTERY_LEVEL_MIN = 0
|
const val BATTERY_LEVEL_MIN = 0
|
||||||
|
|
||||||
val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>(
|
val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>(
|
||||||
"HCV-000-3001" to listOf(
|
"HPP1-0124-0001" to listOf(
|
||||||
listOf(20000, 25074),
|
listOf(20000, 25074),
|
||||||
listOf(20000, 24596),
|
listOf(20000, 24596),
|
||||||
listOf(20000, 26065),
|
listOf(20000, 26065),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|||||||
import com.google.android.datatransport.runtime.dagger.Provides
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 14, exportSchema = false)
|
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 13, exportSchema = false)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MyDatabase : RoomDatabase() {
|
abstract class MyDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class Credentials(
|
|
||||||
val password: String? = "",
|
|
||||||
val username: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class Device(
|
|
||||||
val assigned: Boolean? = false,
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val deviceType: DeviceType? = DeviceType(),
|
|
||||||
val deviceTypeId: Int? = 0,
|
|
||||||
val deviceUser: DeviceUser? = DeviceUser(),
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val name: String? = "",
|
|
||||||
val serialNumber: String? = "",
|
|
||||||
val uid: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class DeviceProvisionData(
|
|
||||||
val credentials: Credentials? = Credentials(),
|
|
||||||
val device: Device? = Device()
|
|
||||||
)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class DeviceProvisionRequest(
|
|
||||||
val deviceTypeName: String? = "",
|
|
||||||
val email: String? = "",
|
|
||||||
val password: String? = "",
|
|
||||||
val serialNumber: String? = "",
|
|
||||||
val uid: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class DeviceProvisionResponse(
|
|
||||||
@SerializedName("Data")
|
|
||||||
val data: DeviceProvisionData? = DeviceProvisionData(),
|
|
||||||
@SerializedName("Message")
|
|
||||||
val message: String? = "",
|
|
||||||
@SerializedName("Result")
|
|
||||||
val result: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class DeviceType(
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val description: String? = "",
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val name: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.deviceprovision
|
|
||||||
|
|
||||||
data class DeviceUser(
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val deviceId: Int? = 0,
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val lastLogin: Any? = Any(),
|
|
||||||
val natsToken: String? = "",
|
|
||||||
val natsTokenExpiry: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0,
|
|
||||||
val username: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.log
|
|
||||||
|
|
||||||
data class UploadLogsData(
|
|
||||||
val filename: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.log
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class UploadLogsResponse(
|
|
||||||
@SerializedName("Data")
|
|
||||||
val data: UploadLogsData? = UploadLogsData(),
|
|
||||||
@SerializedName("Message")
|
|
||||||
val message: String? = "",
|
|
||||||
@SerializedName("Result")
|
|
||||||
val result: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
data class Device(
|
|
||||||
val assigned: Boolean? = false,
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val deviceType: DeviceType? = DeviceType(),
|
|
||||||
val deviceTypeId: Int? = 0,
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val name: String? = "",
|
|
||||||
val serialNumber: String? = "",
|
|
||||||
val uid: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
data class DeviceType(
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val description: String? = "",
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val name: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
data class DeviceUser(
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val device: Device? = Device(),
|
|
||||||
val deviceId: Int? = 0,
|
|
||||||
val enabled: Boolean? = false,
|
|
||||||
val id: Int? = 0,
|
|
||||||
val lastLogin: String? = "",
|
|
||||||
val natsToken: String? = "",
|
|
||||||
val natsTokenExpiry: String? = "",
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0,
|
|
||||||
val username: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
data class LoginData(
|
|
||||||
val accessToken: String? = "",
|
|
||||||
val deviceUser: DeviceUser? = DeviceUser()
|
|
||||||
)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
data class LoginRequest(
|
|
||||||
val lab: String? = "",
|
|
||||||
val latitude: String? = "",
|
|
||||||
val location: String? = "",
|
|
||||||
val longitude: String? = "",
|
|
||||||
val mode: String? = "",
|
|
||||||
val password: String? = "",
|
|
||||||
val serialNumber: String? = "",
|
|
||||||
val username: String? = "",
|
|
||||||
val version: String? = "2.1.26"
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.login
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class LoginResponse(
|
|
||||||
@SerializedName("Data")
|
|
||||||
val data: LoginData? = LoginData(),
|
|
||||||
@SerializedName("Message")
|
|
||||||
val message: String? = "",
|
|
||||||
@SerializedName("Result")
|
|
||||||
val result: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.molbioresult
|
|
||||||
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
|
|
||||||
data class MolbioV2Result(
|
|
||||||
val age: Int? = 0,
|
|
||||||
val analysisDate: String? = "",
|
|
||||||
val analysisId: String? = "",
|
|
||||||
val analysisStatus: String? = "",
|
|
||||||
val analysisType: String? = "",
|
|
||||||
val analysisTypeMethod: String? = "",
|
|
||||||
val bloodGroup: String? = "",
|
|
||||||
val coefficients: List<Int>? = listOf(),
|
|
||||||
val collectionLocation: List<Any>? = listOf(),
|
|
||||||
val collectionTime: String? = "",
|
|
||||||
val collector: String? = "",
|
|
||||||
val curveFitting: String? = "",
|
|
||||||
val deviceName: String? = "",
|
|
||||||
val expiryTime: String? = "",
|
|
||||||
val gender: String? = "",
|
|
||||||
val interpretation: String? = "",
|
|
||||||
val `operator`: String? = "",
|
|
||||||
val patientId: Int? = 0,
|
|
||||||
val pregnancy: Boolean? = false,
|
|
||||||
val rawData: HemoCubeTestData? = HemoCubeTestData(),
|
|
||||||
val recommendation: String? = "",
|
|
||||||
val sampleId: String? = "",
|
|
||||||
val sampleType: String? = "",
|
|
||||||
val sickleCellHistory: Boolean? = false,
|
|
||||||
val testId: String? = "",
|
|
||||||
val testResult: String? = "",
|
|
||||||
val testStatus: String? = "",
|
|
||||||
val testTime: String? = "",
|
|
||||||
val testType: String? = "",
|
|
||||||
val thresholds: String? = "",
|
|
||||||
val underMedication: Boolean? = false,
|
|
||||||
val volume: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.molbioresult
|
|
||||||
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
|
|
||||||
data class MolbioV2ResultData(
|
|
||||||
val age: Int? = 0,
|
|
||||||
val analysisDate: String? = "",
|
|
||||||
val analysisStatus: String? = "",
|
|
||||||
val analysisType: String? = "",
|
|
||||||
val analysisTypeMethod: String? = "",
|
|
||||||
val bloodGroup: String? = "",
|
|
||||||
val coefficients: List<Int>? = listOf(),
|
|
||||||
val collectionLocation: List<Any>? = listOf(),
|
|
||||||
val collectionTime: String? = "",
|
|
||||||
val collector: String? = "",
|
|
||||||
val createdAt: String? = "",
|
|
||||||
val createdBy: Int? = 0,
|
|
||||||
val curveFitting: String? = "",
|
|
||||||
val deviceId: Int? = 0,
|
|
||||||
val expiryTime: String? = "",
|
|
||||||
val gender: String? = "",
|
|
||||||
val id: Int? = 0,
|
|
||||||
val interpretation: String? = "",
|
|
||||||
val `operator`: String? = "",
|
|
||||||
val patientId: Int? = 0,
|
|
||||||
val pregnancy: Boolean? = false,
|
|
||||||
val rawData: HemoCubeTestData? = HemoCubeTestData(),
|
|
||||||
val recommendation: String? = "",
|
|
||||||
val sampleId: String? = "",
|
|
||||||
val sampleType: String? = "",
|
|
||||||
val sickleCellHistory: Boolean? = false,
|
|
||||||
val testId: String? = "",
|
|
||||||
val testResult: String? = "",
|
|
||||||
val testStatus: String? = "",
|
|
||||||
val testTime: String? = "",
|
|
||||||
val testType: String? = "",
|
|
||||||
val thresholds: String? = "",
|
|
||||||
val underMedication: Boolean? = false,
|
|
||||||
val updatedAt: String? = "",
|
|
||||||
val updatedBy: Int? = 0,
|
|
||||||
val volume: Int? = 0
|
|
||||||
)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.molbioresult
|
|
||||||
|
|
||||||
data class MolbioV2ResultRequest(
|
|
||||||
val results: List<MolbioV2Result>? = listOf()
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.molbioresult
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class MolbioV2ResultResponse(
|
|
||||||
@SerializedName("Data")
|
|
||||||
val data: List<MolbioV2ResultData>? = listOf(),
|
|
||||||
@SerializedName("Message")
|
|
||||||
val message: String? = "",
|
|
||||||
@SerializedName("Result")
|
|
||||||
val result: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.molbioresult
|
|
||||||
|
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
|
||||||
|
|
||||||
data class RawData(
|
|
||||||
var _id: String = "",
|
|
||||||
var name: String = "",
|
|
||||||
var incubationTime: String = "",
|
|
||||||
var bloodGroup: String = "",
|
|
||||||
var birthYear: String = "",
|
|
||||||
var state: String = "",
|
|
||||||
var abhaId: String = "",
|
|
||||||
var userImageURL: String = "",
|
|
||||||
var location: UserData.Location? = null,
|
|
||||||
var reportUploadTime: String? = "",
|
|
||||||
var testType: String? = "HEMOCUBE",
|
|
||||||
var testTime: String? = "",
|
|
||||||
var testStatus: Boolean? = false,
|
|
||||||
var gender: String = "",
|
|
||||||
var localFlag: Boolean = false,
|
|
||||||
var deviceId: String? = "",
|
|
||||||
var appVersion:String? = "",
|
|
||||||
var deviceSerialNumber: String = "",
|
|
||||||
var deviceType: String = "HEMOCUBE",
|
|
||||||
var kitSerial: String = "",
|
|
||||||
var resultData: String = "",
|
|
||||||
var led1Buffer: Double? = null,
|
|
||||||
var led2Buffer: Double? = null,
|
|
||||||
var led3Buffer: Double? = null,
|
|
||||||
var led4Buffer: Double? = null,
|
|
||||||
var led1Sample: Double? = null,
|
|
||||||
var led2Sample: Double? = null,
|
|
||||||
var led3Sample: Double? = null,
|
|
||||||
var led4Sample: Double? = null,
|
|
||||||
var led1Average: Double? = null,
|
|
||||||
var led2Average: Double? = null,
|
|
||||||
var led3Average: Double? = null,
|
|
||||||
var led4Average: Double? = null,
|
|
||||||
var abs1: Double? = null,
|
|
||||||
var abs2: Double? = null,
|
|
||||||
var abs3: Double? = null,
|
|
||||||
var abs4: Double? = null,
|
|
||||||
var deviceRatio: Double? = null,
|
|
||||||
var calculatedRatio: Double? = null,
|
|
||||||
var predictedDenovixRatio: Double? = null,
|
|
||||||
var coefficients: String? = "",
|
|
||||||
var classificationResult: String = "",
|
|
||||||
var prdClassification: String = "",
|
|
||||||
var errorMessages: String = "",
|
|
||||||
var batteryLevel: String = "",
|
|
||||||
var batteryCapacity: String = "",
|
|
||||||
var batteryMaxCapacity: String = "",
|
|
||||||
var batteryTemperature: String = "",
|
|
||||||
var batteryVoltage: String = "",
|
|
||||||
)
|
|
||||||
@@ -55,5 +55,4 @@ data class HemoCubeTestData(
|
|||||||
var batteryMaxCapacity: String = "",
|
var batteryMaxCapacity: String = "",
|
||||||
var batteryTemperature: String = "",
|
var batteryTemperature: String = "",
|
||||||
var batteryVoltage: String = "",
|
var batteryVoltage: String = "",
|
||||||
var molbioFlag: Boolean = false
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.example.hpostesting.data.model.test
|
||||||
|
|
||||||
|
import com.example.hpostesting.data.model.Location
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class TestDetails(
|
||||||
|
val testID: String,
|
||||||
|
var testStatus: Status,
|
||||||
|
val patientID: String,
|
||||||
|
val patientName: String,
|
||||||
|
val patientAge: Int?,
|
||||||
|
|
||||||
|
var resultRatio: Double?,
|
||||||
|
var result: TestRightResultType?,
|
||||||
|
|
||||||
|
val reportPath: String?,
|
||||||
|
val csvPath: String?,
|
||||||
|
val logPath: String?,
|
||||||
|
|
||||||
|
// Meta Data
|
||||||
|
var deviceId: String?,
|
||||||
|
val mobileId: String,
|
||||||
|
var kitSerial: String?,
|
||||||
|
val location: Location?,
|
||||||
|
val appVersion: String,
|
||||||
|
|
||||||
|
val registeredTime: Date?,
|
||||||
|
var uploadTime: Date?
|
||||||
|
) {
|
||||||
|
constructor() : this(
|
||||||
|
"",
|
||||||
|
Status.PENDING,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Status {
|
||||||
|
COMPLETED,
|
||||||
|
PENDING,
|
||||||
|
INPROGRESS
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.example.hpostesting.data.model.test
|
||||||
|
|
||||||
|
data class TestInfo(
|
||||||
|
val value: String,
|
||||||
|
val number1: String,
|
||||||
|
val number2: String,
|
||||||
|
val result: String,
|
||||||
|
val resultConfirmatory: String,
|
||||||
|
val directoryPath: String,
|
||||||
|
val fullPath: String
|
||||||
|
)
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.updates
|
|
||||||
|
|
||||||
data class CheckUpdateData(
|
|
||||||
val version: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.updates
|
|
||||||
|
|
||||||
data class CheckUpdateRequest(
|
|
||||||
val currentVersion: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.updates
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
data class CheckUpdateResponse(
|
|
||||||
@SerializedName("Data")
|
|
||||||
val data: CheckUpdateData? = CheckUpdateData(),
|
|
||||||
@SerializedName("Message")
|
|
||||||
val message: String? = "",
|
|
||||||
@SerializedName("Result")
|
|
||||||
val result: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.updates
|
|
||||||
|
|
||||||
data class DeviceUpdateRequest(
|
|
||||||
val serial_no: String? = ""
|
|
||||||
)
|
|
||||||
@@ -1,97 +1,37 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.example.hpostesting.data.Result
|
|
||||||
import com.example.hpostesting.data.api.MolbioAuthApi
|
|
||||||
import com.example.hpostesting.data.api.MolbioResultApi
|
|
||||||
import com.example.hpostesting.data.model.PendingUploads
|
import com.example.hpostesting.data.model.PendingUploads
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
import com.example.hpostesting.data.model.log.UploadLogsResponse
|
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultResponse
|
|
||||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.firestore.FirebaseFirestore
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
import com.google.firebase.firestore.ktx.firestore
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import com.google.firebase.storage.ktx.storage
|
import com.google.firebase.storage.ktx.storage
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
import okhttp3.MultipartBody
|
|
||||||
import okhttp3.ResponseBody
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.ConnectException
|
|
||||||
import java.net.SocketTimeoutException
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
|
||||||
|
|
||||||
class NetworkException(message: String, cause: Throwable) : Exception(message, cause)
|
class DatabaseRepository @Inject constructor() : Repository {
|
||||||
class DatabaseRepository @Inject constructor(
|
|
||||||
@Named("Auth")private val molbioAuthApi: MolbioAuthApi,
|
|
||||||
private val molbioResultApi: MolbioResultApi
|
|
||||||
) : Repository {
|
|
||||||
|
|
||||||
private val db: FirebaseFirestore = Firebase.firestore
|
private val db: FirebaseFirestore = Firebase.firestore
|
||||||
private val storage = Firebase.storage
|
private val storage = Firebase.storage
|
||||||
|
|
||||||
private suspend fun <T : Any> safeApiCall(apiCall: suspend () -> T): Result<T> {
|
|
||||||
return try {
|
|
||||||
val response = apiCall.invoke()
|
|
||||||
Result.Success(response)
|
|
||||||
} catch (e: SocketTimeoutException) {
|
|
||||||
Result.Error(NetworkException("Network timeout", e))
|
|
||||||
} catch (e: ConnectException) {
|
|
||||||
Result.Error(NetworkException("Network connection failed", e))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Result.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun deviceProvision(deviceProvisionRequest: DeviceProvisionRequest): Result<DeviceProvisionResponse> {
|
|
||||||
return safeApiCall { molbioAuthApi.deviceProvision(deviceProvisionRequest) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun login(loginRequest: LoginRequest): Result<LoginResponse> {
|
|
||||||
return safeApiCall { molbioAuthApi.login(loginRequest) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun uploadResults(molbioV2ResultRequest: MolbioV2ResultRequest): Result<MolbioV2ResultResponse> {
|
|
||||||
return safeApiCall { molbioResultApi.uploadResults(molbioV2ResultRequest) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun checkUpdate(checkUpdateRequest: CheckUpdateRequest): Result<CheckUpdateResponse> {
|
|
||||||
return safeApiCall { molbioResultApi.checkUpdate(checkUpdateRequest) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun deviceUpdate(deviceUpdateRequest: DeviceUpdateRequest): Result<ResponseBody> {
|
|
||||||
return safeApiCall { molbioResultApi.deviceUpdate(deviceUpdateRequest) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse> {
|
|
||||||
return safeApiCall { molbioResultApi.uploadLogs(logFile) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String> {
|
override suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
val userdata =
|
val userdata = db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||||
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
if (userdata.documents.isNotEmpty()) {
|
||||||
userdata.documents.forEach {
|
userdata.documents.forEach {
|
||||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.collection("testData").add(data).await()
|
db.collection("testData").add(data!!).await()
|
||||||
Response.Success(data._id)
|
Response.Success(data!!._id)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
}
|
}
|
||||||
@@ -99,15 +39,14 @@ class DatabaseRepository @Inject constructor(
|
|||||||
|
|
||||||
override suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
override suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
val userdata =
|
val userdata = db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||||
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
if (userdata.documents.isNotEmpty()) {
|
||||||
userdata.documents.forEach {
|
userdata.documents.forEach {
|
||||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.collection("testData").add(data).await()
|
db.collection("testData").add(data!!).await()
|
||||||
Response.Success(data._id)
|
Response.Success(data!!._id)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Firebase.crashlytics.recordException(e)
|
Firebase.crashlytics.recordException(e)
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
@@ -117,7 +56,7 @@ class DatabaseRepository @Inject constructor(
|
|||||||
override suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
override suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
db.collection("buffers").add(data!!).await()
|
db.collection("buffers").add(data!!).await()
|
||||||
Response.Success(data.kitno)
|
Response.Success(data!!.kitno)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Firebase.crashlytics.recordException(e)
|
Firebase.crashlytics.recordException(e)
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
@@ -127,16 +66,14 @@ class DatabaseRepository @Inject constructor(
|
|||||||
override suspend fun addDiagnostics(data: DiagnosticsData?): Response<String> {
|
override suspend fun addDiagnostics(data: DiagnosticsData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
db.collection("diagnostics").add(data!!).await()
|
db.collection("diagnostics").add(data!!).await()
|
||||||
Response.Success(data.deviceId)
|
Response.Success(data!!.deviceId)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Firebase.crashlytics.recordException(e)
|
Firebase.crashlytics.recordException(e)
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun uploadFileToStorage(
|
override suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
||||||
patientID: String, filePath: String
|
|
||||||
): Response<Boolean> {
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
val file = Uri.fromFile(File(filePath))
|
val file = Uri.fromFile(File(filePath))
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.example.hpostesting.domain
|
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import okhttp3.Interceptor
|
|
||||||
import okhttp3.Response
|
|
||||||
|
|
||||||
class AuthInterceptor(private val sharedPreferences: SharedPreferences) : Interceptor {
|
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
|
||||||
var request = chain.request()
|
|
||||||
|
|
||||||
val token = sharedPreferences.getString(Constants.ACCESS_TOKEN, null)
|
|
||||||
|
|
||||||
if (token != null) {
|
|
||||||
request = request.newBuilder()
|
|
||||||
.addHeader("Authorization", "Bearer $token")
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
return chain.proceed(request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.example.hpostesting.domain
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class LogFileManager(private val context: Context) {
|
|
||||||
|
|
||||||
fun createLogFile(): File? {
|
|
||||||
val unixTime = System.currentTimeMillis() / 1000L
|
|
||||||
val logFileName = "hpos_$unixTime.log"
|
|
||||||
|
|
||||||
return try {
|
|
||||||
val process = Runtime.getRuntime().exec("logcat -d -v threadtime")
|
|
||||||
val logBuilder = StringBuilder()
|
|
||||||
val input = process.inputStream
|
|
||||||
val bufferedReader = input.bufferedReader()
|
|
||||||
|
|
||||||
bufferedReader.forEachLine { line ->
|
|
||||||
logBuilder.append(line).append("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
val logContent = logBuilder.toString()
|
|
||||||
|
|
||||||
val file = File(context.filesDir, logFileName)
|
|
||||||
val fileOutputStream = FileOutputStream(file)
|
|
||||||
fileOutputStream.write(logContent.toByteArray())
|
|
||||||
fileOutputStream.close()
|
|
||||||
|
|
||||||
file
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,7 @@ package com.example.hpostesting.domain.di
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.content.res.AssetManager
|
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.example.hpostesting.data.api.MolbioAuthApi
|
|
||||||
import com.example.hpostesting.data.api.MolbioResultApi
|
|
||||||
import com.example.hpostesting.data.api.PropertyProvider
|
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.dao.MyDatabase
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
@@ -15,21 +10,13 @@ import com.example.hpostesting.data.datasource.LocalFileDataSource
|
|||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.domain.AuthInterceptor
|
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
import com.example.hpostesting.util.PropertyProviderImpl
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Named
|
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@@ -41,7 +28,9 @@ object AppModule {
|
|||||||
fun provideMyDatabase(@ApplicationContext context: Context): MyDatabase {
|
fun provideMyDatabase(@ApplicationContext context: Context): MyDatabase {
|
||||||
return Room.databaseBuilder(
|
return Room.databaseBuilder(
|
||||||
context, MyDatabase::class.java, "my_database"
|
context, MyDatabase::class.java, "my_database"
|
||||||
).fallbackToDestructiveMigration().build()
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -78,89 +67,13 @@ object AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideDatabaseRepository(
|
fun provideDatabaseRepository(): DatabaseRepository {
|
||||||
@Named("Auth") molbioAuthApi: MolbioAuthApi,
|
return DatabaseRepository()
|
||||||
molbioResultApi: MolbioResultApi
|
|
||||||
): DatabaseRepository {
|
|
||||||
return DatabaseRepository(molbioAuthApi = molbioAuthApi, molbioResultApi = molbioResultApi)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideRepository(
|
fun provideRepository(): Repository {
|
||||||
@Named("Auth") molbioAuthApi: MolbioAuthApi,
|
return DatabaseRepository()
|
||||||
molbioResultApi: MolbioResultApi
|
|
||||||
): Repository {
|
|
||||||
return DatabaseRepository(molbioAuthApi, molbioResultApi)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideAssetManager(@ApplicationContext context: Context): AssetManager {
|
|
||||||
return context.assets
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun providePropertyProvider(assetManager: AssetManager): PropertyProvider {
|
|
||||||
return PropertyProviderImpl(assetManager)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
|
||||||
return context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideAuthInterceptor(sharedPreferences: SharedPreferences): AuthInterceptor {
|
|
||||||
return AuthInterceptor(sharedPreferences)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("Auth")
|
|
||||||
fun provideAuthOkHttpClient(authInterceptor: AuthInterceptor): OkHttpClient {
|
|
||||||
return OkHttpClient.Builder().addInterceptor(authInterceptor)
|
|
||||||
.connectTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideOkHttpClient(): OkHttpClient =
|
|
||||||
OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(30, TimeUnit.SECONDS).build()
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideRetrofit(
|
|
||||||
propertyProvider: PropertyProvider,@Named("Auth") client: OkHttpClient
|
|
||||||
): Retrofit {
|
|
||||||
return Retrofit.Builder().baseUrl(propertyProvider.getProperty("BASE_URL")).client(client)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create()).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("Auth")
|
|
||||||
fun provideAuthRetrofit(propertyProvider: PropertyProvider, client: OkHttpClient): Retrofit {
|
|
||||||
return Retrofit.Builder().baseUrl(propertyProvider.getProperty("BASE_URL")).client(client)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create()).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named("Auth")
|
|
||||||
fun provideAuthApi(@Named("Auth") retrofit: Retrofit): MolbioAuthApi =
|
|
||||||
retrofit.create(MolbioAuthApi::class.java)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideResultApi(retrofit: Retrofit): MolbioResultApi =
|
|
||||||
retrofit.create(MolbioResultApi::class.java)
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideLogFileManager(context: Context): LogFileManager = LogFileManager(context)
|
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val deviceType = when {
|
val deviceType = when {
|
||||||
availableDrivers.isNotEmpty() -> {
|
availableDrivers.isNotEmpty() -> {
|
||||||
val device = availableDrivers[0].device
|
val device = availableDrivers[0].device
|
||||||
Toast.makeText(this, R.string.device, Toast.LENGTH_SHORT).show()
|
|
||||||
when {
|
when {
|
||||||
device.productId == Constants.HOMO_CUBE_ID && device.vendorId == Constants.VENDOR_ID -> {
|
device.productId == Constants.HOMO_CUBE_ID && device.vendorId == Constants.VENDOR_ID -> {
|
||||||
binding.cvItem1.visibility = View.VISIBLE
|
binding.cvItem1.visibility = View.VISIBLE
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
|
|||||||
if (batLevel < 40) {
|
if (batLevel < 40) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
view.context.getString(R.string.low_battery_warning),
|
context?.getString(R.string.low_battery_warning),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
@@ -73,7 +73,7 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
|
|||||||
if (userList.testStatus!!) {
|
if (userList.testStatus!!) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
view.context.getString(R.string.test_already_conducted),
|
context?.getString(R.string.test_already_conducted),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
@@ -81,14 +81,13 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
|
|||||||
if (isBetween15And30Minutes(userList.incubationTime) < Constants.INCUBATION_TIME_MIN) {
|
if (isBetween15And30Minutes(userList.incubationTime) < Constants.INCUBATION_TIME_MIN) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
view.context.getString(R.string.incubation_not_completed),
|
context?.getString(R.string.incubation_not_completed),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} else
|
} else if (isBetween15And30Minutes(userList.incubationTime) > Constants.INCUBATION_TIME_MAX) {
|
||||||
if (isBetween15And30Minutes(userList.incubationTime) > Constants.INCUBATION_TIME_MAX) {
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
view.context.getString(R.string.incubation_crossed_30_minutes),
|
context?.getString(R.string.incubation_crossed_30_minutes),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
@@ -103,7 +102,7 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
|
|||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
view.context.getString(R.string.incubation_not_started),
|
context?.getString(R.string.incubation_not_started),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class UserListAdapter(
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
userCard.setOnClickListener {
|
userCard.setOnClickListener {
|
||||||
if (false) {
|
if (batLevel < Constants.BATTERY_LEVEL_MIN) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
view.context,
|
view.context,
|
||||||
context?.getString(R.string.low_battery_warning),
|
context?.getString(R.string.low_battery_warning),
|
||||||
|
|||||||
@@ -1,46 +1,30 @@
|
|||||||
package com.example.hpostesting.presentation.dashboard
|
package com.example.hpostesting.presentation.dashboard
|
||||||
|
|
||||||
import android.app.DownloadManager
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.FileProvider
|
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.drawerlayout.widget.DrawerLayout
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.navigateUp
|
import androidx.navigation.ui.navigateUp
|
||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.example.hpostesting.data.Result
|
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
|
||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
|
|
||||||
import com.google.firebase.appdistribution.FirebaseAppDistribution
|
import com.google.firebase.appdistribution.FirebaseAppDistribution
|
||||||
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||||
import okhttp3.ResponseBody
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DashboardActivity : AppCompatActivity() {
|
class DashboardActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||||
private lateinit var binding: ActivityDashboardBinding
|
private lateinit var binding: ActivityDashboardBinding
|
||||||
private var downloadId: Long = 0
|
|
||||||
private val hemocubeViewModel: HemoCubeViewModel by viewModels()
|
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context?) {
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
||||||
@@ -55,41 +39,6 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
setSupportActionBar(binding.appBarDashboard.toolbar)
|
setSupportActionBar(binding.appBarDashboard.toolbar)
|
||||||
|
|
||||||
hemocubeViewModel.deviceUpdate.observe(this) { result ->
|
|
||||||
when (result) {
|
|
||||||
is Result.Success -> {
|
|
||||||
// val apkUrl = result.data
|
|
||||||
val apkUrl = "https://dl.dropboxusercontent.com/s/fi/1c3nn7t0co431hicl3hrt/app-debug.apk?rlkey=e4uf13ty1dpcked614vy1aaqp&dl=0"
|
|
||||||
initiateUpdate(apkUrl.toString())
|
|
||||||
Log.d("ApI", "APK URL For App Update: $apkUrl")
|
|
||||||
Toast.makeText(
|
|
||||||
this,
|
|
||||||
"APK UPLOAD ${result.data}",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
// The APK URL LiveData will be updated automatically
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Error -> {
|
|
||||||
result.exception.let { message ->
|
|
||||||
Toast.makeText(this, "An error occurred On Updating App: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Loading -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val drawerLayout: DrawerLayout = binding.drawerLayout
|
val drawerLayout: DrawerLayout = binding.drawerLayout
|
||||||
val navView: NavigationView = binding.navView
|
val navView: NavigationView = binding.navView
|
||||||
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
||||||
@@ -102,8 +51,6 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
navView.setupWithNavController(navController)
|
navView.setupWithNavController(navController)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
@@ -117,82 +64,6 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initiateUpdate(responseBody: String) {
|
|
||||||
// Extract the URL from the ResponseBody
|
|
||||||
val apkUrl = responseBody
|
|
||||||
|
|
||||||
// Check if the extracted APK URL is valid
|
|
||||||
if (!isValidHttpUrl(apkUrl)) {
|
|
||||||
// Handle the case where the URL is not valid
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val request = DownloadManager.Request(Uri.parse(apkUrl))
|
|
||||||
request.setTitle("App Update")
|
|
||||||
request.setDescription("Downloading update...")
|
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
|
||||||
request.setDestinationInExternalFilesDir(this, "Updates", "update.apk")
|
|
||||||
|
|
||||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
|
||||||
downloadId = downloadManager.enqueue(request)
|
|
||||||
|
|
||||||
// Register a BroadcastReceiver to receive the download complete event
|
|
||||||
val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
|
||||||
registerReceiver(downloadReceiver, filter)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to check if a URL has a valid HTTP/HTTPS scheme
|
|
||||||
// Function to extract the APK URL from the ResponseBody
|
|
||||||
private fun extractApkUrl(responseBody: ResponseBody): String {
|
|
||||||
// Assuming your ResponseBody contains the APK URL as a string
|
|
||||||
return responseBody.string()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to check if a URL has a valid HTTP/HTTPS scheme
|
|
||||||
private fun isValidHttpUrl(url: String): Boolean {
|
|
||||||
return url.startsWith("http://") || url.startsWith("https://")
|
|
||||||
}
|
|
||||||
private val downloadReceiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
|
||||||
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
|
||||||
if (id == downloadId) {
|
|
||||||
// Install the downloaded APK
|
|
||||||
installApk()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun installApk() {
|
|
||||||
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
|
||||||
file.setReadable(true, false) // Ensure the file is readable
|
|
||||||
|
|
||||||
val uri: Uri = FileProvider.getUriForFile(
|
|
||||||
this,
|
|
||||||
"com.example.hpostesting.fileprovider",
|
|
||||||
file
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create an intent to install the APK
|
|
||||||
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
|
||||||
installIntent.data = uri
|
|
||||||
installIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
|
||||||
Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
||||||
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
|
||||||
|
|
||||||
// Start the installation
|
|
||||||
startActivity(installIntent)
|
|
||||||
|
|
||||||
Log.d("InstallApk", "Install Intent URI: $uri")
|
|
||||||
Log.d("InstallApk", "Package Name: $packageName")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
unregisterReceiver(downloadReceiver)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
@@ -232,7 +103,4 @@ class DashboardActivity : AppCompatActivity() {
|
|||||||
// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ import android.content.Intent
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.BatteryManager
|
import android.os.BatteryManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Base64
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -17,14 +16,9 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.Result
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
import com.example.hpostesting.presentation.KitScanActivity
|
||||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
||||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||||
@@ -39,7 +33,6 @@ import com.google.firebase.perf.ktx.performance
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||||
import org.json.JSONObject
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@@ -52,7 +45,6 @@ class HomeFragment : Fragment() {
|
|||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
private lateinit var rvAdapter: UserListAdapter
|
private lateinit var rvAdapter: UserListAdapter
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
|
||||||
private var batLevel: Int =
|
private var batLevel: Int =
|
||||||
0 // Initialize with a default value, or obtain the actual battery level
|
0 // Initialize with a default value, or obtain the actual battery level
|
||||||
private lateinit var adapter: OfflineUserListAdapter
|
private lateinit var adapter: OfflineUserListAdapter
|
||||||
@@ -106,7 +98,6 @@ class HomeFragment : Fragment() {
|
|||||||
loadUserData()
|
loadUserData()
|
||||||
setSearch()
|
setSearch()
|
||||||
checkForLocalDBData()
|
checkForLocalDBData()
|
||||||
checkForTokenAndUpdate()
|
|
||||||
} else {
|
} else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
||||||
@@ -116,7 +107,9 @@ class HomeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(), R.string.test_upload, Toast.LENGTH_SHORT
|
requireContext(),
|
||||||
|
R.string.test_upload,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
if (result == "Error") {
|
if (result == "Error") {
|
||||||
@@ -141,137 +134,6 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForTokenAndUpdate() {
|
|
||||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
|
||||||
val natsToken = sharedPreference.getString(Constants.NATS_TOKEN, "").toString()
|
|
||||||
if (accessToken.isEmpty() && natsToken.isEmpty()) {
|
|
||||||
hemoCubeViewModel.login(createLoginRequestData())
|
|
||||||
} else {
|
|
||||||
if (isTokenExpired(accessToken)) {
|
|
||||||
hemoCubeViewModel.login(createLoginRequestData())
|
|
||||||
} else {
|
|
||||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
|
||||||
hemoCubeViewModel.uploadLogs()
|
|
||||||
hemoCubeViewModel.deviceUpdate(createDeviceRequestData())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
|
||||||
when (response) {
|
|
||||||
is Result.Success -> {
|
|
||||||
updateTokens(response)
|
|
||||||
checkForTokenAndUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Error -> {
|
|
||||||
response.exception.let { message ->
|
|
||||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Loading -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.checkUpdate.observe(viewLifecycleOwner) { response ->
|
|
||||||
when (response) {
|
|
||||||
is Result.Success -> {
|
|
||||||
Toast.makeText(
|
|
||||||
requireContext(), response.data.data?.version, Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Error -> {
|
|
||||||
response.exception.let { message ->
|
|
||||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Loading -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response ->
|
|
||||||
when (response) {
|
|
||||||
is Result.Success -> {
|
|
||||||
Toast.makeText(
|
|
||||||
requireContext(),
|
|
||||||
"Log uploaded ${response.data.data?.filename}",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Error -> {
|
|
||||||
response.exception.let { message ->
|
|
||||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Loading -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isTokenExpired(token: String): Boolean {
|
|
||||||
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
|
||||||
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
|
||||||
val jsonPayload = JSONObject(decodedPayload)
|
|
||||||
|
|
||||||
val exp = jsonPayload.optLong("exp", 0)
|
|
||||||
val currentTimeSeconds = System.currentTimeMillis() / 1000
|
|
||||||
|
|
||||||
return exp <= currentTimeSeconds
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateTokens(response: Result.Success<LoginResponse>) {
|
|
||||||
with(sharedPreference.edit()) {
|
|
||||||
putString(Constants.ACCESS_TOKEN, response.data.data?.accessToken)
|
|
||||||
putString(Constants.NATS_TOKEN, response.data.data?.deviceUser?.natsToken)
|
|
||||||
putString(Constants.DEVICE_ID, response.data.data?.deviceUser?.deviceId?.toString())
|
|
||||||
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createLoginRequestData(): LoginRequest {
|
|
||||||
return LoginRequest(
|
|
||||||
password = Constants.devicePassword,
|
|
||||||
serialNumber = Constants.deviceID,
|
|
||||||
username = Constants.deviceID
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createCheckUpdateRequestData(): CheckUpdateRequest {
|
|
||||||
val pInfo = requireActivity().packageManager.getPackageInfo(
|
|
||||||
requireActivity().packageName, 0
|
|
||||||
)
|
|
||||||
val version = pInfo.versionName
|
|
||||||
return CheckUpdateRequest(
|
|
||||||
currentVersion = version
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createDeviceRequestData(): DeviceUpdateRequest {
|
|
||||||
return DeviceUpdateRequest(
|
|
||||||
serial_no = Constants.DEVICE_ID
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setUserId() {
|
private fun setUserId() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
val userId = binding.userId.text.toString()
|
val userId = binding.userId.text.toString()
|
||||||
@@ -279,9 +141,7 @@ class HomeFragment : Fragment() {
|
|||||||
if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
|
if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
|
||||||
hemoCubeViewModel.addUser(
|
hemoCubeViewModel.addUser(
|
||||||
HemoCubeTestData(
|
HemoCubeTestData(
|
||||||
_id = userId,
|
_id = userId, bloodGroup = bloodGroup.toString(), incubationTime = SimpleDateFormat(
|
||||||
bloodGroup = bloodGroup.toString(),
|
|
||||||
incubationTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
).format(Calendar.getInstance().time).toString()
|
).format(Calendar.getInstance().time).toString()
|
||||||
)
|
)
|
||||||
@@ -322,12 +182,8 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
rvAdapter = view?.let {
|
rvAdapter = view?.let {
|
||||||
UserListAdapter(
|
UserListAdapter(
|
||||||
requireContext(),
|
requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||||
hemoCubeViewModel,
|
it, batLevel, requireActivity()
|
||||||
recyclerViewOptions,
|
|
||||||
it,
|
|
||||||
batLevel,
|
|
||||||
requireActivity()
|
|
||||||
)
|
)
|
||||||
}!!
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ class LoginFragment : Fragment() {
|
|||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
||||||
sharedPreference =
|
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.Result
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
@@ -135,32 +133,14 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
showToast(R.string.test_upload)
|
showToast(R.string.test_upload)
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.btnSubmit.visibility = View.GONE
|
binding.btnSubmit.visibility = View.GONE
|
||||||
val i = Intent(
|
val i = Intent(
|
||||||
requireContext().applicationContext,
|
requireContext().applicationContext, DashboardActivity::class.java
|
||||||
DashboardActivity::class.java
|
|
||||||
)
|
)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}
|
|
||||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
|
||||||
when (it) {
|
|
||||||
is Result.Success -> {
|
|
||||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
|
||||||
hemoCubeViewModel.updateMolbioFlag(
|
|
||||||
it1._id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is Result.Error -> {
|
|
||||||
//Remove this line of code while deploying to IOCL
|
|
||||||
it.exception.let { message ->
|
|
||||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == "Local") {
|
if (result == "Local") {
|
||||||
@@ -324,11 +304,11 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
resultData.contains("SNE") && this.testStatusCode < Constants.TEST_STATUS_CODE_CONFIG_COMPLETED -> {
|
resultData.contains("SNE") && this.testStatusCode < Constants.TEST_STATUS_CODE_CONFIG_COMPLETED -> {
|
||||||
val pattern = Regex("HCV-\\d{3}-\\d{4}")
|
val pattern = Regex("HPP1-\\d{4}-\\d{4}")
|
||||||
val matchResult = pattern.find(resultData)
|
val matchResult = pattern.find(resultData)
|
||||||
val hardwareId = matchResult?.value
|
val hardwareId = matchResult?.value
|
||||||
|
|
||||||
if (hardwareId.toString().length == 12) {
|
if (hardwareId.toString().length == 14) {
|
||||||
deviceHardwareId += hardwareId
|
deviceHardwareId += hardwareId
|
||||||
with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
putString(Constants.DEVICE_ID, deviceHardwareId)
|
putString(Constants.DEVICE_ID, deviceHardwareId)
|
||||||
@@ -506,8 +486,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var gradient = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(0)?.get(0)
|
var gradient = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(0)?.get(0)
|
||||||
var constant = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(0)?.get(1)
|
var constant = Constants.DEVICE_CONFIGURATION[deviceHardwareId]?.get(0)?.get(1)
|
||||||
fittedAbs1 = gradient?.times(led1Average)?.plus(constant!!)!!
|
fittedAbs1 = gradient?.times(led1Average)?.plus(constant!!)!!
|
||||||
@@ -625,17 +603,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
if (calculatedRatio != null) {
|
if (calculatedRatio != null) {
|
||||||
if (calculatedRatio < 0.05)
|
if (calculatedRatio < 0.05)
|
||||||
return getString(R.string.error_repeat_test_higher_volume)
|
return getString(R.string.error_repeat_test_higher_volume)
|
||||||
if (calculatedRatio in 0.05..0.155) {
|
if (calculatedRatio in 0.05..0.155)
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.setTextColor(
|
|
||||||
ContextCompat.getColor(
|
|
||||||
requireContext(),
|
|
||||||
R.color.brightGreen
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return getString(R.string.normal)
|
return getString(R.string.normal)
|
||||||
}
|
|
||||||
if (calculatedRatio in 0.155..0.175)
|
if (calculatedRatio in 0.155..0.175)
|
||||||
return getString(R.string.negative_borderline)
|
return getString(R.string.negative_borderline)
|
||||||
if (calculatedRatio in 0.175..0.22)
|
if (calculatedRatio in 0.175..0.22)
|
||||||
@@ -661,17 +630,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
try {
|
try {
|
||||||
hemoCubeViewModel.messages.postValue("result classification")
|
hemoCubeViewModel.messages.postValue("result classification")
|
||||||
if (predictedDenovixRatio != null) {
|
if (predictedDenovixRatio != null) {
|
||||||
if (predictedDenovixRatio in 0.0..0.16) {
|
if (predictedDenovixRatio in 0.0..0.16)
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.setTextColor(
|
|
||||||
ContextCompat.getColor(
|
|
||||||
requireContext(),
|
|
||||||
R.color.brightGreen
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return getString(R.string.normal)
|
return getString(R.string.normal)
|
||||||
}
|
|
||||||
if (predictedDenovixRatio in 0.16..0.165)
|
if (predictedDenovixRatio in 0.16..0.165)
|
||||||
return getString(R.string.negative_borderline)
|
return getString(R.string.negative_borderline)
|
||||||
if (predictedDenovixRatio in 0.165..0.235)
|
if (predictedDenovixRatio in 0.165..0.235)
|
||||||
|
|||||||
@@ -1,46 +1,31 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube
|
package com.example.hpostesting.presentation.hemocube
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.BatteryManager
|
import android.os.BatteryManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.data.Result
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
|
||||||
import com.example.hpostesting.data.model.log.UploadLogsResponse
|
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2Result
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultResponse
|
|
||||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragmentDirections.Companion
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|
||||||
import okhttp3.MultipartBody
|
|
||||||
import okhttp3.RequestBody.Companion.asRequestBody
|
|
||||||
import okhttp3.ResponseBody
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -50,37 +35,20 @@ import javax.inject.Inject
|
|||||||
class HemoCubeViewModel @Inject constructor(
|
class HemoCubeViewModel @Inject constructor(
|
||||||
private val hemoCubeDao: HemoCubeDao,
|
private val hemoCubeDao: HemoCubeDao,
|
||||||
private val repository: Repository,
|
private val repository: Repository,
|
||||||
private val databaseRepository: DatabaseRepository,
|
context: Context,
|
||||||
private val logFileManager: LogFileManager,
|
|
||||||
context: Context
|
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
||||||
val messages = MutableLiveData<String>()
|
val messages = MutableLiveData<String>()
|
||||||
private val sharedPreference: SharedPreferences =
|
private val sharedPreference: SharedPreferences =
|
||||||
context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val deviceProvisionResponse = MutableLiveData<Result<DeviceProvisionResponse>>()
|
|
||||||
|
|
||||||
val loginResponse = MutableLiveData<Result<LoginResponse>>()
|
|
||||||
|
|
||||||
val resultUpload = MutableLiveData<Result<MolbioV2ResultResponse>>()
|
|
||||||
|
|
||||||
val checkUpdate = MutableLiveData<Result<CheckUpdateResponse>>()
|
|
||||||
|
|
||||||
val deviceUpdate = MutableLiveData<Result<ResponseBody>>()
|
|
||||||
|
|
||||||
val uploadLogs = MutableLiveData<Result<UploadLogsResponse>?>()
|
|
||||||
|
|
||||||
|
|
||||||
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
|
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
|
||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
val allUserData = hemoCubeDao.getAll()
|
val allUserData = hemoCubeDao.getAll()
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
|
|
||||||
|
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
val networkStatusLiveData: LiveData<Boolean>
|
||||||
get() = _networkStatusLiveData
|
get() = _networkStatusLiveData
|
||||||
val deviceMessages = MutableLiveData<String?>()
|
val deviceMessages = MutableLiveData<String?>()
|
||||||
@@ -93,8 +61,11 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun uploadHemoCubeResultToDatabase(
|
fun uploadHemoCubeResultToDatabase(
|
||||||
isOnline: Boolean, testStatus: Boolean, kitSerial: String?
|
isOnline: Boolean,
|
||||||
) = viewModelScope.launch {
|
testStatus: Boolean,
|
||||||
|
kitSerial: String?
|
||||||
|
) =
|
||||||
|
viewModelScope.launch {
|
||||||
if (kitSerial != null) {
|
if (kitSerial != null) {
|
||||||
testDetails?.kitSerial = kitSerial
|
testDetails?.kitSerial = kitSerial
|
||||||
}
|
}
|
||||||
@@ -117,54 +88,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deviceProvision(deviceProvisionRequest: DeviceProvisionRequest) = viewModelScope.launch {
|
|
||||||
deviceProvisionResponse.postValue(Result.Loading())
|
|
||||||
databaseRepository.deviceProvision(deviceProvisionRequest).let {
|
|
||||||
deviceProvisionResponse.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun login(loginRequest: LoginRequest) = viewModelScope.launch {
|
|
||||||
loginResponse.postValue(Result.Loading())
|
|
||||||
databaseRepository.login(loginRequest).let {
|
|
||||||
loginResponse.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun uploadResult(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
|
||||||
resultUpload.postValue(Result.Loading())
|
|
||||||
databaseRepository.uploadResults(molbioV2ResultRequest).let {
|
|
||||||
resultUpload.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
|
||||||
checkUpdate.postValue(Result.Loading())
|
|
||||||
databaseRepository.checkUpdate(checkUpdateRequest).let {
|
|
||||||
checkUpdate.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deviceUpdate(deviceUpdateRequest: DeviceUpdateRequest) = viewModelScope.launch {
|
|
||||||
deviceUpdate.postValue(Result.Loading())
|
|
||||||
databaseRepository.deviceUpdate(deviceUpdateRequest).let {
|
|
||||||
deviceUpdate.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun uploadLogs() = viewModelScope.launch {
|
|
||||||
uploadLogs.postValue(Result.Loading())
|
|
||||||
val logFile = logFileManager.createLogFile().let { file ->
|
|
||||||
val requestBody = file?.asRequestBody("multipart/form-data".toMediaTypeOrNull())
|
|
||||||
val multipartFile =
|
|
||||||
requestBody?.let { MultipartBody.Part.createFormData("logFile", file?.name, it) }
|
|
||||||
multipartFile?.let { partFile ->
|
|
||||||
databaseRepository.uploadLogs(partFile).let { result ->
|
|
||||||
uploadLogs.postValue(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun uploadHemoCubeResultToDatabaseforbuffercheckN(bufferCheckData: BufferCheckData) =
|
fun uploadHemoCubeResultToDatabaseforbuffercheckN(bufferCheckData: BufferCheckData) =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@@ -208,11 +131,14 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||||
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
||||||
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
||||||
testDetails?.prdClassification = DataHolder.hemoCubeTestData?.prdClassification.toString()
|
testDetails?.prdClassification =
|
||||||
|
DataHolder.hemoCubeTestData?.prdClassification.toString()
|
||||||
testDetails?.batteryLevel = DataHolder.hemoCubeTestData?.batteryLevel.toString()
|
testDetails?.batteryLevel = DataHolder.hemoCubeTestData?.batteryLevel.toString()
|
||||||
testDetails?.batteryCapacity = DataHolder.hemoCubeTestData?.batteryCapacity.toString()
|
testDetails?.batteryCapacity = DataHolder.hemoCubeTestData?.batteryCapacity.toString()
|
||||||
testDetails?.batteryMaxCapacity = DataHolder.hemoCubeTestData?.batteryMaxCapacity.toString()
|
testDetails?.batteryMaxCapacity =
|
||||||
testDetails?.batteryTemperature = DataHolder.hemoCubeTestData?.batteryTemperature.toString()
|
DataHolder.hemoCubeTestData?.batteryMaxCapacity.toString()
|
||||||
|
testDetails?.batteryTemperature =
|
||||||
|
DataHolder.hemoCubeTestData?.batteryTemperature.toString()
|
||||||
testDetails?.batteryVoltage = DataHolder.hemoCubeTestData?.batteryVoltage.toString()
|
testDetails?.batteryVoltage = DataHolder.hemoCubeTestData?.batteryVoltage.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +159,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
testDetails.localFlag = true
|
testDetails.localFlag = true
|
||||||
uploadResult(MolbioV2ResultRequest(listOf(MolbioV2Result(rawData = testDetails))))
|
|
||||||
hemoCubeDao.insertAll(testDetails)
|
hemoCubeDao.insertAll(testDetails)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,8 +167,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
fireBaseUpload.postValue("Error")
|
fireBaseUpload.postValue("Error")
|
||||||
hemoCubeDao.insertAll(testDetails)
|
hemoCubeDao.insertAll(testDetails)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
@@ -252,11 +175,13 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun addResultTestToDbforbuffercheck(bufferCheckData: BufferCheckData) {
|
private fun addResultTestToDbforbuffercheck(bufferCheckData: BufferCheckData) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
when (val response = repository.addTestToDatabaseforBufferCheck(bufferCheckData)) {
|
when (val response =
|
||||||
|
repository.addTestToDatabaseforBufferCheck(bufferCheckData)) {
|
||||||
is Response.Success -> {
|
is Response.Success -> {
|
||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
@@ -266,8 +191,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||||
fireBaseUpload.postValue("Error")
|
fireBaseUpload.postValue("Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
@@ -298,10 +221,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
hemoCubeDao.updateFieldById(id = userId, true)
|
hemoCubeDao.updateFieldById(id = userId, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateMolbioFlag(userId: String) = viewModelScope.launch {
|
|
||||||
hemoCubeDao.updateFieldById(id = userId, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addUser(userData: HemoCubeTestData) = viewModelScope.launch {
|
fun addUser(userData: HemoCubeTestData) = viewModelScope.launch {
|
||||||
hemoCubeDao.insertAll(userData)
|
hemoCubeDao.insertAll(userData)
|
||||||
}
|
}
|
||||||
@@ -322,7 +241,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun getBatteryTemperature(): Float? {
|
fun getBatteryTemperature(): Float? {
|
||||||
val batteryTemp: Float? = batteryStatus?.let { intent ->
|
val batteryTemp: Float? = batteryStatus?.let { intent ->
|
||||||
val temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)
|
val temperature = intent?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0) ?: 0
|
||||||
temperature.toFloat() / 10
|
temperature.toFloat() / 10
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,18 +259,22 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun getBatteryCapacity(context: Context): Int {
|
fun getBatteryCapacity(context: Context): Int {
|
||||||
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||||
|
val currentCapacity =
|
||||||
|
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
|
||||||
|
|
||||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
|
return currentCapacity
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBatteryMaxCapacity(context: Context): Float {
|
fun getBatteryMaxCapacity(context: Context): Float {
|
||||||
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||||
val designCapacity = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
val designCapacity =
|
||||||
|
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
val currentCapacity =
|
val currentCapacity =
|
||||||
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
|
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER)
|
||||||
|
|
||||||
// Calculate the estimated maximum battery capacity in mAh
|
// Calculate the estimated maximum battery capacity in mAh
|
||||||
|
val maxCapacity = currentCapacity.toFloat() / designCapacity.toFloat() * 100
|
||||||
|
|
||||||
return currentCapacity.toFloat() / designCapacity.toFloat() * 100
|
return maxCapacity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.example.hpostesting.util
|
|
||||||
|
|
||||||
import android.content.res.AssetManager
|
|
||||||
import com.example.hpostesting.data.api.PropertyProvider
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.util.Properties
|
|
||||||
|
|
||||||
class PropertyProviderImpl (private val assetManager: AssetManager) : PropertyProvider {
|
|
||||||
override fun getProperty(key: String): String {
|
|
||||||
val inputStream: InputStream = assetManager.open("app.properties")
|
|
||||||
val properties = Properties()
|
|
||||||
properties.load(inputStream)
|
|
||||||
return properties.getProperty(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,8 +9,6 @@
|
|||||||
<color name="white">#FFFFFFFF</color>
|
<color name="white">#FFFFFFFF</color>
|
||||||
<color name="gray">#808080</color>
|
<color name="gray">#808080</color>
|
||||||
|
|
||||||
<color name="brightGreen">#00FF00</color>
|
|
||||||
<color name="red">#FF0000</color>
|
|
||||||
<color name="blue_app">#4daaff</color>
|
<color name="blue_app">#4daaff</color>
|
||||||
<color name="blue_app_dark">#005db3</color>
|
<color name="blue_app_dark">#005db3</color>
|
||||||
<color name="blue_app_light">#e5f3ff</color>
|
<color name="blue_app_light">#e5f3ff</color>
|
||||||
@@ -19,7 +17,7 @@
|
|||||||
<color name="primary">#4daaff</color>
|
<color name="primary">#4daaff</color>
|
||||||
<color name="primary_dark">#005db3</color>
|
<color name="primary_dark">#005db3</color>
|
||||||
<color name="primary_light">#e5f3ff</color>
|
<color name="primary_light">#e5f3ff</color>
|
||||||
|
<color name="red">#FF0000</color>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,6 @@
|
|||||||
<string name="permission_grant">You must grant permission to access all files to use the app</string>
|
<string name="permission_grant">You must grant permission to access all files to use the app</string>
|
||||||
<string name="permission_required">All permissions are required to use the app.</string>
|
<string name="permission_required">All permissions are required to use the app.</string>
|
||||||
<string name="device_not">Device Not Connected.</string>
|
<string name="device_not">Device Not Connected.</string>
|
||||||
<string name="device">Device is Connected.</string>
|
|
||||||
<string name="enter_proper_login_id">Please enter a proper Login ID</string>
|
<string name="enter_proper_login_id">Please enter a proper Login ID</string>
|
||||||
<string name="enter_proper_password">Please enter a proper password</string>
|
<string name="enter_proper_password">Please enter a proper password</string>
|
||||||
<string name="wrong_password">Wrong Password</string>
|
<string name="wrong_password">Wrong Password</string>
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<external-files-path name="Updates" path="." />
|
|
||||||
</paths>
|
|
||||||
Reference in New Issue
Block a user