Compare commits
2 Commits
api
...
navigation
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b22de3cf8b | ||
|
|
0b6d78dfbb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,7 +1,6 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/misc.xml
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
|
||||
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -7,7 +7,6 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="Embedded JDK" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
6
.idea/kotlinc.xml
generated
6
.idea/kotlinc.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.8.21" />
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/misc.xml
generated
10
.idea/misc.xml
generated
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_auto_graph_24.xml" value="0.1555" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_cancel_24.xml" value="0.1965" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_check_circle_24.xml" value="0.243" />
|
||||
<entry key="app/src/main/res/drawable/ic_baseline_dot_24.xml" value="0.1785" />
|
||||
@@ -19,12 +19,10 @@
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.165" />
|
||||
<entry key="app/src/main/res/layout/activity_splash.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/activity_test_right.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/fragment_graph.xml" value="0.19791666666666666" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_reference.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_sample.xml" value="0.24583333333333332" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_scanner.xml" value="0.24583333333333332" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_exp_sample.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_process.xml" value="0.24375" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_results.xml" value="0.30512820512820515" />
|
||||
<entry key="app/src/main/res/layout/fragment_test_right_results.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/layout/table_item.xml" value="0.22407407407407406" />
|
||||
<entry key="app/src/main/res/menu/menu.xml" value="0.25" />
|
||||
<entry key="app/src/main/res/menu/my_menu.xml" value="0.25" />
|
||||
@@ -33,7 +31,7 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -2,23 +2,19 @@ plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'com.google.firebase.appdistribution'
|
||||
id 'dagger.hilt.android.plugin'
|
||||
id 'com.google.gms.google-services'
|
||||
id 'androidx.navigation.safeargs.kotlin'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
//apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdk 33
|
||||
namespace 'in.sminnovations.hpostesting'
|
||||
compileSdk 32
|
||||
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting.prod"
|
||||
applicationId "com.example.hpos"
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 2
|
||||
versionName "2.0.1"
|
||||
targetSdk 32
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -30,85 +26,41 @@ android {
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '17'
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
dataBinding {
|
||||
enabled = true
|
||||
}
|
||||
lintOptions {
|
||||
checkReleaseBuilds false
|
||||
// Or, if you prefer, you can continue to check for errors in release builds,
|
||||
// but continue the build even when errors are found:
|
||||
abortOnError false
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.10.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'com.google.android.material:material:1.9.0'
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
||||
|
||||
//firebase
|
||||
implementation platform('com.google.firebase:firebase-bom:32.1.0')
|
||||
implementation 'com.google.firebase:firebase-firestore-ktx'
|
||||
implementation 'com.google.firebase:firebase-auth-ktx'
|
||||
implementation 'com.google.firebase:firebase-storage-ktx'
|
||||
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
|
||||
implementation 'com.google.android.gms:play-services-auth:20.5.0'
|
||||
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
||||
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
||||
|
||||
// Testing
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
||||
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
|
||||
implementation 'com.opencsv:opencsv:4.6'
|
||||
implementation 'com.github.mik3y:usb-serial-for-android:3.4.6'
|
||||
|
||||
implementation "androidx.fragment:fragment-ktx:1.6.0"
|
||||
implementation "androidx.fragment:fragment-ktx:1.5.5"
|
||||
|
||||
// CSV read, write
|
||||
implementation 'com.opencsv:opencsv:4.6'
|
||||
|
||||
// Barcode scanner
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
// implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
// implementation "androidx.core:core-ktx:+"
|
||||
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
// Google ML Kit usign play services
|
||||
implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'
|
||||
|
||||
//Room
|
||||
implementation "androidx.room:room-ktx:2.6.0-alpha01"
|
||||
implementation "androidx.room:room-runtime:2.6.0-alpha01"
|
||||
kapt ("androidx.room:room-compiler:2.6.0-alpha01")
|
||||
|
||||
//image
|
||||
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
|
||||
|
||||
// Navigation Component
|
||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.0-beta01"
|
||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.0-beta01"
|
||||
|
||||
//Dagger - Hilt
|
||||
implementation "com.google.dagger:hilt-android:2.46"
|
||||
kapt "com.google.dagger:hilt-android-compiler:2.46"
|
||||
kapt "androidx.hilt:hilt-compiler:1.0.0"
|
||||
|
||||
// Retrofit + GSON
|
||||
implementation "com.squareup.retrofit2:retrofit:2.9.0"
|
||||
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
|
||||
|
||||
}
|
||||
}
|
||||
//repositories {
|
||||
// mavenCentral()
|
||||
//}
|
||||
Binary file not shown.
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.example.hpos",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.example.hpostesting
|
||||
package com.example.hpos
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.*
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
@@ -1,21 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.example.hpos">
|
||||
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
@@ -23,59 +15,43 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/hpos_icon_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.HPOSTesting"
|
||||
android:theme="@style/Theme.HPOS"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.KitScanActivity"
|
||||
android:noHistory="true"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"/>
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.dashboard.DashboardActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_dashboard"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar" />
|
||||
|
||||
<service
|
||||
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
||||
android:name="com.example.hpos.presentation.testRight.UsbService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.SplashActivity"
|
||||
android:name="com.example.hpos.presentation.SplashActivity"
|
||||
android:exported="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.testRight.TestRightActivity"
|
||||
android:name="com.example.hpos.presentation.testRight.TestRightActivity"
|
||||
android:exported="false"
|
||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:noHistory="true"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar">
|
||||
android:parentActivityName="com.example.hpos.presentation.MainActivity">
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />-->
|
||||
<!-- </intent-filter>-->
|
||||
|
||||
<!-- <intent-filter> -->
|
||||
<!-- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> -->
|
||||
<!-- </intent-filter> -->
|
||||
<!-- <meta-data-->
|
||||
<!-- android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"-->
|
||||
<!-- android:resource="@xml/device_filter" />-->
|
||||
</activity>
|
||||
|
||||
|
||||
<!-- <meta-data -->
|
||||
<!-- android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" -->
|
||||
<!-- android:resource="@xml/device_filter" /> -->
|
||||
</activity> <!-- android:theme="@style/Theme.HPOS.ActionBar" -->
|
||||
<!-- android:theme="@style/Theme.HPOS.ActionBar"-->
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.MainActivity"
|
||||
android:exported="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
android:name="com.example.hpos.presentation.MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||
</intent-filter>
|
||||
@@ -83,12 +59,8 @@
|
||||
<meta-data
|
||||
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
||||
android:resource="@xml/device_filter" />
|
||||
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:stateNotNeeded="true"
|
||||
tools:replace="android:screenOrientation" />
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
11
app/src/main/java/com/example/hpos/MyApplication.kt
Normal file
11
app/src/main/java/com/example/hpos/MyApplication.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.example.hpos
|
||||
|
||||
import android.app.Application
|
||||
|
||||
class MyApplication : Application() {
|
||||
|
||||
// private val sampleDetails = PatientDetails("Change it later");
|
||||
// fun getSampleDetails() : PatientDetails = sampleDetails
|
||||
// fun setSampleDetails(sample: SampleDetails) {sampleDetails = sample}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.example.hpostesting.data
|
||||
package com.example.hpos.data
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.test.TestRightDeviceConstants
|
||||
import com.example.hpostesting.data.model.test.TestType
|
||||
import com.example.hpos.data.model.TestRightDeviceConstants
|
||||
import com.example.hpos.data.model.TestType
|
||||
|
||||
object DataHolder {
|
||||
|
||||
@@ -11,8 +10,6 @@ object DataHolder {
|
||||
|
||||
val usbConnected = MutableLiveData(true)
|
||||
|
||||
var mobileUniqueId: String? = null
|
||||
|
||||
var isStoragePermissionGranted = false
|
||||
var isAppFolderCreated = false
|
||||
var appFolderPath = ""
|
||||
@@ -27,14 +24,4 @@ object DataHolder {
|
||||
|
||||
/* (For reference/baseline) Contains pixel no. -> Intensity of light falling on that pixel */
|
||||
val intensityReferenceArray = ArrayList<Double>()
|
||||
|
||||
var selectedTest: UserData? = null
|
||||
|
||||
var kitSerial: String = ""
|
||||
|
||||
var location: UserData.Location? = null
|
||||
|
||||
var testExp: Boolean = true
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data
|
||||
package com.example.hpos.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
7
app/src/main/java/com/example/hpos/data/Repository.kt
Normal file
7
app/src/main/java/com/example/hpos/data/Repository.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.example.hpos.data
|
||||
|
||||
import com.example.hpos.data.model.TestInfo
|
||||
|
||||
interface Repository {
|
||||
suspend fun saveToDatabase(info: TestInfo)
|
||||
}
|
||||
12
app/src/main/java/com/example/hpos/data/RepositoryImpl.kt
Normal file
12
app/src/main/java/com/example/hpos/data/RepositoryImpl.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.example.hpos.data
|
||||
|
||||
import com.example.hpos.data.model.TestInfo
|
||||
|
||||
class RepositoryImpl : Repository {
|
||||
|
||||
override suspend fun saveToDatabase(info: TestInfo) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.example.hpostesting.data.constant
|
||||
package com.example.hpos.data.constant
|
||||
|
||||
object Constants {
|
||||
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
||||
|
||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||
|
||||
const val WRITE_TIMEOUT_MILLIS = 30000 // 30 sec
|
||||
const val READ_TIMEOUT_MILLIS = 60000 // 1 min
|
||||
const val DELAY_BETWEEN_COMMANDS: Long = 1000
|
||||
|
||||
const val TEST_RIGHT_TOTAL_PIXEL = 3694
|
||||
|
||||
const val MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE = 40
|
||||
const val MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE = 9999
|
||||
|
||||
const val RANGE_IN_RESULT_CALCULATIONS = 10
|
||||
|
||||
@@ -28,18 +26,4 @@ object Constants {
|
||||
const val ERROR_CRITICAL = 401
|
||||
|
||||
const val NO_OF_TIMES_TO_RUN_SAMPLE = 1
|
||||
|
||||
const val USER_ID = "usernameId"
|
||||
|
||||
val STATICID = listOf(
|
||||
"VIZ-1000-0004",
|
||||
"VIZ-1000-0005",
|
||||
"VIZ-1000-0006",
|
||||
)
|
||||
|
||||
const val password = "SMI@12345"
|
||||
|
||||
const val BASE_URL = "https://datacollection.micropcr.com/v1/"
|
||||
|
||||
const val TOKEN = "molbioToken"
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.constant
|
||||
package com.example.hpos.data.constant
|
||||
|
||||
enum class TestRightCommands(val command: String) {
|
||||
led2Set50("led2 50\r"),
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class CalculationVariableForTest(
|
||||
var pixelNo: Int,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class ErrorMessage (
|
||||
val message: String,
|
||||
@@ -1,6 +1,4 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class PatientData(
|
||||
val name: String,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model.test
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class TestInfo(
|
||||
val value: String,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model.test
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class TestRightCalculationData(
|
||||
var absorbanceOne: Double?,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model.test
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class TestRightDeviceConstants(
|
||||
var a: String,
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.example.hpostesting.data.model.test
|
||||
package com.example.hpos.data.model
|
||||
|
||||
enum class TestRightResultType {
|
||||
NORMAL,
|
||||
SICKLECELLTRAIT,
|
||||
SICKLECELLDISEASE,
|
||||
POSITIVEBORDERLINE,
|
||||
NEGATIVEBORDERLINE,
|
||||
UNDEFINED
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.data.model.test
|
||||
package com.example.hpos.data.model
|
||||
|
||||
enum class TestType {
|
||||
SICKLECERT,
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
|
||||
class ResultCalculationWithAvgImpl : TestRightResultCalculation {
|
||||
|
||||
private val testRightCalculationData = TestRightCalculationData()
|
||||
|
||||
override fun getResults(wavelengthToAbsorbance: ArrayList<ArrayList<Double>>): TestRightCalculationData {
|
||||
|
||||
val startWavelengthOne =
|
||||
Constants.WAVELENGTH_OF_INTEREST_ONE - Constants.RANGE_IN_RESULT_CALCULATIONS
|
||||
val endWavelengthOne =
|
||||
Constants.WAVELENGTH_OF_INTEREST_ONE + Constants.RANGE_IN_RESULT_CALCULATIONS + 1
|
||||
var sumOfAbsorbanceAtOne = 0.0
|
||||
var noOfAbsorbanceRecordedOne = 0
|
||||
|
||||
val startWavelengthTwo =
|
||||
Constants.WAVELENGTH_OF_INTEREST_TWO - Constants.RANGE_IN_RESULT_CALCULATIONS
|
||||
val endWavelengthTwo =
|
||||
Constants.WAVELENGTH_OF_INTEREST_TWO + Constants.RANGE_IN_RESULT_CALCULATIONS + 1
|
||||
var sumOfAbsorbanceAtTwo = 0.0
|
||||
var noOfAbsorbanceRecordedTwo = 0
|
||||
|
||||
for (each in wavelengthToAbsorbance) {
|
||||
if (each[0] >= startWavelengthOne && each[0] < endWavelengthOne) {
|
||||
sumOfAbsorbanceAtOne += each[1]
|
||||
noOfAbsorbanceRecordedOne++
|
||||
}
|
||||
if (each[0] >= startWavelengthTwo && each[0] < endWavelengthTwo) {
|
||||
sumOfAbsorbanceAtTwo += each[1]
|
||||
noOfAbsorbanceRecordedTwo++
|
||||
}
|
||||
}
|
||||
|
||||
val avgAbsorbanceOne = (sumOfAbsorbanceAtOne / noOfAbsorbanceRecordedOne)
|
||||
val avgAbsorbanceTwo = (sumOfAbsorbanceAtTwo / noOfAbsorbanceRecordedTwo)
|
||||
|
||||
testRightCalculationData.absorbanceOne = avgAbsorbanceOne
|
||||
testRightCalculationData.absorbanceTwo = avgAbsorbanceTwo
|
||||
|
||||
testRightCalculationData.result = calculateResultsAndRatio(avgAbsorbanceOne, avgAbsorbanceTwo)
|
||||
return testRightCalculationData
|
||||
}
|
||||
|
||||
private fun calculateResultsAndRatio(
|
||||
absorbanceAtWaveOne: Double,
|
||||
absorbanceAtWaveTwo: Double
|
||||
): TestRightResultType {
|
||||
|
||||
if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) {
|
||||
val value = absorbanceAtWaveTwo / absorbanceAtWaveOne
|
||||
testRightCalculationData.ratioValue = value
|
||||
|
||||
if (value < 0.24 || value == 0.0) {
|
||||
testRightCalculationData.ratioMinRange = 0.0
|
||||
testRightCalculationData.ratioMaxRange = 0.24
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value >= 0.24 && value < 0.30) {
|
||||
testRightCalculationData.ratioMinRange = 0.24
|
||||
testRightCalculationData.ratioMaxRange = 0.30
|
||||
return TestRightResultType.SICKLECELLTRAIT
|
||||
} else if (value >= 0.30) {
|
||||
testRightCalculationData.ratioMinRange = 0.30
|
||||
testRightCalculationData.ratioMaxRange = 999.0
|
||||
return TestRightResultType.SICKLECELLDISEASE
|
||||
}
|
||||
}
|
||||
|
||||
return TestRightResultType.UNDEFINED
|
||||
|
||||
// if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) {
|
||||
// val value = absorbanceAtWaveTwo / absorbanceAtWaveOne
|
||||
//
|
||||
// if (value < 0.24 || value == 0.0) {
|
||||
// return TestRightResultType.NORMAL
|
||||
// } else if (value >= 0.24 && value < 0.30) {
|
||||
// return TestRightResultType.SICKLECELLTRAIT
|
||||
// } else if (value >= 0.30) {
|
||||
// return TestRightResultType.SICKLECELLDISEASE
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
// return TestRightResultType.UNDEFINED
|
||||
// Log.d(TAG, "value = $value")
|
||||
// println("value = $value")
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.example.hpos.domain
|
||||
|
||||
import android.util.Log
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import kotlin.math.log10
|
||||
|
||||
class ResultCalculationWithFirstImpl {
|
||||
|
||||
private val TAG = "Testright"
|
||||
|
||||
fun getResults(
|
||||
wavelengthToPixelArray: ArrayList<ArrayList<Double>>,
|
||||
intensityReferenceArray: ArrayList<ArrayList<Double>>,
|
||||
intensitySampleArray: ArrayList<ArrayList<Double>>
|
||||
) : TestRightResultType {
|
||||
var pixelNoWithWave_427 = 0
|
||||
var pixelNoWithWave_555 = 0
|
||||
|
||||
Log.d(TAG, "wavelengthToPixelArray size = ${wavelengthToPixelArray.size}")
|
||||
// println("wavelengthToPixelArray size = ${wavelengthToPixelArray.size}")
|
||||
for (each in wavelengthToPixelArray) {
|
||||
var diff = each[0] - 427
|
||||
if (pixelNoWithWave_427 == 0 && diff >= 0 && diff < 1) {
|
||||
pixelNoWithWave_427 = each[1].toInt()
|
||||
}
|
||||
|
||||
diff = each[0] - 555
|
||||
if (pixelNoWithWave_555 == 0 && diff >= 0 && diff < 1) {
|
||||
pixelNoWithWave_555 = each[1].toInt()
|
||||
}
|
||||
|
||||
if (pixelNoWithWave_427 != 0 && pixelNoWithWave_555 != 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "pixelOfInterest_427 = ${pixelNoWithWave_427}")
|
||||
Log.d(TAG, "pixelOfInterest_555 = ${pixelNoWithWave_555}")
|
||||
|
||||
// println("pixelOfInterest_427 = ${pixelNoWithWave_427}")
|
||||
// println("pixelOfInterest_555 = ${pixelNoWithWave_555}")
|
||||
|
||||
val invertedPixel_427 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_427
|
||||
val invertedPixel_555 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_555
|
||||
|
||||
var io_427 = 0.0
|
||||
var io_555 = 0.0
|
||||
|
||||
for (each in intensityReferenceArray) {
|
||||
if (each[0].toInt() == invertedPixel_427) {
|
||||
io_427 = each[1]
|
||||
}
|
||||
if (each[0].toInt() == invertedPixel_555) {
|
||||
io_555 = each[1]
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "I0 values are I0_427 = $io_427 , IO_555 = $io_555")
|
||||
// println("I0 values are I0_427 = $io_427 , IO_555 = $io_555")
|
||||
|
||||
var i_427 = 0.0
|
||||
var i_555 = 0.0
|
||||
|
||||
for (each in intensitySampleArray) {
|
||||
if (each[0].toInt() == invertedPixel_427) {
|
||||
i_427 = each[1]
|
||||
}
|
||||
if (each[0].toInt() == invertedPixel_555) {
|
||||
i_555 = each[1]
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "I values are I_427 = $i_427 , I_555 = $i_555")
|
||||
// println("I values are I_427 = $i_427 , I_555 = $i_555")
|
||||
|
||||
val absorbanceAtPixelWithWave_427 = log10(io_427 / i_427)
|
||||
val absorbanceAtPixelWithWave_555 = log10(io_555 / i_555)
|
||||
Log.d(
|
||||
TAG,
|
||||
"absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555"
|
||||
)
|
||||
// println("absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555")
|
||||
|
||||
var value = 0.0
|
||||
if (absorbanceAtPixelWithWave_427 != 0.0 && absorbanceAtPixelWithWave_555 != 0.0) {
|
||||
value = absorbanceAtPixelWithWave_555 / absorbanceAtPixelWithWave_427
|
||||
}
|
||||
Log.d(TAG, "value = $value")
|
||||
// println("value = $value")
|
||||
|
||||
|
||||
if (value < 0.24 || value == 0.0) {
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value >= 0.24 && value < 0.30) {
|
||||
return TestRightResultType.SICKLECELLTRAIT
|
||||
} else if (value >= 0.30) {
|
||||
return TestRightResultType.SICKLECELLDISEASE
|
||||
}
|
||||
return TestRightResultType.UNDEFINED
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.example.hpostesting.domain
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.test.TestRightCalculationData
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
|
||||
class ResultCalculationWithMaxImpl : TestRightResultCalculation {
|
||||
|
||||
@@ -57,24 +57,24 @@ class ResultCalculationWithMaxImpl : TestRightResultCalculation {
|
||||
val value = absorbanceAtWaveTwo / absorbanceAtWaveOne
|
||||
testRightCalculationData.ratioValue = value
|
||||
|
||||
if (value <= 0.29) {
|
||||
if (value < 0.28 || value == 0.0) {
|
||||
testRightCalculationData.ratioMinRange = 0.0
|
||||
testRightCalculationData.ratioMaxRange = 0.29
|
||||
testRightCalculationData.ratioMaxRange = 0.28
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value > 0.29 && value <= 0.32) {
|
||||
testRightCalculationData.ratioMinRange = 0.29
|
||||
testRightCalculationData.ratioMaxRange = 0.32
|
||||
return TestRightResultType.NEGATIVEBORDERLINE
|
||||
} else if (value > 0.32 && value <= 0.50) {
|
||||
testRightCalculationData.ratioMinRange = 0.32
|
||||
testRightCalculationData.ratioMaxRange = 0.50
|
||||
} else if (value >= 0.28 && value < 0.285) {
|
||||
testRightCalculationData.ratioMinRange = 0.28
|
||||
testRightCalculationData.ratioMaxRange = 0.285
|
||||
return TestRightResultType.UNDEFINED
|
||||
} else if (value >= 0.285 && value < 0.52) {
|
||||
testRightCalculationData.ratioMinRange = 0.285
|
||||
testRightCalculationData.ratioMaxRange = 0.52
|
||||
return TestRightResultType.SICKLECELLTRAIT
|
||||
} else if (value > 0.50 && value <= 0.55) {
|
||||
testRightCalculationData.ratioMinRange = 0.50
|
||||
testRightCalculationData.ratioMaxRange = 0.55
|
||||
return TestRightResultType.POSITIVEBORDERLINE
|
||||
}else if (value > 0.55) {
|
||||
testRightCalculationData.ratioMinRange = 0.55
|
||||
} else if (value >= 0.52 && value < 0.525) {
|
||||
testRightCalculationData.ratioMinRange = 0.52
|
||||
testRightCalculationData.ratioMaxRange = 0.525
|
||||
return TestRightResultType.UNDEFINED
|
||||
}else if (value >= 0.525) {
|
||||
testRightCalculationData.ratioMinRange = 0.525
|
||||
testRightCalculationData.ratioMaxRange = 999.0
|
||||
return TestRightResultType.SICKLECELLDISEASE
|
||||
}
|
||||
@@ -1,44 +1,45 @@
|
||||
package com.example.hpostesting.domain
|
||||
package com.example.hpos.domain
|
||||
|
||||
import android.util.Log
|
||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.test.TestRightCalculationData
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.PatientData
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.opencsv.CSVWriter
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.util.Collections.sort
|
||||
|
||||
class SaveRawData(private val localFileRepository: LocalFileRepository) {
|
||||
class SaveRawData {
|
||||
|
||||
private val TAG = "saverawdata"
|
||||
|
||||
fun saveCsv(folderPath: String, fileName: String, matrix: ArrayList<ArrayList<Double>>) {
|
||||
// try {
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
// val writer = CSVWriter(FileWriter(fullPath))
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
|
||||
sort(matrix) { one: ArrayList<Double>, two: ArrayList<Double> ->
|
||||
one[0].compareTo(two[0])
|
||||
}
|
||||
|
||||
val content = ArrayList<Array<String>>()
|
||||
content.add(arrayOf("NM", "CA"))
|
||||
|
||||
for (eachRow in matrix) {
|
||||
|
||||
if (eachRow[0] >= Constants.MIN_WAVELENGTH_RANGE_TO_RECORD && eachRow[0] < Constants.MAX_WAVELENGTH_RANGE_TO_RECORD + 1) {
|
||||
// val rowContent = arrayOf(String.format("%.3f", eachRow[0]), String.format("%.3f", eachRow[1]))
|
||||
val rowContent =
|
||||
arrayOf(
|
||||
String.format("%.10f", eachRow[0]),
|
||||
String.format("%.10f", eachRow[1])
|
||||
)
|
||||
content.add(rowContent)
|
||||
sort(matrix) { one: ArrayList<Double>, two: ArrayList<Double> ->
|
||||
one[0].compareTo(two[0])
|
||||
}
|
||||
}
|
||||
|
||||
localFileRepository.saveCsvToDisk(fullPath, content)
|
||||
// writer.writeAll(content) // data is adding to csv
|
||||
// writer.close()
|
||||
val content = ArrayList<Array<String>>()
|
||||
content.add(arrayOf("NM", "CA"))
|
||||
|
||||
for (eachRow in matrix) {
|
||||
|
||||
if (eachRow[0] >= Constants.MIN_WAVELENGTH_RANGE_TO_RECORD && eachRow[0] < Constants.MAX_WAVELENGTH_RANGE_TO_RECORD + 1) {
|
||||
// val rowContent = arrayOf(String.format("%.3f", eachRow[0]), String.format("%.3f", eachRow[1]))
|
||||
val rowContent =
|
||||
arrayOf(
|
||||
String.format("%.10f", eachRow[0]),
|
||||
String.format("%.10f", eachRow[1])
|
||||
)
|
||||
content.add(rowContent)
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
|
||||
// } catch (e: Exception) {
|
||||
// Log.e(TAG, e.toString())
|
||||
@@ -46,18 +47,15 @@ class SaveRawData(private val localFileRepository: LocalFileRepository) {
|
||||
}
|
||||
|
||||
fun saveLog(folderPath: String, fileName: String, calculationData: TestRightCalculationData) {
|
||||
// val fileObj = File(folderPath, fileName)
|
||||
// val writer = FileWriter(fileObj)
|
||||
val fileObj = File(folderPath, fileName)
|
||||
val writer = FileWriter(fileObj)
|
||||
|
||||
// writer.append(getLogStringFromObj(calculationData))
|
||||
// writer.flush()
|
||||
// writer.close()
|
||||
|
||||
val fullPath = folderPath + fileName
|
||||
localFileRepository.saveTextToDisk(fullPath, getLogStringFromObj(calculationData))
|
||||
writer.append(getLogStringFromObj(calculationData))
|
||||
writer.flush()
|
||||
writer.close()
|
||||
}
|
||||
|
||||
private fun getLogStringFromObj(calculationData: TestRightCalculationData): String {
|
||||
fun getLogStringFromObj(calculationData: TestRightCalculationData): String {
|
||||
var outputString = "Test calculation logs ==>\n"
|
||||
outputString += "Absorbance one = ${
|
||||
String.format(
|
||||
@@ -98,30 +96,24 @@ class SaveRawData(private val localFileRepository: LocalFileRepository) {
|
||||
folderPath: String,
|
||||
fileName: String,
|
||||
calculationData: TestRightCalculationData,
|
||||
testDetails: UserData?
|
||||
patientData: PatientData
|
||||
) {
|
||||
// val fileObj = File(folderPath, fileName)
|
||||
// val writer = FileWriter(fileObj)
|
||||
val fileObj = File(folderPath, fileName)
|
||||
val writer = FileWriter(fileObj)
|
||||
|
||||
// writer.append(getLogStringFromObjWithPatientData(calculationData, patientData))
|
||||
// writer.flush()
|
||||
// writer.close()
|
||||
|
||||
val fullPath = folderPath + fileName
|
||||
localFileRepository.saveTextToDisk(
|
||||
fullPath,
|
||||
getLogStringFromObjWithPatientData(calculationData, testDetails)
|
||||
)
|
||||
writer.append(getLogStringFromObjWithPatientData(calculationData, patientData))
|
||||
writer.flush()
|
||||
writer.close()
|
||||
}
|
||||
|
||||
private fun getLogStringFromObjWithPatientData(
|
||||
calculationData: TestRightCalculationData,
|
||||
testDetails: UserData?
|
||||
patientData: PatientData
|
||||
): String {
|
||||
var outputString = "Test calculation logs ==>\n"
|
||||
outputString += "Name = ${testDetails?.name}\n"
|
||||
outputString += "ID = ${testDetails?._id}\n"
|
||||
// outputString += "Gender = ${patientData.gender}\n"
|
||||
outputString += "Name = ${patientData.name}\n"
|
||||
outputString += "Age = ${patientData.age}\n"
|
||||
outputString += "Gender = ${patientData.gender}\n"
|
||||
outputString += "Absorbance one = ${
|
||||
String.format(
|
||||
"%.3f",
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.example.hpostesting.domain
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||
import com.example.hpostesting.data.model.CalculationVariableForTest
|
||||
import android.util.Log
|
||||
import com.example.hpos.data.model.CalculationVariableForTest
|
||||
import com.opencsv.CSVWriter
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.FileWriter
|
||||
|
||||
class SaveRawDataTest(private val localFileRepository: LocalFileRepository) {
|
||||
class SaveRawDataTest {
|
||||
|
||||
private val TAG = "SaveRawDataTest"
|
||||
|
||||
@@ -11,7 +15,7 @@ class SaveRawDataTest(private val localFileRepository: LocalFileRepository) {
|
||||
|
||||
// try {
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
// val writer = CSVWriter(FileWriter(fullPath))
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
val content = ArrayList<Array<String>>()
|
||||
|
||||
// Header
|
||||
@@ -31,40 +35,27 @@ class SaveRawDataTest(private val localFileRepository: LocalFileRepository) {
|
||||
content.add(rowContent)
|
||||
}
|
||||
|
||||
localFileRepository.saveCsvToDisk(fullPath, content)
|
||||
// writer.writeAll(content) // data is adding to csv
|
||||
// writer.close()
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
// } catch (e: Exception){
|
||||
// Log.e(TAG, e.toString())
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(folderPath: String, fileName: String, isReference: Boolean, fullString: String) {
|
||||
// val fileObj = File(folderPath, fileName)
|
||||
val fileObj = File(folderPath, fileName)
|
||||
|
||||
// Log.d(TAG, "$folderPath --- $fileName")
|
||||
// val writer = FileWriter(fileObj)
|
||||
val writer = FileWriter(fileObj)
|
||||
|
||||
// if (isReference)
|
||||
// writer.append("\nREFERENCE OUTPUT\n")
|
||||
// else
|
||||
// writer.append("\nSAMPLE OUTPUT\n")
|
||||
//
|
||||
// writer.append(fullString)
|
||||
// writer.flush()
|
||||
// writer.close()
|
||||
|
||||
val filePath = folderPath + fileName
|
||||
var stringToWrite = ""
|
||||
stringToWrite += if (isReference)
|
||||
"\nREFERENCE OUTPUT\n"
|
||||
if (isReference)
|
||||
writer.append("\nREFERENCE OUTPUT\n")
|
||||
else
|
||||
"\nSAMPLE OUTPUT\n"
|
||||
|
||||
stringToWrite += fullString
|
||||
|
||||
localFileRepository.saveTextToDisk(filePath, stringToWrite)
|
||||
writer.append("\nSAMPLE OUTPUT\n")
|
||||
|
||||
writer.append(fullString)
|
||||
writer.flush()
|
||||
writer.close()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.example.hpostesting.domain
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.test.TestRightCalculationData
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
|
||||
class SickleFindResultCaluculationWithMaxImpl : TestRightResultCalculation{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.example.hpostesting.domain
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpostesting.data.model.test.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
|
||||
interface TestRightResultCalculation {
|
||||
fun getResults(
|
||||
171
app/src/main/java/com/example/hpos/presentation/MainActivity.kt
Normal file
171
app/src/main/java/com/example/hpos/presentation/MainActivity.kt
Normal file
@@ -0,0 +1,171 @@
|
||||
package com.example.hpos.presentation
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.get
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.ActivityMainBinding
|
||||
import com.example.hpos.presentation.testRight.TestRightActivity
|
||||
import com.example.hpos.util.MyViewModelFactory
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity()
|
||||
// , SerialInputOutputManager.Listener
|
||||
{
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var viewModel: MainViewModel
|
||||
|
||||
private var myMenu: Menu? = null
|
||||
|
||||
private val TAG = "MainActivity"
|
||||
|
||||
private var mUsbReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent) {
|
||||
val action = intent.action
|
||||
if (UsbManager.ACTION_USB_DEVICE_DETACHED == action) {
|
||||
DataHolder.usbConnected.value = false
|
||||
// Toast.makeText(context, "Detached", Toast.LENGTH_SHORT).show()
|
||||
} else if (UsbManager.ACTION_USB_DEVICE_ATTACHED == action) {
|
||||
DataHolder.usbConnected.value = true
|
||||
// Toast.makeText(context, "Attached", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
viewModel = ViewModelProvider(
|
||||
this,
|
||||
MyViewModelFactory(applicationContext)
|
||||
)[MainViewModel::class.java]
|
||||
|
||||
setSupportActionBar(binding.myToolbar)
|
||||
|
||||
setupNavigationDrawer()
|
||||
|
||||
setupListeners()
|
||||
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
|
||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
|
||||
registerReceiver(mUsbReceiver, filter)
|
||||
}
|
||||
|
||||
private fun setupNavigationDrawer() {
|
||||
// Pass the ActionBarToggle action into the drawerListener
|
||||
val actionBarToggle = ActionBarDrawerToggle(this, binding.drawerLayout, 0, 0)
|
||||
binding.drawerLayout.addDrawerListener(actionBarToggle)
|
||||
|
||||
// For the Navigation drawer
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
// Call syncState() on the action bar so it'll automatically change to the back button when the drawer layout is open
|
||||
actionBarToggle.syncState()
|
||||
|
||||
// Call setNavigationItemSelectedListener on the NavigationView to detect when items are clicked
|
||||
binding.navView.setNavigationItemSelectedListener { menuItem: MenuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.about_us -> {
|
||||
Toast.makeText(this, "Test clicked", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
R.id.download_report -> {
|
||||
Toast.makeText(this, "Download clicked", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
R.id.settings -> {
|
||||
Toast.makeText(this, "Settings clicked", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAndUpdateUsbConnection() {
|
||||
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager)
|
||||
if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID){
|
||||
Log.d(TAG, "Device matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}")
|
||||
DataHolder.usbConnected.value = true
|
||||
} else if (availableDrivers.isNotEmpty()) {
|
||||
Log.d(TAG, "Device NOT matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}")
|
||||
Toast.makeText(this, "Device Not Compatible", Toast.LENGTH_SHORT).show()
|
||||
DataHolder.usbConnected.value = false
|
||||
} else {
|
||||
Log.d(TAG, "Device NOT Connected")
|
||||
DataHolder.usbConnected.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
|
||||
binding.cvItem1.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLECERT
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
binding.cvItem2.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLEFIND
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
DataHolder.usbConnected.observe(this){
|
||||
// Log.d(TAG, "usbConnected observer called with value -> $it")
|
||||
if (it){
|
||||
myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
||||
} else {
|
||||
// Log.d(TAG, "into no block -> $it")
|
||||
myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.my_menu, menu)
|
||||
myMenu = menu
|
||||
checkAndUpdateUsbConnection()
|
||||
return true
|
||||
}
|
||||
|
||||
// override the onSupportNavigateUp() function to launch the Drawer when the hamburger icon is clicked
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
binding.drawerLayout.openDrawer(binding.navView)
|
||||
return true
|
||||
}
|
||||
|
||||
// override the onBackPressed() function to close the Drawer when the back button is clicked
|
||||
override fun onBackPressed() {
|
||||
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
binding.drawerLayout.closeDrawer(GravityCompat.START)
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation
|
||||
package com.example.hpos.presentation
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
39
app/src/main/java/com/example/hpos/presentation/RVAdapter.kt
Normal file
39
app/src/main/java/com/example/hpos/presentation/RVAdapter.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.example.hpos.presentation
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.model.PatientData
|
||||
|
||||
class RVAdapter : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
|
||||
|
||||
private val dataset = ArrayList<PatientData>()
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.table_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataset.size
|
||||
}
|
||||
|
||||
fun updateDataSet(newDataSet: ArrayList<PatientData>) {
|
||||
dataset.clear()
|
||||
dataset.addAll(newDataSet)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.example.hpos.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.databinding.ActivitySplashBinding
|
||||
import com.example.hpos.util.MyUtils
|
||||
|
||||
/**
|
||||
* Splash Activity
|
||||
* Used for preprocessing of data, permissions
|
||||
*/
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivitySplashBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySplashBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
checkForPermissions()
|
||||
}
|
||||
|
||||
private fun checkForPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
getPermissionsAboveAndroidR()
|
||||
} else {
|
||||
getPermissionsBelowAndroidR()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun getPermissionsAboveAndroidR() {
|
||||
// Checking if permission is already granted or not.
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
val storagePermissionResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = false
|
||||
Toast.makeText(
|
||||
this,
|
||||
"You must grant permission to storage to use the app",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
val intent = Intent()
|
||||
intent.action = Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
|
||||
intent.data = Uri.fromParts("package", this.packageName, null)
|
||||
storagePermissionResultLauncher.launch(intent)
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPermissionsBelowAndroidR() {
|
||||
val requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = false
|
||||
Toast.makeText(
|
||||
this,
|
||||
"You must grant permission to storage to use the app",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
} else {
|
||||
DataHolder.isStoragePermissionGranted = true
|
||||
moveToLandingPage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveToLandingPage() {
|
||||
createAppFolder()
|
||||
val i = Intent(applicationContext, MainActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
private fun createAppFolder() {
|
||||
val folderPath = MyUtils.createAppFolder(applicationContext)
|
||||
if (folderPath != null){
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation
|
||||
package com.example.hpos.presentation
|
||||
|
||||
interface UsbServiceListener {
|
||||
fun onUsbRead(data: ByteArray?)
|
||||
@@ -1,38 +1,32 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.ServiceConnection
|
||||
import android.content.*
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbDeviceConnection
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.*
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.get
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.databinding.ActivityTestRightBinding
|
||||
import com.example.hpos.util.MyViewModelFactory
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityTestRightBinding
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class TestRightActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityTestRightBinding
|
||||
private val viewModel by viewModels<TestRightViewModel>()
|
||||
private lateinit var viewModel: TestRightViewModel
|
||||
private var myMenu: Menu? = null
|
||||
|
||||
private lateinit var mDriver: UsbSerialDriver
|
||||
@@ -64,8 +58,6 @@ class TestRightActivity : AppCompatActivity() {
|
||||
val binder = service as UsbService.UsbServiceBinder
|
||||
mService = binder.getService()
|
||||
viewModel.isServiceConnected = true
|
||||
|
||||
// Todo: Uncomment this
|
||||
mConnection.let { mService.connect(mDriver, mConnection!!) }
|
||||
moveToNext()
|
||||
}
|
||||
@@ -79,6 +71,10 @@ class TestRightActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityTestRightBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
viewModel = ViewModelProvider(
|
||||
this,
|
||||
MyViewModelFactory(this.applicationContext)
|
||||
)[TestRightViewModel::class.java]
|
||||
|
||||
setSupportActionBar(binding.myToolbar)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
@@ -108,12 +104,6 @@ class TestRightActivity : AppCompatActivity() {
|
||||
// .replace(binding.flMain.id, TestRightExpSample()).commit()
|
||||
// }
|
||||
|
||||
// Todo: Comment this
|
||||
// private fun connectUsb(permissionGranted: Boolean) {
|
||||
// setupService()
|
||||
// }
|
||||
|
||||
// Todo: Uncomment this
|
||||
private fun connectUsb(permissionGranted: Boolean) {
|
||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||
@@ -129,8 +119,6 @@ class TestRightActivity : AppCompatActivity() {
|
||||
onBackPressed()
|
||||
return
|
||||
}
|
||||
|
||||
viewModel.testDetails?.deviceId = mDriver.device.serialNumber.toString()
|
||||
DataHolder.deviceSerialNumber = mDriver.device.serialNumber.toString()
|
||||
mConnection = manager.openDevice(mDriver.device)
|
||||
|
||||
@@ -161,7 +149,7 @@ class TestRightActivity : AppCompatActivity() {
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.ACTION_USB_PERMISSION),
|
||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||
PendingIntent.FLAG_ONE_SHOT
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
@@ -8,21 +8,20 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.children
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.TestRightCommands
|
||||
import com.example.hpostesting.data.model.ErrorMessage
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpReferenceBinding
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.constant.TestRightCommands
|
||||
import com.example.hpos.data.model.ErrorMessage
|
||||
import com.example.hpos.databinding.FragmentTestRightExpReferenceBinding
|
||||
import com.example.hpos.presentation.UsbServiceListener
|
||||
import com.example.hpos.presentation.utils.MyDialogListener
|
||||
import com.example.hpos.presentation.utils.UIUtils
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class TestRightExpReference : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||
@@ -67,7 +66,8 @@ class TestRightExpReference : Fragment() {
|
||||
getString(R.string.yes),
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {
|
||||
|
||||
// Todo: Only for testing
|
||||
// viewModel.progressBar.postValue(true)
|
||||
}
|
||||
override fun onClickPositiveButton() {
|
||||
startTakingReference()
|
||||
@@ -256,8 +256,6 @@ class TestRightExpReference : Fragment() {
|
||||
Log.d(TAG, "sendCmdToFetchLightIntensities() called")
|
||||
viewModel.progressBar.postValue(true)
|
||||
val fullReadOutput = StringBuilder()
|
||||
|
||||
DataHolder.testExp = true
|
||||
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.printAll,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@@ -8,23 +7,22 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.TestRightCommands
|
||||
import com.example.hpostesting.data.model.ErrorMessage
|
||||
import com.example.hpostesting.data.model.test.TestType
|
||||
import com.example.hpostesting.presentation.MainActivity
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpSampleBinding
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.PreferenceUtility
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.constant.TestRightCommands
|
||||
import com.example.hpos.data.model.ErrorMessage
|
||||
import com.example.hpos.data.model.PatientData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.FragmentTestRightExpSampleBinding
|
||||
import com.example.hpos.presentation.UsbServiceListener
|
||||
import com.example.hpos.presentation.utils.MyDialogListener
|
||||
import com.example.hpos.presentation.utils.UIUtils
|
||||
|
||||
@AndroidEntryPoint
|
||||
class TestRightExpSample : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpSampleBinding
|
||||
@@ -76,52 +74,50 @@ class TestRightExpSample : Fragment() {
|
||||
}
|
||||
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
// val details = validateAndReturnTestData()
|
||||
// if (details != null) {
|
||||
// viewModel.patientDetails = details
|
||||
val details = checkAndReturnPatientDetails()
|
||||
if (details != null) {
|
||||
viewModel.patientDetails = details
|
||||
|
||||
UIUtils.createAlertDialog(
|
||||
requireContext(),
|
||||
"WARNING",
|
||||
"Please check if you have placed the sample of this person ${viewModel.testDetails?._id}",
|
||||
getString(R.string.no),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
override fun onClickPositiveButton() {
|
||||
UIUtils.createAlertDialog(
|
||||
requireContext(),
|
||||
getString(R.string.have_you_placed_sample),
|
||||
getString(R.string.please_place_sample),
|
||||
getString(R.string.no),
|
||||
getString(R.string.yes_and_run),
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
override fun onClickPositiveButton() {
|
||||
startAcquiring()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// }
|
||||
UIUtils.createAlertDialog(
|
||||
requireContext(),
|
||||
getString(R.string.have_you_placed_sample),
|
||||
getString(R.string.please_place_sample),
|
||||
getString(R.string.no),
|
||||
getString(R.string.yes_and_run),
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
override fun onClickPositiveButton() {
|
||||
startAcquiring()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
binding.tvSkip.setOnClickListener {
|
||||
DataHolder.sampleReadCounter = 0
|
||||
DataHolder.isReferenceTaken = false
|
||||
val i = Intent(requireContext(), MainActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
// binding.etNameBlock.setOnClickListener { binding.etName.isErrorEnabled = false }
|
||||
// binding.etAgeBlock.setOnClickListener { binding.etAge.isErrorEnabled = false }
|
||||
// binding.etGenderBlock.setOnClickListener { binding.ddGender.isErrorEnabled = false }
|
||||
binding.etNameBlock.setOnClickListener { binding.etName.isErrorEnabled = false }
|
||||
binding.etAgeBlock.setOnClickListener { binding.etAge.isErrorEnabled = false }
|
||||
binding.etGenderBlock.setOnClickListener { binding.ddGender.isErrorEnabled = false }
|
||||
}
|
||||
|
||||
// private fun validateAndReturnTestData(): TestDetails? {
|
||||
//
|
||||
// return PatientData(name.toString(), age.toString().toInt(), gender.toString(), TestRightResultType.UNDEFINED)
|
||||
// }
|
||||
private fun checkAndReturnPatientDetails(): PatientData? {
|
||||
val name = binding.etName.editText?.text?.trim()
|
||||
if (name.isNullOrEmpty()) {
|
||||
binding.etName.error = getString(R.string.name_error)
|
||||
return null
|
||||
}
|
||||
val age = binding.etAge.editText?.text?.trim()
|
||||
if (age.isNullOrEmpty()) {
|
||||
binding.etAge.error = getString(R.string.age_error)
|
||||
return null
|
||||
} else if (age.toString().toInt() < 0 || age.toString().toInt() > 199) {
|
||||
binding.etAge.error = getString(R.string.age_error_out_of_bound)
|
||||
return null
|
||||
}
|
||||
val gender = binding.ddGender.editText?.text
|
||||
if (gender.isNullOrEmpty()) {
|
||||
binding.ddGender.error = getString(R.string.gender_error)
|
||||
return null
|
||||
}
|
||||
return PatientData(name.toString(), age.toString().toInt(), gender.toString(), TestRightResultType.UNDEFINED)
|
||||
}
|
||||
|
||||
/**
|
||||
* Executing the commands sequentially each after successfully executing one.
|
||||
@@ -175,8 +171,6 @@ class TestRightExpSample : Fragment() {
|
||||
Log.d(TAG, "sendCmdToFetchLightIntensities() called")
|
||||
viewModel.progressBar.postValue(true)
|
||||
val fullReadOutput = StringBuilder()
|
||||
|
||||
DataHolder.testExp = false
|
||||
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.printAll,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
@@ -248,34 +242,46 @@ class TestRightExpSample : Fragment() {
|
||||
// viewModel.mapWavelengthToAbsorbance()
|
||||
// viewModel.calculateResults()
|
||||
|
||||
if (viewModel.calculationData.absorbanceOne!! < 0 || viewModel.calculationData.absorbanceTwo!! < 0) {
|
||||
Toast.makeText(requireContext(), " ", Toast.LENGTH_SHORT).show()
|
||||
viewModel.progressBar.postValue(false)
|
||||
} else {
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightResults())
|
||||
.commit()
|
||||
}
|
||||
viewModel.progressBar.postValue(false)
|
||||
// binding.progressBar.visibility = View.GONE
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightResults())
|
||||
.commit()
|
||||
}
|
||||
|
||||
private fun saveDataLocally() {
|
||||
// OLD ------------------------------
|
||||
// val patientName = viewModel.testDetails?.patientName
|
||||
val patientName = viewModel.patientDetails.name
|
||||
// if (patientName.length > 5){
|
||||
// patientName = patientName.substring(0, 5)
|
||||
// }
|
||||
// val id = PreferenceUtility.generateId(requireContext())
|
||||
|
||||
// val prefixCsv: String = if (DataHolder.selectedTestType == TestType.SICKLECERT)
|
||||
// "HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
// else
|
||||
// "HPOSSF_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
val id = PreferenceUtility.generateId(requireContext())
|
||||
|
||||
// val fileNameCsv = prefixCsv + id + fileExtensionCsv
|
||||
val prefixCsv: String = if (DataHolder.selectedTestType == TestType.SICKLECERT)
|
||||
"HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
else
|
||||
"HPOSSF_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
|
||||
// NEW ------------------------------
|
||||
viewModel.saveCsv(requireContext().applicationContext, viewModel.getCSVFileName())
|
||||
// viewModel.saveCsvForTesting(requireContext().applicationContext, viewModel.getDetailedCSVFileName())
|
||||
viewModel.saveLogWithPatient(requireContext().applicationContext, viewModel.getLogFileName())
|
||||
// val prefixCsv = "HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
val fileExtensionCsv = ".csv"
|
||||
val fileNameCsv = prefixCsv + id + fileExtensionCsv
|
||||
saveCsv(fileNameCsv)
|
||||
|
||||
val prefixTxt = "log_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
val fileExtensionTxt = ".txt"
|
||||
val fileNameTxt = prefixTxt + id + fileExtensionTxt
|
||||
saveLog(fileNameTxt)
|
||||
}
|
||||
|
||||
private fun saveCsv(fileName: String) {
|
||||
Log.d(TAG, "saveCsv() called")
|
||||
|
||||
viewModel.saveCsv(requireContext().applicationContext, fileName)
|
||||
viewModel.saveCsvForTesting(requireContext().applicationContext, "detailed_$fileName")
|
||||
}
|
||||
|
||||
private fun saveLog(fileName: String) {
|
||||
Log.d(TAG, "saveLog() called")
|
||||
viewModel.saveLogWithPatient(requireContext().applicationContext, fileName)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.PreferenceUtility
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.FragmentTestRightResultsBinding
|
||||
import com.example.hpos.presentation.MainActivity
|
||||
import com.example.hpos.util.MyUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class TestRightResults : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightResultsBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
private val TAG = "TestRightResults"
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTestRightResultsBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupListeners()
|
||||
updateResults()
|
||||
// saveCsv()
|
||||
// saveLog()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.ivHome.setOnClickListener {
|
||||
val i = Intent(requireContext().applicationContext, MainActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
binding.ivNext.setOnClickListener {
|
||||
moveToSamplePage()
|
||||
}
|
||||
}
|
||||
|
||||
fun moveToSamplePage() {
|
||||
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
||||
DataHolder.sampleReadCounter = 0
|
||||
DataHolder.isReferenceTaken = false
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.fl_main, TestRightExpReference())
|
||||
.commit()
|
||||
} else {
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightExpSample())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveLog() {
|
||||
Log.d(TAG, "saveLog() called")
|
||||
|
||||
val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
||||
val fileName: String = "log_" + sdfDate.format(Date()) + ".txt"
|
||||
|
||||
viewModel.saveLog(requireContext().applicationContext, fileName)
|
||||
|
||||
// if (!DataHolder.isAppFolderCreated) {
|
||||
// val folderPath = MyUtils.createAppFolder(requireContext().applicationContext)
|
||||
// if (folderPath != null) {
|
||||
// DataHolder.isAppFolderCreated = true
|
||||
// DataHolder.appFolderPath = folderPath
|
||||
// viewModel.saveLog(DataHolder.appFolderPath, fileName)
|
||||
// }
|
||||
// } else {
|
||||
// viewModel.saveLog(DataHolder.appFolderPath, fileName)
|
||||
// }
|
||||
}
|
||||
|
||||
// private fun saveCsv() {
|
||||
// Log.d(TAG, "saveCsv() called")
|
||||
//
|
||||
// val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
||||
// val fileName: String = sdfDate.format(Date()) + ".csv"
|
||||
//
|
||||
// if (!DataHolder.isAppFolderCreated) {
|
||||
// val folderPath = MyUtils.createAppFolder(requireContext().applicationContext)
|
||||
// if (folderPath != null) {
|
||||
// DataHolder.isAppFolderCreated = true
|
||||
// DataHolder.appFolderPath = folderPath
|
||||
// viewModel.saveCsv(DataHolder.appFolderPath, fileName)
|
||||
//
|
||||
// viewModel.saveCsvForTesting(DataHolder.appFolderPath, "testing$fileName")
|
||||
// }
|
||||
// } else {
|
||||
// viewModel.saveCsv(DataHolder.appFolderPath, fileName)
|
||||
//
|
||||
// viewModel.saveCsvForTesting(DataHolder.appFolderPath, "testing$fileName")
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
private fun saveCsv() {
|
||||
Log.d(TAG, "saveCsv() called")
|
||||
|
||||
// val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
||||
// val fileName: String = sdfDate.format(Date()) + ".csv"
|
||||
|
||||
val prefix = "HPOSSC_${DataHolder.deviceSerialNumber}_"
|
||||
val fileExtension = ".csv"
|
||||
|
||||
val fileName = PreferenceUtility.generateId(requireContext(), prefix) + fileExtension
|
||||
|
||||
|
||||
viewModel.saveCsv(requireContext().applicationContext, fileName)
|
||||
viewModel.saveCsvForTesting(requireContext().applicationContext, "testing$fileName")
|
||||
}
|
||||
|
||||
private fun updateResults() {
|
||||
binding.tvName.text = getString(R.string.name_in_textview, viewModel.patientDetails.name)
|
||||
binding.tvAge.text =
|
||||
getString(R.string.age_in_textview, viewModel.patientDetails.age.toString())
|
||||
binding.tvGender.text =
|
||||
getString(R.string.gender_in_textview, viewModel.patientDetails.gender)
|
||||
|
||||
if (DataHolder.selectedTestType == TestType.SICKLECERT){
|
||||
when (viewModel.patientDetails.results) {
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
}
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
}
|
||||
TestRightResultType.SICKLECELLTRAIT -> {
|
||||
binding.resultTrait.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
// binding.resultUndefined.visibility = View.VISIBLE
|
||||
Toast.makeText(requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG).show()
|
||||
moveToSamplePage()
|
||||
// val i = Intent(requireContext().applicationContext, MainActivity::class.java)
|
||||
// startActivity(i)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
when (viewModel.patientDetails.results) {
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
binding.resultDisease.text = "Positive"
|
||||
}
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
binding.resultNormal.text = "Negative"
|
||||
}
|
||||
else -> {
|
||||
Toast.makeText(requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG).show()
|
||||
moveToSamplePage()
|
||||
// val i = Intent(requireContext().applicationContext, MainActivity::class.java)
|
||||
// startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// when (viewModel.patientDetails.results) {
|
||||
// TestRightResultType.NORMAL -> {
|
||||
// binding.resultNormal.visibility = View.VISIBLE
|
||||
// }
|
||||
// TestRightResultType.SICKLECELLDISEASE -> {
|
||||
// binding.resultDisease.visibility = View.VISIBLE
|
||||
// }
|
||||
// TestRightResultType.SICKLECELLTRAIT -> {
|
||||
// binding.resultTrait.visibility = View.VISIBLE
|
||||
// }
|
||||
// else -> {
|
||||
// binding.resultUndefined.visibility = View.VISIBLE
|
||||
// }
|
||||
// }
|
||||
|
||||
// Log.d(TAG, "\n\n\n\nFor intensity Reference array size = ${DataHolder.intensityReferenceArray.size}")
|
||||
// for (each in DataHolder.intensityReferenceArray){
|
||||
// Log.d(TAG, "${each}")
|
||||
// }
|
||||
//
|
||||
// Log.d(TAG, "\n\n\n\nFor intensity Reference array size = ${viewModel.intensitySampleArray.size}")
|
||||
// for (each in viewModel.intensitySampleArray){
|
||||
// Log.d(TAG, "${each}")
|
||||
// }
|
||||
// Log.d(TAG,"")
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.*
|
||||
import com.example.hpos.domain.*
|
||||
import com.example.hpos.util.MyUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Collections.sort
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
class TestRightViewModel : ViewModel() {
|
||||
|
||||
private val TAG = "TestRightViewModel"
|
||||
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
|
||||
// val errorTriggered = MutableLiveData<String>("")
|
||||
val errorTriggered = MutableLiveData<ErrorMessage>()
|
||||
var numberOfSampleRun = 0
|
||||
|
||||
lateinit var patientDetails: PatientData
|
||||
|
||||
// var deviceConstant: TestRightDeviceConstants? = null
|
||||
private lateinit var calculationData: TestRightCalculationData
|
||||
|
||||
/* (For exp sample) Contains pixel no. -> Intensity of light falling on that pixel */
|
||||
val intensitySampleArray = ArrayList<Double>()
|
||||
|
||||
val wavelengthToAbsorbance = ArrayList<ArrayList<Double>>()
|
||||
|
||||
val calculationVariableList = ArrayList<CalculationVariableForTest>()
|
||||
|
||||
fun mapDeviceConstants(string: String) {
|
||||
// Log.d(TAG, "mapDeviceConstants() called")
|
||||
// Log.d(TAG, "mapDeviceConstants() value -> $string")
|
||||
if (string.isNotEmpty()) {
|
||||
val listOfStrings = string.split(",")
|
||||
if (listOfStrings.size >= 4) {
|
||||
DataHolder.deviceConstant = TestRightDeviceConstants(
|
||||
listOfStrings[0].trim(),
|
||||
listOfStrings[1].trim(),
|
||||
listOfStrings[2].trim(),
|
||||
listOfStrings[3].trim()
|
||||
)
|
||||
|
||||
mapPixelNumberToWavelength()
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 201: In processing the data from device"
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 201: In processing the data from device",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error (showing error if empty by using a mutable error string)
|
||||
// "Error 202: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 202: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
fun mapPixelNumberToWavelength() {
|
||||
// viewModelScope.launch {
|
||||
DataHolder.wavelengthToPixelArray.clear()
|
||||
if (DataHolder.deviceConstant != null) {
|
||||
for (x in 1..Constants.TEST_RIGHT_TOTAL_PIXEL) {
|
||||
// val index = x - 1
|
||||
val wavelength: Double =
|
||||
(DataHolder.deviceConstant!!.a.toDouble() * (x.toDouble()
|
||||
.pow((3).toDouble()))) +
|
||||
(DataHolder.deviceConstant!!.b.toDouble() * (x.toDouble()
|
||||
.pow((2).toDouble()))) +
|
||||
(DataHolder.deviceConstant!!.c.toDouble() * x) +
|
||||
(DataHolder.deviceConstant!!.d.toDouble())
|
||||
|
||||
DataHolder.wavelengthToPixelArray.add(wavelength)
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 203: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 203: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
fun mapIntensityValues(fullString: String, isReference: Boolean) {
|
||||
|
||||
if (isReference) DataHolder.intensityReferenceArray.clear()
|
||||
else intensitySampleArray.clear()
|
||||
|
||||
Log.d("SURYAKUMAR", fullString)
|
||||
val listOfString = fullString.split("\n")
|
||||
|
||||
for (line in listOfString) {
|
||||
if ("Buf" in line) {
|
||||
/* Removing trailing spaces and "Buf" from the string then taking lhs & rhs of ':' */
|
||||
val numbers = line.trim()
|
||||
.substring(3).split(":")
|
||||
if (numbers.size >= 2) {
|
||||
|
||||
if (isReference)
|
||||
DataHolder.intensityReferenceArray.add(numbers[1].toDouble())
|
||||
else
|
||||
intensitySampleArray.add(numbers[1].toDouble())
|
||||
} else {
|
||||
// "Error 204: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 204: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// fun mapWavelengthToAbsorbance(){
|
||||
// var indexInReference = intensityReferenceArray.size - 1
|
||||
// var indexInSample = intensitySampleArray.size - 1
|
||||
// for (each in wavelengthToPixelArray){
|
||||
// val wavelength = each[0]
|
||||
// val invertedPixel = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - each[1]
|
||||
//
|
||||
// var Io = 0.0
|
||||
// if (intensityReferenceArray[indexInReference][0].toInt() == invertedPixel.toInt()){
|
||||
// Io = intensityReferenceArray[indexInReference][1]
|
||||
// }
|
||||
//
|
||||
// var I = 0.0
|
||||
// if (intensitySampleArray[indexInSample][0].toInt() == invertedPixel.toInt()){
|
||||
// I = intensitySampleArray[indexInSample][1]
|
||||
// }
|
||||
//
|
||||
// val absorbance = log10(Io/I)
|
||||
//
|
||||
// val temp = ArrayList<Double>(2)
|
||||
// temp.add(wavelength)
|
||||
// temp.add(absorbance)
|
||||
// wavelengthToAbsorbance.add(temp)
|
||||
//
|
||||
// indexInReference--
|
||||
// indexInSample--
|
||||
// }
|
||||
// }
|
||||
|
||||
fun mapWavelengthToAbsorbance() {
|
||||
if (DataHolder.intensityReferenceArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != DataHolder.intensityReferenceArray.size) {
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 205: Unable to fetch data from device, please try again by reopening the app",
|
||||
Constants.ERROR_CRITICAL
|
||||
)
|
||||
)
|
||||
|
||||
throw Exception("Inconsistency in the data, size of arrays are not same. \nintensityReferenceArray.size = ${DataHolder.intensityReferenceArray.size} ; intensitySampleArray.size = ${intensitySampleArray.size} ; wavelengthToPixelArray.size = ${DataHolder.wavelengthToPixelArray.size}")
|
||||
}
|
||||
|
||||
wavelengthToAbsorbance.clear()
|
||||
calculationVariableList.clear()
|
||||
|
||||
// Index pointing to last of the array
|
||||
// var indexInIntensityArrays = intensityReferenceArray.size - 1
|
||||
// for ((index,wavelength) in wavelengthToPixelArray.withIndex()) {
|
||||
for (index in 0 until DataHolder.wavelengthToPixelArray.size) {
|
||||
|
||||
val invertedPixelIndex = (Constants.TEST_RIGHT_TOTAL_PIXEL) - (index + 1)
|
||||
|
||||
val i0 = DataHolder.intensityReferenceArray[invertedPixelIndex]
|
||||
// if (intensityReferenceArray[indexInIntensityArrays][0].toInt() == invertedPixelIndex.toInt()) {
|
||||
// Io = intensityReferenceArray[indexInIntensityArrays][1]
|
||||
// } else {
|
||||
// // Not needed - As you are calculating index and also checking the size of all 3 array before
|
||||
// throw Exception("Inconsistency in the data, pixel not found in intensity reference array \n pixel in intensityReferenceArray = ${intensityReferenceArray[indexInIntensityArrays][0]} & inverted pixel value = ${invertedPixelIndex.toInt()}")
|
||||
// }
|
||||
|
||||
val i1 = intensitySampleArray[invertedPixelIndex]
|
||||
// if (intensitySampleArray[indexInIntensityArrays][0].toInt() == invertedPixelIndex.toInt()) {
|
||||
// I = intensitySampleArray[indexInIntensityArrays][1]
|
||||
// } else {
|
||||
// // Not needed - As you are calculating index and also checking the size of all 3 array before
|
||||
// throw Exception("Inconsistency in the data, pixel not found in intensity sample array \n pixel in intensitySampleArray = ${intensitySampleArray[indexInIntensityArrays][0]} & inverted pixel value = ${invertedPixelIndex.toInt()}")
|
||||
// }
|
||||
|
||||
// if (I==0.0 || Io == 0.0){
|
||||
// throw Exception("error in data calculation I = $I & Io = $Io")
|
||||
// }
|
||||
|
||||
val absorbance = log10(i0 / i1)
|
||||
val wavelength = DataHolder.wavelengthToPixelArray[index]
|
||||
val temp = ArrayList<Double>(2)
|
||||
temp.add(wavelength)
|
||||
temp.add(absorbance)
|
||||
wavelengthToAbsorbance.add(temp)
|
||||
|
||||
// Todo: Remove
|
||||
val calculationVariableForTest = CalculationVariableForTest()
|
||||
calculationVariableForTest.pixelNo = index + 1
|
||||
calculationVariableForTest.invertedPixelNo =
|
||||
invertedPixelIndex + 1 // 0-based indexing
|
||||
calculationVariableForTest.wavelength = wavelength
|
||||
calculationVariableForTest.I0 = i0
|
||||
calculationVariableForTest.I = i1
|
||||
calculationVariableForTest.absorbance = absorbance
|
||||
calculationVariableList.add(calculationVariableForTest)
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateResults() {
|
||||
DataHolder.sampleReadCounter++
|
||||
|
||||
// patientDetails.results = ResultCalculationZeroImpl().getResults(wavelengthToPixelArray, intensityReferenceArray, intensitySampleArray)
|
||||
|
||||
|
||||
val resultCalculation: TestRightResultCalculation = ResultCalculationWithMaxImpl()
|
||||
calculationData = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
// patientDetails.results = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
patientDetails.results = calculationData.result
|
||||
|
||||
}
|
||||
|
||||
fun calculateResultsForSickleFind() {
|
||||
DataHolder.sampleReadCounter++
|
||||
val resultCalculation: TestRightResultCalculation =
|
||||
SickleFindResultCaluculationWithMaxImpl()
|
||||
calculationData = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
patientDetails.results = calculationData.result
|
||||
|
||||
}
|
||||
|
||||
fun saveCsv(appContext: Context, filename: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveCsv(folderPath!!, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveCsv(folderPath, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveCsvForTesting(appContext: Context, filename: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawDataTest().saveCsv(folderPath!!, filename, calculationVariableList)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawDataTest().saveCsv(folderPath, filename, calculationVariableList)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(appContext: Context, fileName: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveLog(folderPath!!, fileName, calculationData)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveLog(folderPath, fileName, calculationData)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogWithPatient(appContext: Context, fileName: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveLogWithPatientData(
|
||||
folderPath!!,
|
||||
fileName,
|
||||
calculationData,
|
||||
patientDetails
|
||||
)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveLogWithPatientData(
|
||||
folderPath,
|
||||
fileName,
|
||||
calculationData,
|
||||
patientDetails
|
||||
)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogTest(appContext: Context, isReference: Boolean, fullString: String) {
|
||||
var fileName: String =
|
||||
"test_log_" + SimpleDateFormat("ddMMyyyy_HHmmss").format(Date()) + ".txt"
|
||||
fileName = if (isReference) {
|
||||
"reference_$fileName"
|
||||
} else {
|
||||
"sample_$fileName"
|
||||
}
|
||||
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawDataTest().saveLog(folderPath!!, fileName, isReference, fullString)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawDataTest().saveLog(folderPath, fileName, isReference, fullString)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
@@ -6,9 +6,9 @@ import android.hardware.usb.UsbDeviceConnection
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.TestRightCommands
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.constant.TestRightCommands
|
||||
import com.example.hpos.presentation.UsbServiceListener
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialPort
|
||||
import com.hoho.android.usbserial.util.SerialInputOutputManager
|
||||
@@ -33,13 +33,21 @@ class UsbService : Service() {
|
||||
return binder
|
||||
}
|
||||
|
||||
// fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
||||
// mPort = driver.ports[0] // Most devices have just one port (port 0)
|
||||
// mPort.open(connection)
|
||||
// mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
||||
//
|
||||
// isUsbConnected = true
|
||||
// Log.d(TAG, "My Usb Connected ${mPort.driver}")
|
||||
// }
|
||||
|
||||
var listener: UsbServiceListener? = null
|
||||
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
||||
// Todo: Uncomment this
|
||||
mPort = driver.ports[0] // Most devices have just one port (port 0)
|
||||
mPort.open(connection)
|
||||
mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
||||
//
|
||||
|
||||
isUsbConnected = true
|
||||
Log.d(TAG, "My Usb Connected ${mPort.driver}")
|
||||
|
||||
@@ -66,44 +74,28 @@ class UsbService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
// Todo: comment this
|
||||
// fun eventDrivenWrite(command: TestRightCommands, listener: UsbServiceListener) {
|
||||
// this.listener = listener
|
||||
// try {
|
||||
// when (command) {
|
||||
// TestRightCommands.autoset -> {
|
||||
// this.listener!!.onUsbRead("OK".toByteArray())
|
||||
// }
|
||||
// TestRightCommands.led2Set50 -> {
|
||||
// this.listener!!.onUsbRead("OK".toByteArray())
|
||||
// }
|
||||
// TestRightCommands.run -> {
|
||||
// this.listener!!.onUsbRead("OK [0]".toByteArray())
|
||||
// }
|
||||
// TestRightCommands.read -> {
|
||||
// this.listener!!.onUsbRead(InputData().inputRead.toByteArray())
|
||||
// }
|
||||
// TestRightCommands.printAll -> {
|
||||
// if (DataHolder.testExp) {
|
||||
// for (each in InputData().printForReference.lines()) {
|
||||
// this.listener!!.onUsbRead((each + "\n").toByteArray())
|
||||
// }
|
||||
// } else {
|
||||
// for (each in InputData().printForSample.lines()) {
|
||||
// this.listener!!.onUsbRead((each + "\n").toByteArray())
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else -> {
|
||||
// this.listener!!.onUsbRead("OK".toByteArray())
|
||||
// }
|
||||
// val usbIoManager = SerialInputOutputManager(mPort,
|
||||
// object : SerialInputOutputManager.Listener{
|
||||
// override fun onNewData(data: ByteArray?) {
|
||||
// Log.e(TAG, "onNewData() called inside eventDrivenWrite() :: command = ${command.command}")
|
||||
// listener.onUsbRead(data)
|
||||
// }
|
||||
// override fun onRunError(e: Exception?) {
|
||||
// Log.e(TAG, "onRunError() called inside eventDrivenWrite()")
|
||||
// listener.onUsbError(e)
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// usbIoManager.start();
|
||||
//
|
||||
// try {
|
||||
// mPort.write(command.command.toByteArray(), Constants.WRITE_TIMEOUT_MILLIS)
|
||||
// } catch (e: IOException) {
|
||||
// listener.onUsbError(e)
|
||||
// }
|
||||
// }
|
||||
|
||||
// Todo: Uncomment this
|
||||
fun eventDrivenWrite(command: TestRightCommands, listener: UsbServiceListener) {
|
||||
this.listener = listener
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation.utils
|
||||
package com.example.hpos.presentation.utils
|
||||
|
||||
interface MyDialogListener {
|
||||
fun onClickNegativeButton()
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.hpostesting.presentation.utils
|
||||
package com.example.hpos.presentation.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
25
app/src/main/java/com/example/hpos/util/MyUtils.kt
Normal file
25
app/src/main/java/com/example/hpos/util/MyUtils.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.example.hpos.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import com.example.hpos.R
|
||||
import java.io.File
|
||||
|
||||
object MyUtils {
|
||||
|
||||
fun createAppFolder(context: Context) : String? {
|
||||
val folderPath = Environment.getExternalStorageDirectory().absolutePath + "/" + context.resources.getString(R.string.app_name) + "/"
|
||||
val file = File(folderPath)
|
||||
|
||||
return if (!file.exists()) {
|
||||
if (!file.mkdirs()) {
|
||||
null
|
||||
} else {
|
||||
folderPath
|
||||
}
|
||||
} else {
|
||||
folderPath
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.hpos.util
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpos.presentation.MainViewModel
|
||||
import com.example.hpos.presentation.testRight.TestRightViewModel
|
||||
|
||||
class MyViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
|
||||
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(MainViewModel::class.java))
|
||||
return MainViewModel() as T
|
||||
else if (modelClass.isAssignableFrom(TestRightViewModel::class.java))
|
||||
return TestRightViewModel() as T
|
||||
else
|
||||
throw IllegalArgumentException("Unknown ViewModel class");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
||||
@HiltAndroidApp
|
||||
class HPOSTestingApplication: Application() {
|
||||
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.example.hpostesting.data
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkRequest
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
class NetworkStatusLiveData(context: Context) : LiveData<Boolean>() {
|
||||
|
||||
private val connectivityManager: ConnectivityManager =
|
||||
context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
postValue(true)
|
||||
}
|
||||
|
||||
override fun onLost(network: Network) {
|
||||
postValue(false)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
override fun onActive() {
|
||||
super.onActive()
|
||||
postValue(isNetworkAvailable())
|
||||
registerNetworkCallback()
|
||||
}
|
||||
|
||||
override fun onInactive() {
|
||||
super.onInactive()
|
||||
unregisterNetworkCallback()
|
||||
}
|
||||
|
||||
private fun registerNetworkCallback() {
|
||||
val networkRequest = NetworkRequest.Builder()
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
||||
.build()
|
||||
|
||||
connectivityManager.registerNetworkCallback(networkRequest, networkCallback)
|
||||
}
|
||||
|
||||
private fun unregisterNetworkCallback() {
|
||||
connectivityManager.unregisterNetworkCallback(networkCallback)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun isNetworkAvailable(): Boolean {
|
||||
val network = connectivityManager.activeNetwork
|
||||
val networkCapabilities = connectivityManager.getNetworkCapabilities(network)
|
||||
return networkCapabilities != null &&
|
||||
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
|
||||
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +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,31 +0,0 @@
|
||||
package com.example.hpostesting.data.api
|
||||
|
||||
import com.example.hpostesting.data.model.patient.MolbioLogin
|
||||
import com.example.hpostesting.data.model.patient.UploadResponse
|
||||
import com.google.gson.JsonObject
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
import retrofit2.http.Part
|
||||
|
||||
interface MolbioApi {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("devices/login")
|
||||
suspend fun login(@Body jsonObject: JsonObject): MolbioLogin
|
||||
|
||||
|
||||
@Multipart
|
||||
@PUT("results/upload")
|
||||
fun uploadPdf(@Header("Authorization") auth:String, @Part file: MultipartBody.Part, @Part("DeviceId") name: RequestBody): Call<JsonObject>
|
||||
|
||||
@Multipart
|
||||
@PUT("results/upload")
|
||||
suspend fun uploadNewPdf(@Header("Authorization") auth:String,@Part("") count:RequestBody,@Part("") userId:RequestBody,@Part file_csv: MultipartBody.Part,@Part file_log:MultipartBody.Part,@Part("DeviceId") name:RequestBody): UploadResponse
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.example.hpostesting.data.dao
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.google.gson.Gson
|
||||
|
||||
class Converters {
|
||||
private val gson = Gson()
|
||||
|
||||
@TypeConverter
|
||||
fun fromString(value: String?): UserData.Location? {
|
||||
return if (value != null) {
|
||||
gson.fromJson(value, UserData.Location::class.java)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toString(location: UserData.Location?): String? {
|
||||
return if (location != null) {
|
||||
gson.toJson(location)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.example.hpostesting.data.dao
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
|
||||
@Database(entities = [UserData::class], version = 1, exportSchema = false)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class MyDatabase : RoomDatabase() {
|
||||
abstract fun userDao(): UserDao
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.example.hpostesting.data.dao
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
|
||||
@Dao
|
||||
interface UserDao {
|
||||
@Query("SELECT * from user_table")
|
||||
fun getAll(): LiveData<List<UserData>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(userData: UserData)
|
||||
|
||||
@Query("SELECT * FROM user_table WHERE _id = :id")
|
||||
suspend fun getUserByID(id: String): UserData
|
||||
|
||||
@Query("DELETE FROM user_table WHERE _id = :id")
|
||||
suspend fun deleteById(id: String)
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.example.hpostesting.data.datasource
|
||||
|
||||
import com.opencsv.CSVWriter
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
class LocalFileDataSource {
|
||||
|
||||
fun saveCsvToDisk(filepath: String, contents: ArrayList<Array<String>>){
|
||||
val writer = CSVWriter(FileWriter(filepath))
|
||||
writer.writeAll(contents) // data is adding to csv
|
||||
writer.close()
|
||||
}
|
||||
|
||||
fun saveTextToDisk(filepath: String, contents: String){
|
||||
val writer = FileWriter(File(filepath))
|
||||
|
||||
writer.append(contents)
|
||||
writer.flush()
|
||||
writer.close()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
|
||||
class AadharCard {
|
||||
var name = ""
|
||||
var dateOfBirth = ""
|
||||
var gender = ""
|
||||
var careOf = ""
|
||||
var district = ""
|
||||
var landmark = ""
|
||||
var house = ""
|
||||
var location = ""
|
||||
var pinCode = ""
|
||||
var postOffice = ""
|
||||
var state = ""
|
||||
var street = ""
|
||||
var subDistrict = ""
|
||||
var vtc = ""
|
||||
var mobile = ""
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
data class Location(
|
||||
var latitude: Double?,
|
||||
var longitude: Double?
|
||||
) {
|
||||
constructor() : this(null, null)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
data class PendingUploads(
|
||||
// Filename
|
||||
val pendingId: String,
|
||||
val mobileId: String,
|
||||
val patientId: String,
|
||||
val filePath: String,
|
||||
val timeAdded: Date
|
||||
) {
|
||||
constructor(): this("", "", "", "", Calendar.getInstance().time)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
sealed class Response<out R> {
|
||||
data class Success<out T>(val data: T) : Response<T>()
|
||||
data class Error(val exception: Exception) : Response<Nothing>()
|
||||
// object Loading : Response<Nothing>()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
data class MolbioLogin(
|
||||
val token: String
|
||||
)
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
import java.util.Date
|
||||
|
||||
data class PatientDetails(
|
||||
var id: String,
|
||||
var isIdABHA: Boolean,
|
||||
var name: String?,
|
||||
var yob: Int?,
|
||||
var gender: Gender?,
|
||||
var mobile: String?,
|
||||
var isUnderMedication: Boolean?,
|
||||
var isUnderTransfusion: Boolean?,
|
||||
val photoUrl: String?,
|
||||
var careOf: String?,
|
||||
var isMarried: Boolean?,
|
||||
var bloodGroup: String?,
|
||||
var address: Address?,
|
||||
var category: Category?,
|
||||
var registerDate: Date?,
|
||||
var uploadDate: Date?
|
||||
) {
|
||||
constructor() : this(
|
||||
"",
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
|
||||
enum class Gender {
|
||||
MALE,
|
||||
FEMALE,
|
||||
OTHER
|
||||
}
|
||||
|
||||
// enum class BloodGroup {
|
||||
// O_POSITIVE, O_NEGATIVE,
|
||||
// A_POSITIVE, A_NEGATIVE,
|
||||
// B_POSITIVE, B_NEGATIVE,
|
||||
// AB_POSITIVE, AB_NEGATIVE,
|
||||
// }
|
||||
|
||||
data class Address(
|
||||
var house: String?,
|
||||
val street: String?,
|
||||
var city: String?,
|
||||
val landMark: String?,
|
||||
var postOffice: String?,
|
||||
var district: String?,
|
||||
val subDistrict: String?,
|
||||
var state: String?,
|
||||
val vtc: String?,
|
||||
var pinCode: Int?,
|
||||
) {
|
||||
constructor() : this(null, null, null, null, null, null, null, null, null, null)
|
||||
}
|
||||
|
||||
enum class Category {
|
||||
GENERAL,
|
||||
OBC,
|
||||
SC,
|
||||
ST,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
data class UploadResponse(
|
||||
val success: Boolean
|
||||
)
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
|
||||
@Entity(tableName = "user_table")
|
||||
data class UserData(
|
||||
@PrimaryKey
|
||||
var _id: String = "",
|
||||
var name: String = "",
|
||||
var birthYear: String = "",
|
||||
var userImageURL: String = "",
|
||||
var location: Location? = null,
|
||||
var createdBy: String? = "",
|
||||
var reportUploadTime: String? = "",
|
||||
var testTime: String? = "",
|
||||
var testStatus: Boolean? = false,
|
||||
var mobileId: String = "",
|
||||
var deviceId: String = "",
|
||||
var deviceSerialNumber: String = "",
|
||||
var kitSerial: String = "",
|
||||
var csvPath: String = "",
|
||||
var reportPath: String = "",
|
||||
var result: TestRightResultType? = null,
|
||||
var resultRatio: Double? = null,
|
||||
var uploadFlag: Boolean? = false
|
||||
) {
|
||||
enum class Gender {
|
||||
MALE,
|
||||
FEMALE,
|
||||
OTHER
|
||||
}
|
||||
|
||||
data class Location(
|
||||
var latitude: Double? = null,
|
||||
var longitude: Double? = null
|
||||
)
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
package com.example.hpostesting.data.repository
|
||||
|
||||
import android.net.Uri
|
||||
import com.example.hpostesting.data.api.MolbioApi
|
||||
import com.example.hpostesting.data.model.PendingUploads
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.patient.MolbioLogin
|
||||
import com.example.hpostesting.data.model.patient.UploadResponse
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.firebase.storage.ktx.storage
|
||||
import com.google.gson.JsonObject
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import java.io.File
|
||||
import java.net.ConnectException
|
||||
import java.net.SocketTimeoutException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
class NetworkException(message: String, cause: Throwable) : Exception(message, cause)
|
||||
|
||||
@Singleton
|
||||
class DatabaseRepository @Inject constructor(
|
||||
private val molbioApi: MolbioApi
|
||||
) : Repository {
|
||||
|
||||
private val db: FirebaseFirestore = Firebase.firestore
|
||||
private val storage = Firebase.storage
|
||||
|
||||
private suspend fun <T : Any> safeApiCall(apiCall: suspend () -> T): com.example.hpostesting.data.Result<T> {
|
||||
return try {
|
||||
val response = apiCall.invoke()
|
||||
com.example.hpostesting.data.Result.Success(response)
|
||||
} catch (e: SocketTimeoutException) {
|
||||
com.example.hpostesting.data.Result.Error(NetworkException("Network timeout", e))
|
||||
} catch (e: ConnectException) {
|
||||
com.example.hpostesting.data.Result.Error(
|
||||
NetworkException(
|
||||
"Network connection failed",
|
||||
e
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
com.example.hpostesting.data.Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun login(jsonObject: JsonObject): com.example.hpostesting.data.Result<MolbioLogin> {
|
||||
return safeApiCall { molbioApi.login(jsonObject) }
|
||||
}
|
||||
|
||||
suspend fun uploadPdf(token:String,count:RequestBody,userId:RequestBody,file_csv:MultipartBody.Part,log_csv:MultipartBody.Part,deviceId:RequestBody): com.example.hpostesting.data.Result<UploadResponse> {
|
||||
return safeApiCall { molbioApi.uploadNewPdf(token,count,userId,file_csv,log_csv,deviceId) }
|
||||
}
|
||||
|
||||
suspend fun addTestToDatabase(data: UserData): Response<String> {
|
||||
return try {
|
||||
val userdata = db.collection("patientData").whereEqualTo("_id", data._id).get().await()
|
||||
if (userdata.documents.isNotEmpty()) {
|
||||
userdata.documents.forEach {
|
||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||
}
|
||||
}
|
||||
db.collection("testData").add(data).await()
|
||||
Response.Success(data._id)
|
||||
} catch (e: Exception) {
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
||||
try {
|
||||
|
||||
val file = Uri.fromFile(File(filePath))
|
||||
val riversRef = storage.reference.child("$patientID/${file.lastPathSegment}")
|
||||
riversRef.putFile(file).await()
|
||||
return Response.Success(true)
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun addToPendingQueue(pendingUploads: PendingUploads): Response<Boolean> {
|
||||
return try {
|
||||
db.collection("pendingUploads").document(pendingUploads.pendingId).set(pendingUploads)
|
||||
.await()
|
||||
|
||||
Response.Success(true)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAllFromPendingQueue(): List<PendingUploads> {
|
||||
val pendingList = mutableListOf<PendingUploads>()
|
||||
return try {
|
||||
val querySnapshot = db.collection("pendingUploads").orderBy("timeAdded").get().await()
|
||||
|
||||
for (doc in querySnapshot.documents) {
|
||||
val pendingFile = doc.toObject(PendingUploads::class.java)
|
||||
pendingFile?.let {
|
||||
pendingList.add(it)
|
||||
}
|
||||
}
|
||||
pendingList
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
pendingList
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun removeFromPendingQueue(fileName: String): Response<Boolean> {
|
||||
return try {
|
||||
db.collection("pendingUploads").document(fileName).delete().await()
|
||||
|
||||
Response.Success(true)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.example.hpostesting.data.repository
|
||||
|
||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||
|
||||
class LocalFileRepository(private val localFileDataSource: LocalFileDataSource) {
|
||||
fun saveCsvToDisk(filepath: String, contents: ArrayList<Array<String>>) =
|
||||
localFileDataSource.saveCsvToDisk(filepath, contents)
|
||||
|
||||
fun saveTextToDisk(filepath: String, contents: String) =
|
||||
localFileDataSource.saveTextToDisk(filepath, contents)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.hpostesting.data.repository
|
||||
|
||||
interface Repository {
|
||||
// suspend fun addToDatabase(data: PatientDetails)
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.example.hpostesting.domain
|
||||
|
||||
import android.app.job.JobParameters
|
||||
import android.app.job.JobService
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MyJobScheduler : JobService(){
|
||||
|
||||
@Inject
|
||||
lateinit var sharedPreference: SharedPreferences
|
||||
private lateinit var viewModel: TestRightViewModel
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(application)
|
||||
.create(TestRightViewModel::class.java)
|
||||
}
|
||||
|
||||
override fun onStartJob(p0: JobParameters?): Boolean {
|
||||
Log.d("jober","job started")
|
||||
sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
viewModel.networkStatusLiveData.observeForever {
|
||||
if (it) {
|
||||
fetchInternalDataAndUpload()
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun fetchInternalDataAndUpload() {
|
||||
val token = sharedPreference.getString(Constants.TOKEN,"")
|
||||
viewModel.allUserData.observeForever {userList ->
|
||||
userList.forEach {user ->
|
||||
if (user.uploadFlag == false) {
|
||||
viewModel.bulkUploadResultToDatabase(user, token)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onStopJob(p0: JobParameters?): Boolean {
|
||||
Log.d("jober_stop","Job stopped")
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.example.hpostesting.domain.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.room.Room
|
||||
import com.example.hpostesting.data.api.MolbioApi
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.dao.MyDatabase
|
||||
import com.example.hpostesting.data.dao.UserDao
|
||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||
import com.example.hpostesting.domain.SaveRawData
|
||||
import com.example.hpostesting.domain.SaveRawDataTest
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMyDatabase(@ApplicationContext context: Context): MyDatabase {
|
||||
return Room.databaseBuilder(
|
||||
context, MyDatabase::class.java, "my_database"
|
||||
).build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMyDao(myDatabase: MyDatabase): UserDao {
|
||||
return myDatabase.userDao()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContext(application: Application): Context {
|
||||
return application.applicationContext
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSaveRawData(): SaveRawData {
|
||||
val repository = LocalFileRepository(LocalFileDataSource())
|
||||
return SaveRawData(repository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSaveRawDataTest(): SaveRawDataTest {
|
||||
val repository = LocalFileRepository(LocalFileDataSource())
|
||||
return SaveRawDataTest(repository)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRetrofit(): Retrofit =
|
||||
Retrofit
|
||||
.Builder()
|
||||
.baseUrl(Constants.BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMolbioApi(retrofit: Retrofit): MolbioApi =
|
||||
retrofit.create(MolbioApi::class.java)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||
return context.getSharedPreferences("my_preferences", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideViewModelFactory(application: Application): ViewModelProvider.Factory {
|
||||
return ViewModelProvider.AndroidViewModelFactory.getInstance(application)
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
||||
import com.journeyapps.barcodescanner.ScanContract
|
||||
import com.journeyapps.barcodescanner.ScanIntentResult
|
||||
import com.journeyapps.barcodescanner.ScanOptions
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityKitScanBinding
|
||||
|
||||
class KitScanActivity : AppCompatActivity() {
|
||||
|
||||
private val TAG = "KitScanActivity"
|
||||
private lateinit var binding: ActivityKitScanBinding
|
||||
|
||||
private val barcodeLauncher = registerForActivityResult(
|
||||
ScanContract()
|
||||
) { result: ScanIntentResult ->
|
||||
if (result.contents.isNullOrEmpty()) {
|
||||
Toast.makeText(this, "Cancelled: Unable to scan, Try Again!!", Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
Log.d(TAG, result.contents)
|
||||
processScannedData(result.contents)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processScannedData(contents: String) {
|
||||
binding.nameEditText.setText(contents)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityKitScanBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken){
|
||||
DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial
|
||||
moveToNext()
|
||||
}
|
||||
|
||||
binding.nameEditText.setText("SMI/SC/")
|
||||
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
binding.btnScanNow.setOnClickListener {
|
||||
startScanningNow()
|
||||
}
|
||||
|
||||
|
||||
binding.btnGo.setOnClickListener {
|
||||
val serialNumber = binding.nameEditText.text.toString().trim()
|
||||
if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) {
|
||||
DataHolder.kitSerial = binding.nameEditText.text.toString()
|
||||
DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString()
|
||||
moveToNext()
|
||||
} else {
|
||||
Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSerialValid(s: String): Boolean {
|
||||
if (s.length != 17){
|
||||
binding.nameEditText.error = getString(R.string.invalid_kit)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun moveToNext() {
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
private fun startScanningNow() {
|
||||
val options = ScanOptions()
|
||||
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||
options.setPrompt("Scan a barcode")
|
||||
options.setCameraId(0) // Use a specific camera of the device
|
||||
|
||||
options.setBeepEnabled(true)
|
||||
options.setBarcodeImageEnabled(true)
|
||||
|
||||
options.setPrompt("Start Scanning")
|
||||
options.setOrientationLocked(false)
|
||||
// options.setTimeout(10000) // in ms
|
||||
|
||||
barcodeLauncher.launch(options)
|
||||
}
|
||||
|
||||
private fun checkDataNotNull(): Boolean {
|
||||
return if (DataHolder.selectedTest?._id == null) {
|
||||
Toast.makeText(
|
||||
applicationContext,
|
||||
"Please Select patient before starting test",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
val i = Intent(applicationContext, DashboardActivity::class.java)
|
||||
startActivity(i)
|
||||
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.location.Location
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.get
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.test.TestType
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationCallback
|
||||
import com.google.android.gms.location.LocationRequest
|
||||
import com.google.android.gms.location.LocationResult
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
private var myMenu: Menu? = null
|
||||
|
||||
private val TAG = "MainActivity"
|
||||
|
||||
private lateinit var fusedLocationClient: FusedLocationProviderClient
|
||||
private lateinit var locationCallback: LocationCallback
|
||||
|
||||
private var mUsbReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent) {
|
||||
val action = intent.action
|
||||
if (UsbManager.ACTION_USB_DEVICE_DETACHED == action) {
|
||||
DataHolder.usbConnected.value = false
|
||||
} else if (UsbManager.ACTION_USB_DEVICE_ATTACHED == action) {
|
||||
DataHolder.usbConnected.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.myToolbar)
|
||||
|
||||
setupListeners()
|
||||
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
||||
getLocation()
|
||||
locationCallback = object : LocationCallback() {
|
||||
override fun onLocationResult(locationResult: LocationResult) {
|
||||
locationResult.lastLocation?.let { location ->
|
||||
DataHolder.selectedTest!!.location = UserData.Location(location.latitude, location.longitude)
|
||||
Log.i("Location", DataHolder.location.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val filter = IntentFilter().apply {
|
||||
addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
|
||||
addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
|
||||
}
|
||||
registerReceiver(mUsbReceiver, filter)
|
||||
}
|
||||
|
||||
private fun checkAndUpdateUsbConnection() {
|
||||
val availableDrivers = UsbSerialProber.getDefaultProber()
|
||||
.findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager)
|
||||
if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Device matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}"
|
||||
)
|
||||
DataHolder.usbConnected.value = true
|
||||
} else if (availableDrivers.isNotEmpty()) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Device NOT matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}"
|
||||
)
|
||||
Toast.makeText(this, "Device Not Compatible", Toast.LENGTH_SHORT).show()
|
||||
DataHolder.usbConnected.value = false
|
||||
} else {
|
||||
Log.d(TAG, "Device NOT Connected")
|
||||
DataHolder.usbConnected.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.cvItem1.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLECERT
|
||||
val i = Intent(applicationContext, KitScanActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
binding.cvItem2.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLEFIND
|
||||
val i = Intent(applicationContext, KitScanActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
DataHolder.usbConnected.observe(this) {
|
||||
if (it) {
|
||||
myMenu?.get(0)?.icon =
|
||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
||||
} else {
|
||||
myMenu?.get(0)?.icon =
|
||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.my_menu, menu)
|
||||
myMenu = menu
|
||||
checkAndUpdateUsbConnection()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun requestCoarseLocationPermission() {
|
||||
val coarseLocationPermission = Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
val coarseLocationPermissionRequestCode = 101
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this, coarseLocationPermission
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this, arrayOf(coarseLocationPermission), coarseLocationPermissionRequestCode
|
||||
)
|
||||
} else {
|
||||
getLocation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestFineLocationPermission() {
|
||||
val fineLocationPermission = Manifest.permission.ACCESS_FINE_LOCATION
|
||||
val fineLocationPermissionRequestCode = 102
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this, fineLocationPermission
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this, arrayOf(fineLocationPermission), fineLocationPermissionRequestCode
|
||||
)
|
||||
} else {
|
||||
getLocation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLocation() {
|
||||
val coarseLocationPermission = Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
val fineLocationPermission = Manifest.permission.ACCESS_FINE_LOCATION
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
this, coarseLocationPermission
|
||||
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
|
||||
this, fineLocationPermission
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
// Handle location permission request if needed
|
||||
Toast.makeText(this, "Please enable location services", Toast.LENGTH_SHORT).show()
|
||||
requestCoarseLocationPermission()
|
||||
requestFineLocationPermission()
|
||||
return
|
||||
}
|
||||
|
||||
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
|
||||
location?.let {
|
||||
DataHolder.selectedTest!!.location =
|
||||
UserData.Location(location.latitude, location.longitude)
|
||||
} ?: run {
|
||||
requestLocationUpdates()
|
||||
}
|
||||
}.addOnFailureListener { exception: Exception ->
|
||||
exception.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestLocationUpdates() {
|
||||
val locationRequest = LocationRequest.create().apply {
|
||||
interval = 10000 // Interval for receiving location updates (in milliseconds)
|
||||
fastestInterval = 5000 // Fastest interval for location updates (in milliseconds)
|
||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY // Location accuracy priority
|
||||
}
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
this, Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
|
||||
this, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, null)
|
||||
}
|
||||
|
||||
private fun stopLocationUpdates() {
|
||||
fusedLocationClient.removeLocationUpdates(locationCallback)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
stopLocationUpdates()
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int, permissions: Array<String>, grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
when (requestCode) {
|
||||
101 -> {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// Coarse location permission granted
|
||||
requestFineLocationPermission()
|
||||
} else {
|
||||
// Coarse location permission denied
|
||||
Toast.makeText(this, "Coarse location permission denied", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
102 -> {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// Fine location permission granted
|
||||
getLocation()
|
||||
} else {
|
||||
// Fine location permission denied
|
||||
Toast.makeText(this, "Fine location permission denied", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.util.MyUtils
|
||||
import com.google.firebase.firestore.FirebaseFirestoreSettings
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivitySplashBinding
|
||||
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivitySplashBinding
|
||||
|
||||
private val requiredPermissions = listOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
)
|
||||
|
||||
private var allPermissionsGranted = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySplashBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setupFirestoreCache()
|
||||
setupStaticConstants()
|
||||
|
||||
requestPermissions()
|
||||
}
|
||||
|
||||
private fun setupStaticConstants() {
|
||||
DataHolder.mobileUniqueId =
|
||||
Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
|
||||
}
|
||||
|
||||
private fun setupFirestoreCache() {
|
||||
val settings = FirebaseFirestoreSettings.Builder()
|
||||
.setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED)
|
||||
.build()
|
||||
Firebase.firestore.firestoreSettings = settings
|
||||
}
|
||||
|
||||
private fun requestPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
requestPermissionsAboveAndroidR()
|
||||
} else {
|
||||
requestPermissionsBelowAndroidR()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun requestPermissionsAboveAndroidR() {
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
handlePermissionsResult(true)
|
||||
} else {
|
||||
val requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
handlePermissionsResult(true)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this,
|
||||
"You must grant permission to access all files to use the app",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
|
||||
requestPermissionLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestPermissionsBelowAndroidR() {
|
||||
val permissionsToRequest = requiredPermissions
|
||||
.filterNot { permission ->
|
||||
ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
.toTypedArray()
|
||||
|
||||
if (permissionsToRequest.isNotEmpty()) {
|
||||
requestPermissionLauncher.launch(permissionsToRequest)
|
||||
} else {
|
||||
checkLocationAndCameraPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkLocationAndCameraPermissions() {
|
||||
val fineLocationPermission = Manifest.permission.ACCESS_FINE_LOCATION
|
||||
val coarseLocationPermission = Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
val cameraPermission = Manifest.permission.CAMERA
|
||||
val locationPermissionsGranted =
|
||||
ContextCompat.checkSelfPermission(this, fineLocationPermission) == PackageManager.PERMISSION_GRANTED &&
|
||||
ContextCompat.checkSelfPermission(this, coarseLocationPermission) == PackageManager.PERMISSION_GRANTED
|
||||
val cameraPermissionGranted = ContextCompat.checkSelfPermission(this, cameraPermission) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
if (locationPermissionsGranted && cameraPermissionGranted) {
|
||||
handlePermissionsResult(true)
|
||||
} else {
|
||||
val permissionsToRequest = mutableListOf<String>()
|
||||
if (!locationPermissionsGranted) {
|
||||
permissionsToRequest.add(fineLocationPermission)
|
||||
permissionsToRequest.add(coarseLocationPermission)
|
||||
}
|
||||
if (!cameraPermissionGranted) {
|
||||
permissionsToRequest.add(cameraPermission)
|
||||
}
|
||||
|
||||
requestPermissionLauncher.launch(permissionsToRequest.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
private val requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
||||
val grantedPermissions = permissions.entries.filter { it.value }.map { it.key }
|
||||
handlePermissionsResult(grantedPermissions.size == requiredPermissions.size)
|
||||
}
|
||||
|
||||
private fun handlePermissionsResult(allGranted: Boolean) {
|
||||
allPermissionsGranted = allGranted
|
||||
if (allGranted) {
|
||||
moveToLandingPage()
|
||||
} else {
|
||||
Toast.makeText(this, "All permissions are required to use the app.", Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveToLandingPage() {
|
||||
createAppFolder()
|
||||
val intent = Intent(applicationContext, DashboardActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun createAppFolder() {
|
||||
val folderPath = MyUtils.createAppFolder(applicationContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.example.hpostesting.presentation.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.UserItemViewBinding
|
||||
|
||||
class UserListAdapter(options: FirestoreRecyclerOptions<UserData>, private val view: View) :
|
||||
FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
||||
|
||||
class OrderItemViewHolder(val binding: UserItemViewBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OrderItemViewHolder {
|
||||
return OrderItemViewHolder(
|
||||
UserItemViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBindViewHolder(holder: OrderItemViewHolder, position: Int, model: UserData) {
|
||||
holder.binding.apply {
|
||||
userName.text = model.name
|
||||
userId.text = model._id
|
||||
Glide.with(view).load(model.userImageURL).into(userImage)
|
||||
if (model.testStatus!!) {
|
||||
teststatus.text = "Test concluded"
|
||||
|
||||
} else {
|
||||
teststatus.text = "Test is Pending"
|
||||
}
|
||||
userCard.setOnClickListener {
|
||||
if (model.testStatus != null) {
|
||||
if (model.testStatus!!) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Test has been already conducted for this user",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
DataHolder.selectedTest = model
|
||||
view.findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||
|
||||
@AndroidEntryPoint
|
||||
class DashboardActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||
private lateinit var binding: ActivityDashboardBinding
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityDashboardBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.appBarDashboard.toolbar)
|
||||
|
||||
val drawerLayout: DrawerLayout = binding.drawerLayout
|
||||
val navView: NavigationView = binding.navView
|
||||
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
||||
|
||||
appBarConfiguration = AppBarConfiguration(
|
||||
setOf(
|
||||
R.id.nav_home, R.id.nav_profile, R.id.nav_settings
|
||||
), drawerLayout
|
||||
)
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.dashboard, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding
|
||||
|
||||
class GalleryFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentGalleryBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
|
||||
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
// val textView: TextView = binding.textGallery
|
||||
// galleryViewModel.text.observe(viewLifecycleOwner) {
|
||||
//// textView.text = it
|
||||
// }
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -1,290 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.gson.JsonObject
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import java.util.Locale
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private lateinit var rvAdapter: UserListAdapter
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private var loginCount = 1
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
DataHolder.selectedTest = null
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
deleteIncompleteRegistrations(userData)
|
||||
}
|
||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isConnected ->
|
||||
if (isConnected) {
|
||||
binding.internetAvailableCL.visibility = View.VISIBLE
|
||||
binding.internetNotAvailableCL.visibility = View.GONE
|
||||
login()
|
||||
loadUserData()
|
||||
setSearch()
|
||||
// checkForLocalDBData()
|
||||
} else {
|
||||
binding.internetAvailableCL.visibility = View.GONE
|
||||
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
||||
setUserId()
|
||||
}
|
||||
}
|
||||
binding.btnLogout.setOnClickListener {
|
||||
logoutUser(requireContext())
|
||||
}
|
||||
binding.uploadData.setOnClickListener {
|
||||
showUploadDialog()
|
||||
}
|
||||
//
|
||||
// val jobScheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
//
|
||||
// val jobInfo = JobInfo.Builder(1, ComponentName(this, MyJobScheduler::class.java))
|
||||
// .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||
// .setPersisted(true)
|
||||
// .setPeriodic(30 * 60 * 1000)
|
||||
// .build()
|
||||
// jobScheduler.schedule(jobInfo)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val jsonObject = JsonObject()
|
||||
jsonObject.addProperty("Username", "hposdevice")
|
||||
jsonObject.addProperty("Password", "sickle")
|
||||
viewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
val editor = sharedPreference.edit()
|
||||
editor.putString(Constants.TOKEN, response.data.token)
|
||||
editor.apply()
|
||||
Log.d("login_api", "called")
|
||||
// showUploadDialog()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
if (loginCount < 3) {
|
||||
viewModel.login(jsonObject)
|
||||
loginCount++
|
||||
}
|
||||
Log.d("API Error", response.exception.message.toString())
|
||||
}
|
||||
|
||||
is Result.Loading -> {
|
||||
Toast.makeText(requireContext(), "Loading", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun login() {
|
||||
val jsonObject = JsonObject()
|
||||
jsonObject.addProperty("Username", "hposdevice")
|
||||
jsonObject.addProperty("Password", "sickle")
|
||||
viewModel.login(jsonObject)
|
||||
}
|
||||
|
||||
private fun setUserId() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val userId = binding.userId.text.toString()
|
||||
if (userId.length >= 18) {
|
||||
val userData = UserData(_id = userId)
|
||||
DataHolder.selectedTest = userData
|
||||
findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||
} else {
|
||||
val errorMessage = getString(R.string.user_id_error_message)
|
||||
Toast.makeText(requireContext(), errorMessage, Toast.LENGTH_SHORT).show()
|
||||
binding.userId.error = errorMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadUserData() {
|
||||
val query = Firebase.firestore.collection("patientData")
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
}
|
||||
|
||||
private fun saveUserId(userId: String) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.USER_ID, userId)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
private fun logoutUser(context: Context) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle("Log Out")
|
||||
builder.setMessage("Do you want to LogOut the Application?")
|
||||
|
||||
// Positive button
|
||||
builder.setPositiveButton("Yes") { dialog, _ ->
|
||||
saveUserId("")
|
||||
findNavController().navigate(R.id.action_nav_home_to_loginFragment)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
// Negative button
|
||||
builder.setNegativeButton("No") { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
|
||||
private fun getData(search: String?, field: String) {
|
||||
val capitalizedSearch = search?.replaceFirstChar {
|
||||
if (search.lowercase()
|
||||
.startsWith(it.lowercase())
|
||||
) it.titlecase(Locale.getDefault()) else it.toString()
|
||||
|
||||
}
|
||||
|
||||
val query = Firebase.firestore.collection("patientData").orderBy(field).startAt(search)
|
||||
.endAt(search + "\uf8ff")
|
||||
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
}
|
||||
|
||||
private fun setSearch() {
|
||||
binding.searchProduct.setOnQueryTextListener(object :
|
||||
androidx.appcompat.widget.SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
return if (!query.isNullOrEmpty()) {
|
||||
val field = when {
|
||||
binding.userIdRadioButton.isChecked -> "_id"
|
||||
binding.abhaIdRadioButton.isChecked -> "abhaId"
|
||||
binding.aadharIdRadioButton.isChecked -> "aadharId"
|
||||
else -> null
|
||||
}
|
||||
field?.let { getData(query, it) }
|
||||
false
|
||||
} else {
|
||||
loadUserData()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(query: String?): Boolean {
|
||||
return if (!query.isNullOrEmpty()) {
|
||||
val field = when {
|
||||
binding.userIdRadioButton.isChecked -> "_id"
|
||||
binding.abhaIdRadioButton.isChecked -> "abhaId"
|
||||
binding.aadharIdRadioButton.isChecked -> "aadharId"
|
||||
else -> null
|
||||
}
|
||||
field?.let { getData(query, it) }
|
||||
false
|
||||
} else {
|
||||
loadUserData()
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun checkForLocalDBData() {
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility = if (userDataList.isEmpty()) View.GONE else View.VISIBLE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
}
|
||||
|
||||
private fun showUploadDialog() {
|
||||
val builder = AlertDialog.Builder(requireContext())
|
||||
builder.setTitle(R.string.upload_db_registration_title)
|
||||
builder.setMessage(R.string.upload_db_registration_message)
|
||||
|
||||
builder.setPositiveButton(R.string.upload) { dialog, _ ->
|
||||
uploadLocalDBData(dialog)
|
||||
}
|
||||
|
||||
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun uploadLocalDBData(dialog: DialogInterface) {
|
||||
val token = sharedPreference.getString(Constants.TOKEN, "")
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
if (userDataList.isEmpty()) {
|
||||
dialog.dismiss()
|
||||
} else {
|
||||
userDataList.forEach { userData ->
|
||||
viewModel.bulkUploadResultToDatabase(userData, token!!)
|
||||
}
|
||||
dialog.dismiss()
|
||||
Toast.makeText(
|
||||
requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteIncompleteRegistrations(userDataList: List<UserData>) {
|
||||
userDataList.forEach { userData ->
|
||||
if (userData._id.isEmpty()) {
|
||||
viewModel.deleteById(userData._id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
interface ItemClickListener {
|
||||
fun onClick(pos: Int)
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpostesting.presentation.dashboard.ui.slideshow.SlideshowViewModel
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentSlideshowBinding
|
||||
|
||||
class SlideshowFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentSlideshowBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val slideshowViewModel =
|
||||
ViewModelProvider(this).get(SlideshowViewModel::class.java)
|
||||
|
||||
_binding = FragmentSlideshowBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
// val textView: TextView = binding.textSlideshow
|
||||
// slideshowViewModel.text.observe(viewLifecycleOwner) {
|
||||
// textView.text = it
|
||||
// }
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding
|
||||
|
||||
class LoginFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentLoginBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
init()
|
||||
}
|
||||
|
||||
|
||||
private fun init() {
|
||||
if (isUserLoggedIn()) {
|
||||
navigateToHomeFragment()
|
||||
return
|
||||
}
|
||||
|
||||
binding.btnLogin.setOnClickListener {
|
||||
val loginId = binding.loginId.text.toString()
|
||||
val password = binding.password.text.toString()
|
||||
|
||||
if (loginId.isNotBlank() && password.isNotBlank()) {
|
||||
performLogin(loginId, password)
|
||||
} else {
|
||||
if (loginId.isBlank()) {
|
||||
binding.loginId.error = "Please enter a proper Login ID"
|
||||
}
|
||||
if (password.isBlank()) {
|
||||
binding.password.error = "Please enter a proper password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isUserLoggedIn(): Boolean {
|
||||
return sharedPreference.getString(Constants.USER_ID, "")?.isNotBlank() == true
|
||||
}
|
||||
|
||||
private fun navigateToHomeFragment() {
|
||||
findNavController().navigate(R.id.action_loginFragment_to_homeFragment)
|
||||
}
|
||||
|
||||
private fun performLogin(loginId: String, password: String) {
|
||||
val matchingId = Constants.STATICID.firstOrNull { it == loginId }
|
||||
if (matchingId != null) {
|
||||
if (password == Constants.password) {
|
||||
saveUserId(loginId)
|
||||
navigateToHomeFragment()
|
||||
return
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Wrong Password", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
Toast.makeText(requireContext(), "Wrong UserID", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun saveUserId(userId: String) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.USER_ID, userId)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard.ui.gallery
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class mGalleryViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is gallery Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard.ui.home
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is home Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.example.hpostesting.presentation.dashboard.ui.slideshow
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class SlideshowViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is slideshow Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,210 +0,0 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
import com.example.hpostesting.data.model.test.TestType
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.util.MyUtils.calculateAgeFromYOB
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightResultsBinding
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@AndroidEntryPoint
|
||||
class TestRightResults : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightResultsBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTestRightResultsBinding.inflate(inflater, container, false)
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupListeners()
|
||||
updateResults()
|
||||
|
||||
viewModel.fireBaseUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
"Success" -> {
|
||||
Toast.makeText(
|
||||
requireContext(), "Test Results Upload Successfully", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
"Loading" -> {
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
Toast.makeText(requireContext(), "Test upload failed, please try again $it", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.ivHome.setOnClickListener {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
checkBloodGroup()
|
||||
}
|
||||
}
|
||||
binding.ivNext.setOnClickListener {
|
||||
val i = Intent(requireContext().applicationContext, DashboardActivity::class.java)
|
||||
startActivity(i)
|
||||
// moveToSamplePage()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkBloodGroup() {
|
||||
binding.apply {
|
||||
val bloodGroup = etBloodGroup.text.toString()
|
||||
if (bloodGroup.isEmpty()) {
|
||||
etBloodGroup.error = "Please enter your blood group"
|
||||
} else {
|
||||
val db: FirebaseFirestore = Firebase.firestore
|
||||
val userdata =
|
||||
db.collection("patientData").whereEqualTo("_id", viewModel.testDetails?._id)
|
||||
.get().await()
|
||||
if (userdata.documents.isNotEmpty()) {
|
||||
userdata.documents.forEach {
|
||||
db.collection("patientData").document(it.id).update("bloodGroup", bloodGroup)
|
||||
}
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
val i = Intent(requireContext().applicationContext, DashboardActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateResults() {
|
||||
if (viewModel.testDetails?.name == "" && viewModel.testDetails?.birthYear == "") {
|
||||
binding.tvName.visibility = View.GONE
|
||||
binding.tvAge.visibility = View.GONE
|
||||
} else {
|
||||
binding.tvName.text = getString(R.string.name_in_textview, viewModel.testDetails?.name)
|
||||
binding.tvAge.text = getString(
|
||||
R.string.age_in_textview,
|
||||
viewModel.testDetails?.birthYear?.toInt()?.calculateAgeFromYOB().toString()
|
||||
)
|
||||
}
|
||||
|
||||
binding.tvId.text = getString(R.string.patient_id_in_tv, viewModel.testDetails?._id)
|
||||
|
||||
|
||||
if (DataHolder.selectedTestType == TestType.SICKLECERT) {
|
||||
// when (viewModel.testDetails?.result) {
|
||||
// TestRightResultType.NORMAL -> {
|
||||
// binding.resultNormal.visibility = View.VISIBLE
|
||||
// }
|
||||
//
|
||||
// TestRightResultType.SICKLECELLDISEASE -> {
|
||||
// binding.resultDisease.visibility = View.VISIBLE
|
||||
// }
|
||||
//
|
||||
// TestRightResultType.SICKLECELLTRAIT -> {
|
||||
// binding.resultTrait.visibility = View.VISIBLE
|
||||
// }
|
||||
//
|
||||
// TestRightResultType.POSITIVEBORDERLINE -> {
|
||||
// binding.resultPositiveBorderline.visibility = View.VISIBLE
|
||||
// binding.tvRecommended.visibility = View.VISIBLE
|
||||
// }
|
||||
//
|
||||
// TestRightResultType.NEGATIVEBORDERLINE -> {
|
||||
// binding.resultNegativeBorderline.visibility = View.VISIBLE
|
||||
// binding.tvRecommended.visibility = View.VISIBLE
|
||||
// }
|
||||
// else -> {
|
||||
//// binding.resultUndefined.visibility = View.VISIBLE
|
||||
// Toast.makeText(
|
||||
// requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG
|
||||
// ).show()
|
||||
// moveToSamplePage()
|
||||
// }
|
||||
// }
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
} else {
|
||||
when (viewModel.testDetails?.result) {
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
binding.resultDisease.text = "Positive"
|
||||
}
|
||||
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
binding.resultNormal.text = "Negative"
|
||||
}
|
||||
|
||||
else -> {
|
||||
Toast.makeText(
|
||||
requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG
|
||||
).show()
|
||||
moveToSamplePage()
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
val deviceStaticId = sharedPreference.getString(Constants.USER_ID, "")
|
||||
val token = sharedPreference.getString(Constants.TOKEN,"")
|
||||
if (isNetworkAvailable) {
|
||||
if (token != null) {
|
||||
viewModel.uploadResultToDatabase(requireContext(), true, deviceStaticId!!,token)
|
||||
}
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
} else {
|
||||
if (token != null) {
|
||||
viewModel.uploadResultToDatabase(requireContext(), false, deviceStaticId!!,token)
|
||||
}
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Internet not available, Test Data added to Local DB",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun moveToSamplePage() {
|
||||
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
||||
DataHolder.sampleReadCounter = 0
|
||||
DataHolder.isReferenceTaken = false
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightExpReference())
|
||||
.commit()
|
||||
} else {
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightExpSample())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
package com.example.hpostesting.presentation.testRight
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.dao.UserDao
|
||||
import com.example.hpostesting.data.model.CalculationVariableForTest
|
||||
import com.example.hpostesting.data.model.ErrorMessage
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.patient.MolbioLogin
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.test.TestRightCalculationData
|
||||
import com.example.hpostesting.data.model.test.TestRightDeviceConstants
|
||||
import com.example.hpostesting.data.model.test.TestType
|
||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||
import com.example.hpostesting.domain.ResultCalculationWithMaxImpl
|
||||
import com.example.hpostesting.domain.SaveRawData
|
||||
import com.example.hpostesting.domain.SaveRawDataTest
|
||||
import com.example.hpostesting.domain.SickleFindResultCaluculationWithMaxImpl
|
||||
import com.example.hpostesting.domain.TestRightResultCalculation
|
||||
import com.example.hpostesting.util.MyUtils
|
||||
import com.google.firebase.storage.FirebaseStorage
|
||||
import com.google.gson.JsonObject
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
@HiltViewModel
|
||||
class TestRightViewModel @Inject constructor(
|
||||
private val saveRawData: SaveRawData,
|
||||
private val saveRawDataTest: SaveRawDataTest,
|
||||
private val repository: DatabaseRepository,
|
||||
private val userDao: UserDao,
|
||||
context: Context
|
||||
) : ViewModel() {
|
||||
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
|
||||
val errorTriggered = MutableLiveData<ErrorMessage>()
|
||||
var numberOfSampleRun = 0
|
||||
|
||||
val loginResponse = MutableLiveData<Result<MolbioLogin>>()
|
||||
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
val testDetails = DataHolder.selectedTest
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
val networkStatusLiveData: LiveData<Boolean>
|
||||
get() = _networkStatusLiveData
|
||||
|
||||
val allUserData = userDao.getAll()
|
||||
|
||||
lateinit var calculationData: TestRightCalculationData
|
||||
|
||||
/* (For exp sample) Contains pixel no. -> Intensity of light falling on that pixel */
|
||||
val intensitySampleArray = ArrayList<Double>()
|
||||
|
||||
val wavelengthToAbsorbance = ArrayList<ArrayList<Double>>()
|
||||
|
||||
val calculationVariableList = ArrayList<CalculationVariableForTest>()
|
||||
|
||||
fun mapDeviceConstants(string: String) {
|
||||
// Log.d(TAG, "mapDeviceConstants() called")
|
||||
// Log.d(TAG, "mapDeviceConstants() value -> $string")
|
||||
if (string.isNotEmpty()) {
|
||||
val listOfStrings = string.split(",")
|
||||
if (listOfStrings.size >= 4) {
|
||||
DataHolder.deviceConstant = TestRightDeviceConstants(
|
||||
listOfStrings[0].trim(),
|
||||
listOfStrings[1].trim(),
|
||||
listOfStrings[2].trim(),
|
||||
listOfStrings[3].trim()
|
||||
)
|
||||
|
||||
mapPixelNumberToWavelength()
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 201: In processing the data from device"
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 201: In processing the data from device", Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error (showing error if empty by using a mutable error string)
|
||||
// "Error 202: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 202: Unable to fetch data from device.", Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
fun mapPixelNumberToWavelength() {
|
||||
// viewModelScope.launch {
|
||||
DataHolder.wavelengthToPixelArray.clear()
|
||||
if (DataHolder.deviceConstant != null) {
|
||||
for (x in 1..Constants.TEST_RIGHT_TOTAL_PIXEL) {
|
||||
// val index = x - 1
|
||||
val wavelength: Double = (DataHolder.deviceConstant!!.a.toDouble() * (x.toDouble()
|
||||
.pow((3).toDouble()))) + (DataHolder.deviceConstant!!.b.toDouble() * (x.toDouble()
|
||||
.pow((2).toDouble()))) + (DataHolder.deviceConstant!!.c.toDouble() * x) + (DataHolder.deviceConstant!!.d.toDouble())
|
||||
|
||||
DataHolder.wavelengthToPixelArray.add(wavelength)
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 203: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 203: Unable to fetch data from device.", Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
fun mapIntensityValues(fullString: String, isReference: Boolean) {
|
||||
|
||||
if (isReference) DataHolder.intensityReferenceArray.clear()
|
||||
else intensitySampleArray.clear()
|
||||
|
||||
val listOfString = fullString.split("\n")
|
||||
|
||||
for (line in listOfString) {
|
||||
if ("Buf" in line) {/* Removing trailing spaces and "Buf" from the string then taking lhs & rhs of ':' */
|
||||
val numbers = line.trim().substring(3).split(":")
|
||||
if (numbers.size >= 2) {
|
||||
|
||||
if (isReference) DataHolder.intensityReferenceArray.add(numbers[1].toDouble())
|
||||
else intensitySampleArray.add(numbers[1].toDouble())
|
||||
} else {
|
||||
// "Error 204: Unable to fetch data from device."
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 204: Unable to fetch data from device.", Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
// fun mapWavelengthToAbsorbance(){
|
||||
// var indexInReference = intensityReferenceArray.size - 1
|
||||
// var indexInSample = intensitySampleArray.size - 1
|
||||
// for (each in wavelengthToPixelArray){
|
||||
// val wavelength = each[0]
|
||||
// val invertedPixel = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - each[1]
|
||||
//
|
||||
// var Io = 0.0
|
||||
// if (intensityReferenceArray[indexInReference][0].toInt() == invertedPixel.toInt()){
|
||||
// Io = intensityReferenceArray[indexInReference][1]
|
||||
// }
|
||||
//
|
||||
// var I = 0.0
|
||||
// if (intensitySampleArray[indexInSample][0].toInt() == invertedPixel.toInt()){
|
||||
// I = intensitySampleArray[indexInSample][1]
|
||||
// }
|
||||
//
|
||||
// val absorbance = log10(Io/I)
|
||||
//
|
||||
// val temp = ArrayList<Double>(2)
|
||||
// temp.add(wavelength)
|
||||
// temp.add(absorbance)
|
||||
// wavelengthToAbsorbance.add(temp)
|
||||
//
|
||||
// indexInReference--
|
||||
// indexInSample--
|
||||
// }
|
||||
// }
|
||||
|
||||
fun mapWavelengthToAbsorbance() {
|
||||
if (DataHolder.intensityReferenceArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != DataHolder.intensityReferenceArray.size) {
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 205: Unable to fetch data from device, please try again by reopening the app",
|
||||
Constants.ERROR_CRITICAL
|
||||
)
|
||||
)
|
||||
|
||||
throw Exception("Inconsistency in the data, size of arrays are not same. \nintensityReferenceArray.size = ${DataHolder.intensityReferenceArray.size} ; intensitySampleArray.size = ${intensitySampleArray.size} ; wavelengthToPixelArray.size = ${DataHolder.wavelengthToPixelArray.size}")
|
||||
}
|
||||
|
||||
wavelengthToAbsorbance.clear()
|
||||
calculationVariableList.clear()
|
||||
|
||||
// Index pointing to last of the array
|
||||
// var indexInIntensityArrays = intensityReferenceArray.size - 1
|
||||
// for ((index,wavelength) in wavelengthToPixelArray.withIndex()) {
|
||||
for (index in 0 until DataHolder.wavelengthToPixelArray.size) {
|
||||
|
||||
val invertedPixelIndex = (Constants.TEST_RIGHT_TOTAL_PIXEL) - (index + 1)
|
||||
|
||||
val i0 = DataHolder.intensityReferenceArray[invertedPixelIndex]
|
||||
// if (intensityReferenceArray[indexInIntensityArrays][0].toInt() == invertedPixelIndex.toInt()) {
|
||||
// Io = intensityReferenceArray[indexInIntensityArrays][1]
|
||||
// } else {
|
||||
// // Not needed - As you are calculating index and also checking the size of all 3 array before
|
||||
// throw Exception("Inconsistency in the data, pixel not found in intensity reference array \n pixel in intensityReferenceArray = ${intensityReferenceArray[indexInIntensityArrays][0]} & inverted pixel value = ${invertedPixelIndex.toInt()}")
|
||||
// }
|
||||
|
||||
val i1 = intensitySampleArray[invertedPixelIndex]
|
||||
// if (intensitySampleArray[indexInIntensityArrays][0].toInt() == invertedPixelIndex.toInt()) {
|
||||
// I = intensitySampleArray[indexInIntensityArrays][1]
|
||||
// } else {
|
||||
// // Not needed - As you are calculating index and also checking the size of all 3 array before
|
||||
// throw Exception("Inconsistency in the data, pixel not found in intensity sample array \n pixel in intensitySampleArray = ${intensitySampleArray[indexInIntensityArrays][0]} & inverted pixel value = ${invertedPixelIndex.toInt()}")
|
||||
// }
|
||||
|
||||
// if (I==0.0 || Io == 0.0){
|
||||
// throw Exception("error in data calculation I = $I & Io = $Io")
|
||||
// }
|
||||
|
||||
val absorbance = log10(i0 / i1)
|
||||
val wavelength = DataHolder.wavelengthToPixelArray[index]
|
||||
val temp = ArrayList<Double>(2)
|
||||
temp.add(wavelength)
|
||||
temp.add(absorbance)
|
||||
wavelengthToAbsorbance.add(temp)
|
||||
|
||||
// Todo: Remove
|
||||
val calculationVariableForTest = CalculationVariableForTest()
|
||||
calculationVariableForTest.pixelNo = index + 1
|
||||
calculationVariableForTest.invertedPixelNo =
|
||||
invertedPixelIndex + 1 // 0-based indexing
|
||||
calculationVariableForTest.wavelength = wavelength
|
||||
calculationVariableForTest.I0 = i0
|
||||
calculationVariableForTest.I = i1
|
||||
calculationVariableForTest.absorbance = absorbance
|
||||
calculationVariableList.add(calculationVariableForTest)
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateResults() {
|
||||
DataHolder.sampleReadCounter++
|
||||
|
||||
// patientDetails.results = ResultCalculationZeroImpl().getResults(wavelengthToPixelArray, intensityReferenceArray, intensitySampleArray)
|
||||
|
||||
|
||||
val resultCalculation: TestRightResultCalculation = ResultCalculationWithMaxImpl()
|
||||
calculationData = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
// patientDetails.results = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
// patientDetails.results = calculationData.result
|
||||
|
||||
testDetails?.result = calculationData.result
|
||||
testDetails?.resultRatio = calculationData.ratioValue
|
||||
testDetails?.testStatus = true
|
||||
|
||||
}
|
||||
|
||||
fun calculateResultsForSickleFind() {
|
||||
DataHolder.sampleReadCounter++
|
||||
val resultCalculation: TestRightResultCalculation =
|
||||
SickleFindResultCaluculationWithMaxImpl()
|
||||
calculationData = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
testDetails?.result = calculationData.result
|
||||
testDetails?.testStatus = true
|
||||
|
||||
}
|
||||
|
||||
fun saveCsv(appContext: Context, filename: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
// SaveRawData().saveCsv(folderPath!!, filename, wavelengthToAbsorbance)
|
||||
saveRawData.saveCsv(folderPath!!, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
// SaveRawData().saveCsv(folderPath, filename, wavelengthToAbsorbance)
|
||||
saveRawData.saveCsv(folderPath, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveCsvForTesting(appContext: Context, filename: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
// SaveRawDataTest().saveCsv(folderPath!!, filename, calculationVariableList)
|
||||
saveRawDataTest.saveCsv(folderPath!!, filename, calculationVariableList)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
// SaveRawDataTest().saveCsv(folderPath, filename, calculationVariableList)
|
||||
saveRawDataTest.saveCsv(folderPath, filename, calculationVariableList)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(appContext: Context, fileName: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
// SaveRawData().saveLog(folderPath!!, fileName, calculationData)
|
||||
saveRawData.saveLog(folderPath!!, fileName, calculationData)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
// SaveRawData().saveLog(folderPath, fileName, calculationData)
|
||||
saveRawData.saveLog(folderPath, fileName, calculationData)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogWithPatient(appContext: Context, fileName: String) {
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
// SaveRawData().saveLogWithPatientData(
|
||||
saveRawData.saveLogWithPatientData(
|
||||
folderPath!!, fileName, calculationData, testDetails
|
||||
)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
// SaveRawData().saveLogWithPatientData(
|
||||
saveRawData.saveLogWithPatientData(
|
||||
folderPath, fileName, calculationData, testDetails
|
||||
)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogTest(appContext: Context, isReference: Boolean, fullString: String) {
|
||||
var fileName: String =
|
||||
"test_log_" + SimpleDateFormat("ddMMyyyy_HHmmss").format(Date()) + ".txt"
|
||||
fileName = if (isReference) {
|
||||
"reference_$fileName"
|
||||
} else {
|
||||
"sample_$fileName"
|
||||
}
|
||||
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
saveRawDataTest.saveLog(folderPath!!, fileName, isReference, fullString)
|
||||
// SaveRawDataTest().saveLog(folderPath!!, fileName, isReference, fullString)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
saveRawDataTest.saveLog(folderPath, fileName, isReference, fullString)
|
||||
// SaveRawDataTest().saveLog(folderPath, fileName, isReference, fullString)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCSVFileName(): String {
|
||||
val prefixCsv: String =
|
||||
if (DataHolder.selectedTestType == TestType.SICKLECERT) "HPOSSC_${testDetails?._id}"
|
||||
else "HPOSSF_${testDetails?._id}"
|
||||
|
||||
val fileExtensionCsv = ".csv"
|
||||
|
||||
return prefixCsv + fileExtensionCsv
|
||||
}
|
||||
|
||||
fun getLogFileName(): String {
|
||||
val prefixTxt = "log_${testDetails?._id}"
|
||||
val fileExtensionTxt = ".txt"
|
||||
return prefixTxt + fileExtensionTxt
|
||||
}
|
||||
|
||||
private fun addResultTestToDb(csvFilePath: String, logTxtFilePath: String, token: String) {
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
viewModelScope.launch {
|
||||
testDetails!!.reportUploadTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(testDetails)) {
|
||||
is Response.Success -> {
|
||||
uploadToMolbio(csvFilePath, logTxtFilePath, token)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun uploadToMolbio(csvFilePath: String, logTxtFilePath: String, token: String) = viewModelScope.launch {
|
||||
val csv_file = File(csvFilePath)
|
||||
val log_file=File(logTxtFilePath)
|
||||
|
||||
val csv_reqBody = RequestBody.create(MediaType.parse("text/csv"), csv_file)
|
||||
val log_reqBody = RequestBody.create(MediaType.parse("text/txt"), log_file)
|
||||
val deviceId= testDetails?.deviceSerialNumber?.let {
|
||||
RequestBody.create(MediaType.parse("text/plain"),
|
||||
it
|
||||
)
|
||||
}
|
||||
val userId= testDetails?._id?.let { RequestBody.create(MediaType.parse("text/plain"), it) }
|
||||
val csv_formData = MultipartBody.Part.createFormData("csv_file", csv_file.name, csv_reqBody)
|
||||
val log_formData = MultipartBody.Part.createFormData("csv_file", log_file.name, log_reqBody)
|
||||
val count = "1".let {
|
||||
RequestBody.create(MediaType.parse("text/plain"),
|
||||
it
|
||||
)
|
||||
}
|
||||
repository.uploadPdf(token, count, userId!!, csv_formData, log_formData, deviceId!!).let { upload ->
|
||||
when(upload) {
|
||||
is Result.Success -> {
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
is Result.Error -> {
|
||||
fireBaseUpload.postValue(upload.exception.message)
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean, deviceSerialNumber: String, token: String) = viewModelScope.launch {
|
||||
fireBaseUpload.postValue("Loading")
|
||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||
testDetails?.csvPath = csvFilePath
|
||||
testDetails?.reportPath = logTxtFilePath
|
||||
testDetails?.deviceSerialNumber = deviceSerialNumber
|
||||
if (isOnline) {
|
||||
val storageRef = FirebaseStorage.getInstance().reference
|
||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||
|
||||
try {
|
||||
val csvFileUri = Uri.fromFile(File(csvFilePath))
|
||||
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
||||
|
||||
val csvUploadTask =
|
||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!).putFile(csvFileUri)
|
||||
.await()
|
||||
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
||||
.putFile(logTxtFileUri).await()
|
||||
|
||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
||||
testDetails?.csvPath = csvUri
|
||||
testDetails?.reportPath = logUri
|
||||
addResultTestToDb(csvFilePath, logTxtFilePath, token)
|
||||
} catch (exception: Exception) {
|
||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||
}
|
||||
} else {
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
userDao.insertAll(testDetails!!).let {
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bulkUploadResultToDatabase(userData: UserData, token: String?) = viewModelScope.launch {
|
||||
fireBaseUpload.postValue("Loading")
|
||||
val storageRef = FirebaseStorage.getInstance().reference
|
||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||
try {
|
||||
val csvFileUri = Uri.fromFile(File(userData.csvPath))
|
||||
val logTxtFileUri = Uri.fromFile(File(userData.reportPath))
|
||||
|
||||
val csvUploadTask =
|
||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!).putFile(csvFileUri)
|
||||
.await()
|
||||
val logUploadTask =
|
||||
storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!).putFile(logTxtFileUri)
|
||||
.await()
|
||||
|
||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||
|
||||
val csvFilePath = userData.csvPath
|
||||
val logTxtFilePath = userData.reportPath
|
||||
|
||||
userData.csvPath = csvUri
|
||||
userData.reportPath = logUri
|
||||
|
||||
bulkAddResultTestToDb(userData, csvFilePath, logTxtFilePath, token)
|
||||
} catch (exception: Exception) {
|
||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bulkAddResultTestToDb(
|
||||
userData: UserData,
|
||||
csvFilePath: String,
|
||||
logTxtFilePath: String,
|
||||
token: String?
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
userData.reportUploadTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(userData)) {
|
||||
is Response.Success -> {
|
||||
uploadToMolbio(csvFilePath, logTxtFilePath, token!!)
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteById(userId: String) = viewModelScope.launch {
|
||||
userDao.deleteById(id = userId)
|
||||
}
|
||||
|
||||
fun login(jsonObject: JsonObject) = viewModelScope.launch {
|
||||
loginResponse.postValue(Result.Loading())
|
||||
repository.login(jsonObject).let {
|
||||
loginResponse.postValue(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
fun main(){
|
||||
val dateFormat = SimpleDateFormat("MM:HHddMMyyyy", Locale.getDefault())
|
||||
val currentDate = Date()
|
||||
print(dateFormat.format(currentDate))
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.example.hpostesting.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import com.example.hpostesting.data.model.patient.PatientDetails
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
object MyUtils {
|
||||
|
||||
fun createAppFolder(context: Context) : String? {
|
||||
val folderPath = getAppFolderPath(context)
|
||||
val file = File(folderPath)
|
||||
|
||||
return if (!file.exists()) {
|
||||
if (!file.mkdirs()) {
|
||||
null
|
||||
} else {
|
||||
folderPath
|
||||
}
|
||||
} else {
|
||||
folderPath
|
||||
}
|
||||
}
|
||||
|
||||
fun getAppFolderPath(context: Context) : String {
|
||||
return Environment.getExternalStorageDirectory().absolutePath + "/" + context.resources.getString(R.string.app_name) + "/"
|
||||
}
|
||||
|
||||
fun isInternetConnected(): Boolean {
|
||||
val runtime = Runtime.getRuntime()
|
||||
try {
|
||||
val ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8")
|
||||
val exitValue = ipProcess.waitFor()
|
||||
return exitValue == 0
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun generateTestIdForPatient(patientId: String): String {
|
||||
val dateFormat = SimpleDateFormat("HHmm_ddMMyyyy", Locale.getDefault())
|
||||
return patientId + "_" + dateFormat.format(Date())
|
||||
}
|
||||
|
||||
fun String.mapToGender(): PatientDetails.Gender {
|
||||
return if (this.lowercase() == "m"|| this.lowercase() == "male") {
|
||||
PatientDetails.Gender.MALE
|
||||
} else if (this.lowercase() == "f"|| this.lowercase() == "female") {
|
||||
PatientDetails.Gender.FEMALE
|
||||
} else {
|
||||
PatientDetails.Gender.OTHER
|
||||
}
|
||||
}
|
||||
|
||||
fun String.mapToCategory(): PatientDetails.Category {
|
||||
return when (this.lowercase()){
|
||||
"gen" -> PatientDetails.Category.GENERAL
|
||||
"general" -> PatientDetails.Category.GENERAL
|
||||
"obc" -> PatientDetails.Category.OBC
|
||||
"sc" -> PatientDetails.Category.SC
|
||||
"st" -> PatientDetails.Category.ST
|
||||
else -> {PatientDetails.Category.GENERAL}
|
||||
}
|
||||
}
|
||||
|
||||
fun String.fetchYOBFromDOB(): Int {
|
||||
val startIndex = if (this.length >= 4) this.length - 4 else 0
|
||||
return this.substring(startIndex).toInt()
|
||||
}
|
||||
|
||||
fun Int.calculateAgeFromYOB(): Int {
|
||||
val currentY = SimpleDateFormat("yyyy").format(Date()).toInt()
|
||||
return (currentY - this)
|
||||
}
|
||||
|
||||
fun String.mapYesNoStringToBool(): Boolean {
|
||||
return this.lowercase() == "yes"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#005DB3" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||
</vector>
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#EF0A0A" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M17,7l-1.41,1.41L18.17,11H8v2h10.17l-2.58,2.58L17,17l5,-5zM4,5h8V3H4c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h8v-2H4V5z"/>
|
||||
</vector>
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#005DB3" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||
</vector>
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M9.5,6.5v3h-3v-3H9.5M11,5H5v6h6V5L11,5zM9.5,14.5v3h-3v-3H9.5M11,13H5v6h6V13L11,13zM17.5,6.5v3h-3v-3H17.5M19,5h-6v6h6V5L19,5zM13,13h1.5v1.5H13V13zM14.5,14.5H16V16h-1.5V14.5zM16,13h1.5v1.5H16V13zM13,16h1.5v1.5H13V16zM14.5,17.5H16V19h-1.5V17.5zM16,16h1.5v1.5H16V16zM17.5,14.5H19V16h-1.5V14.5zM17.5,17.5H19V19h-1.5V17.5zM22,7h-2V4h-3V2h5V7zM22,22v-5h-2v3h-3v2H22zM2,22h5v-2H4v-3H2V22zM2,2v5h2V4h3V2H2z"/>
|
||||
</vector>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners
|
||||
android:radius="20dp"/>
|
||||
|
||||
<solid android:color="@color/white"/>
|
||||
|
||||
<stroke android:color="@color/gray"
|
||||
android:width="1dp"/>
|
||||
|
||||
</shape>
|
||||
@@ -1,6 +0,0 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#FFFFFF" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
|
||||
<path android:fillColor="@android:color/white" android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
|
||||
</vector>
|
||||
@@ -1,5 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#BB0303"
|
||||
<vector android:height="16dp" android:tint="#BB0303"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#2E7D32"
|
||||
<vector android:height="16dp" android:tint="#2E7D32"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#FFFFFF" android:viewportHeight="24"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
</vector>
|
||||
@@ -1,5 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#005DB3" android:viewportHeight="24"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
|
||||
</vector>
|
||||
@@ -1,12 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
|
||||
</vector>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
@@ -1,9 +0,0 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:centerColor="#009688"
|
||||
android:endColor="#00695C"
|
||||
android:startColor="#4DB6AC"
|
||||
android:type="linear" />
|
||||
</shape>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user