Compare commits
21 Commits
seperate_t
...
2.1.118
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f922f585b5 | ||
|
|
1742363f1a | ||
|
|
ba9564d867 | ||
|
|
1aaf2ba485 | ||
|
|
85756a7052 | ||
|
|
0141c2791e | ||
|
|
a52538e72d | ||
|
|
c9d0c440e3 | ||
|
|
20f408230e | ||
|
|
c8d5d41c81 | ||
|
|
210c9fed5d | ||
|
|
b68ec45642 | ||
|
|
1e5afa0a5c | ||
|
|
80ab69c772 | ||
|
|
f7dc879c75 | ||
|
|
e8b5d12db5 | ||
|
|
626dd380ab | ||
|
|
70b0b93f57 | ||
|
|
5cdc156f33 | ||
|
|
71d298cd69 | ||
|
|
bb6f4ee859 |
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 114
|
||||
versionName "2.1.114"
|
||||
versionCode 120
|
||||
versionName "2.1.120"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
<application
|
||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||
android:largeHeap="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
||||
@@ -8,7 +8,7 @@ object Constants {
|
||||
const val DOCUMENT_ID_FOR_UPDATE ="2o71vBKLqdgEKYtFG8Lb"
|
||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||
|
||||
const val MOLBIO_INTEGRATION = false
|
||||
const val MOLBIO_INTEGRATION = true
|
||||
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
||||
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
||||
const val DEVICE_ID_API = "deviceIDAPI"
|
||||
|
||||
@@ -109,20 +109,7 @@ class DatabaseRepository @Inject constructor(
|
||||
}
|
||||
|
||||
override 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) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
||||
@@ -247,4 +234,22 @@ class DatabaseRepository @Inject constructor(
|
||||
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun addTestToDatabasefornew(data: HemoCubeTestData?): 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) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import okhttp3.ResponseBody
|
||||
|
||||
interface Repository {
|
||||
suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String>
|
||||
suspend fun addTestToDatabasefornew(data: HemoCubeTestData?): Response<String>
|
||||
|
||||
suspend fun addTestToDatabase(data: UserData?): Response<String>
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
@@ -24,7 +23,7 @@ import androidx.navigation.ui.setupWithNavController
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.LanguageManager
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||
import com.example.hpostesting.presentation.NatsManager
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.jig.JigActivity
|
||||
@@ -35,10 +34,16 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.BuildConfig
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||
import okhttp3.ResponseBody
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
interface NatsMessageCallback {
|
||||
fun onMessageReceived(topic: String, message: String)
|
||||
@@ -62,7 +67,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
private var downloadId: Long = 0
|
||||
// TODO: Remove hemocube viewmodel
|
||||
private val hemocubeViewModel: HemoCubeViewModel by viewModels()
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun attachBaseContext(newBase: Context?) {
|
||||
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
||||
LanguageManager.setLocale(newBase, languageCode)
|
||||
@@ -75,6 +80,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
Log.d(TAG, "Received message on topic $topic: $message")
|
||||
}
|
||||
|
||||
@SuppressLint("SetWorldReadable")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -96,15 +102,22 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
// Handle success
|
||||
val apkUrl = result.data
|
||||
// val apkUrl = "https://dl.dropboxusercontent.com/s/fi/1c3nn7t0co431hicl3hrt/app-debug.apk?rlkey=e4uf13ty1dpcked614vy1aaqp&dl=0"
|
||||
initiateUpdate(apkUrl.toString())
|
||||
Log.d("ApI", "APK URL: $apkUrl")
|
||||
// Toast.makeText(
|
||||
// this,
|
||||
// "APK UPLOAD ${result.data}",
|
||||
// Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
val apk = result.data
|
||||
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
||||
file.setReadable(true, false) // Ensure the file is readable
|
||||
apk.byteStream().use { input ->
|
||||
file.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
Log.d("Responsebodyformat", "Responsebodyformat: ")
|
||||
installApk(file)
|
||||
Log.e("ApI", "APK URL: $apk")
|
||||
Toast.makeText(
|
||||
this,
|
||||
"${result.data}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
@@ -154,56 +167,15 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
private fun initiateUpdate(url: String) {
|
||||
val apkUrl = url
|
||||
if (!isValidHttpUrl(apkUrl)) {
|
||||
return
|
||||
}
|
||||
|
||||
val request = DownloadManager.Request(Uri.parse(apkUrl))
|
||||
request.setTitle("App Update")
|
||||
request.setDescription("Downloading update...")
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||
request.setDestinationInExternalFilesDir(this, "Updates", "update.apk")
|
||||
|
||||
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
downloadId = downloadManager.enqueue(request)
|
||||
|
||||
// Register a BroadcastReceiver to receive the download complete event
|
||||
val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
isRegistered = true
|
||||
registerReceiver(downloadReceiver, filter, RECEIVER_EXPORTED)
|
||||
}
|
||||
}
|
||||
private fun extractApkUrl(responseBody: ResponseBody): String {
|
||||
return responseBody.string()
|
||||
}
|
||||
private fun isValidHttpUrl(url: String): Boolean {
|
||||
return url.startsWith("http://") || url.startsWith("https://")
|
||||
}
|
||||
private val downloadReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
||||
if (id == downloadId) {
|
||||
installApk()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun installApk() {
|
||||
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
||||
file.setReadable(true, false) // Ensure the file is readable
|
||||
|
||||
private fun installApk(file: File) {
|
||||
val pInfo = baseContext.packageManager.getPackageInfo(baseContext.packageName, 0)
|
||||
val uri: Uri = FileProvider.getUriForFile(
|
||||
this,
|
||||
"in.sminnovations.hpostesting.dev.fileprovider",
|
||||
"${BuildConfig.APPLICATION_ID}.fileprovider",
|
||||
file
|
||||
)
|
||||
|
||||
// Create an intent to install the APK
|
||||
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||
installIntent.data = uri
|
||||
installIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
@@ -221,7 +193,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
override fun onDestroy() {
|
||||
if(isRegistered) {
|
||||
try {
|
||||
unregisterReceiver(downloadReceiver)
|
||||
// unregisterReceiver(downloadReceiver)
|
||||
} catch (e: Exception) {
|
||||
Log.d("HomeFragment", e.toString())
|
||||
}
|
||||
@@ -278,6 +250,14 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
override fun setResponse(response: String) {
|
||||
responses = responses+response+"\n"
|
||||
println(responses)
|
||||
Log.d("DashBoardActResponse",response)
|
||||
// if (response.contains("checkUpdate")) {
|
||||
// hemocubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
// }
|
||||
}
|
||||
|
||||
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
||||
return DeviceUpdateRequest(
|
||||
serial_no = sharedPreference.getString(Constants.DEVICE_ID, "")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
@@ -99,6 +100,7 @@ class HomeFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
@@ -148,35 +150,67 @@ class HomeFragment : Fragment() {
|
||||
checkForTokenAndUpdate()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||
// Now re-subscribe to allUserData
|
||||
hemoCubeViewModel.allLocalData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||
|
||||
Log.d("LOCAL_DB OBSERVE", "OBSERVE CALLED")
|
||||
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||
originalUserDataList.forEach { userData ->
|
||||
Log.d(
|
||||
": USER DATA",
|
||||
originalUserDataList.count().toString() + " : " + userData._id
|
||||
)
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||
if(accessToken.isNotEmpty()) {
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
val currentTimeFormatted = SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||
Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
val bufferIntensityThreshold =
|
||||
Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId]?.toString()
|
||||
?: "defaultThreshold" // Handle possible nulls safely
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = currentTimeFormatted,
|
||||
analysisStatus = userData.classificationResult
|
||||
?: "defaultStatus", // Handle possible nulls
|
||||
thresholds = bufferIntensityThreshold,
|
||||
interpretation = userData.classificationResult
|
||||
?: "defaultInterpretation", // Handle possible nulls
|
||||
testId = userData._id,
|
||||
testTime = currentTimeFormatted,
|
||||
collectionTime = currentTimeFormatted,
|
||||
expiryTime = currentTimeFormatted
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
resultList.results?.forEach { result ->
|
||||
val userData = result.rawData
|
||||
Log.d("UserData", userData.toString())
|
||||
if (userData != null) {
|
||||
if (!userData.localFlag) {
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
resultList.results?.forEach { result ->
|
||||
result.rawData?.let { sanitizeDoubleValues(it) }
|
||||
}
|
||||
|
||||
// Then, check if there are any results to upload.
|
||||
if (resultList.results?.isNotEmpty() == true) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
Log.d("resultcount1", "Uploading sanitized results")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -203,30 +237,34 @@ class HomeFragment : Fragment() {
|
||||
logoutUser(requireContext())
|
||||
}
|
||||
|
||||
binding.btnLogout1.setOnClickListener {
|
||||
logoutUser(requireContext())
|
||||
}
|
||||
|
||||
binding.uploadData.setOnClickListener {
|
||||
showUploadDialog(requireContext())
|
||||
}
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
|
||||
val btnSaveLocalVisibility =
|
||||
if (userData.any { it.testStatus == true }) View.GONE else View.GONE
|
||||
|
||||
binding.downloadCSV.visibility = btnSaveLocalVisibility
|
||||
|
||||
binding.downloadCSV.setOnClickListener {
|
||||
if (btnSaveLocalVisibility == View.VISIBLE) {
|
||||
// Execute the action when the button is visible (testStatus is true for at least one user)
|
||||
showDownloadDialog(requireContext())
|
||||
} else {
|
||||
// Handle the case when the button is not visible
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"No test details stored locally",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
// showUploadDialog(requireContext())
|
||||
}
|
||||
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
//
|
||||
// val btnSaveLocalVisibility =
|
||||
// if (userData.any { it.testStatus == true }) View.GONE else View.GONE
|
||||
//
|
||||
// binding.downloadCSV.visibility = btnSaveLocalVisibility
|
||||
//
|
||||
// binding.downloadCSV.setOnClickListener {
|
||||
// if (btnSaveLocalVisibility == View.VISIBLE) {
|
||||
// // Execute the action when the button is visible (testStatus is true for at least one user)
|
||||
// showDownloadDialog(requireContext())
|
||||
// } else {
|
||||
// // Handle the case when the button is not visible
|
||||
// Toast.makeText(
|
||||
// requireContext(),
|
||||
// "No test details stored locally",
|
||||
// Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
binding.btnNewKit.setOnClickListener {
|
||||
@@ -238,6 +276,17 @@ class HomeFragment : Fragment() {
|
||||
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
||||
requireActivity().finish()
|
||||
}
|
||||
|
||||
|
||||
binding.btnNewKitoffline.setOnClickListener {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.KIT_NUMBER, "")
|
||||
putInt(Constants.KIT_COUNT, 0)
|
||||
apply()
|
||||
}
|
||||
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
||||
requireActivity().finish()
|
||||
}
|
||||
binding.btnQuickCapture.setOnClickListener {
|
||||
DataHolder.hemoCubeTestData = HemoCubeTestData()
|
||||
|
||||
@@ -253,41 +302,32 @@ class HomeFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun checkForTokenAndUpdate() {
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||
if (!isTokenAvailable) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
if (isTokenExpired(accessToken)) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
isTokenAvailable = true
|
||||
if(userID.isNotEmpty() && password.isNotEmpty()) {
|
||||
Log.d("istoken",isTokenAvailable.toString())
|
||||
if (!isTokenAvailable) {
|
||||
Log.d("istoken1",isTokenAvailable.toString())
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
isTokenAvailable = true
|
||||
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.downloadClientCertificate()
|
||||
}
|
||||
}
|
||||
} else if (deviceId.isNotEmpty()) {
|
||||
}else if(isTokenAvailable){
|
||||
Log.d("istoken7",isTokenAvailable.toString())
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||
}else{
|
||||
if(isTokenExpired(accessToken)) {
|
||||
Log.d("istoken8",isTokenAvailable.toString())
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
}
|
||||
}
|
||||
} else if (userID == "deviceIDAPI" && password == "devicePasswordAPI" && deviceId.isNotEmpty()) {
|
||||
fetchDeviceCredentials()
|
||||
// This code will execute after credentials have been successfully fetched and stored.
|
||||
userID = sharedPreference.getString("username", "").toString()
|
||||
password = sharedPreference.getString("password", "").toString()
|
||||
accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
if (accessToken.isEmpty()) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
// Continue with your existing logic if the token is not empty.
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
@@ -300,6 +340,9 @@ class HomeFragment : Fragment() {
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
updateTokens(response)
|
||||
response.data.data?.accessToken
|
||||
isTokenAvailable = true
|
||||
Log.d("istoken2",isTokenAvailable.toString())
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
@@ -321,6 +364,36 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
|
||||
Log.d("success,","uploded")
|
||||
it.data.data?.forEach { id ->
|
||||
id.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
)
|
||||
}
|
||||
}
|
||||
Toast.makeText(activity, "Molbio Result is successfully uploaded", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
//Remove this line of code while deploying to IOCL
|
||||
it.exception.let { message ->
|
||||
Toast.makeText(activity, "$message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
Log.d("resultuploadfail", message.toString())
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
@@ -329,13 +402,14 @@ class HomeFragment : Fragment() {
|
||||
// "Log uploaded ${response.data.data?.filename}",
|
||||
// Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred in uploading logs: $message",
|
||||
"$message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
@@ -350,28 +424,84 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.checkUpdate.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
val updatedversion = response.data.data?.version.toString()
|
||||
val currentversion =
|
||||
context?.let { ctx ->
|
||||
val packageInfo = ctx.packageManager.getPackageInfo(ctx.packageName, 0)
|
||||
val versionName = packageInfo.versionName
|
||||
val versionCode: Long = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
// From Android P (API level 28), versionCode is deprecated and you should use longVersionCode instead.
|
||||
packageInfo.longVersionCode
|
||||
} else {
|
||||
// For older Android versions, use versionCode (cast it to Long for consistency).
|
||||
packageInfo.versionCode.toLong()
|
||||
}
|
||||
|
||||
// Use versionName and versionCode as needed
|
||||
Log.d("AppInfo", "Version Name: $versionName, Version Code: $versionCode")
|
||||
}
|
||||
Log.d("versionnow",currentversion.toString())
|
||||
Log.d("versionnow",updatedversion.toString())
|
||||
if(updatedversion > currentversion.toString()){
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"new version ${response.data.data?.version} Available",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}else{
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"App is Up to date",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
// response.exception.let { message ->
|
||||
//// Toast.makeText(
|
||||
//// activity,
|
||||
//// "$message",
|
||||
//// Toast.LENGTH_LONG
|
||||
//// )
|
||||
//// .show()
|
||||
// }
|
||||
}
|
||||
|
||||
is Result.Loading -> {
|
||||
}
|
||||
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.downloadcertificate.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
val url = response.data
|
||||
|
||||
val fileName = "nats_certificate.zip"
|
||||
val downloadDirectory = "NATS"
|
||||
val file = downloadFile(url, requireContext(), fileName, downloadDirectory)
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"NATS certificate Downloaded",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
val fileName = "nats_certificate.zip"
|
||||
val unzipDirectoryPath = requireContext().getExternalFilesDir(null)?.absolutePath + "/$downloadDirectory"
|
||||
|
||||
// Check if the directory with extracted files exists.
|
||||
val directory = File(unzipDirectoryPath)
|
||||
if (directory.exists() && directory.isDirectory) {
|
||||
// Assuming if the directory exists, the certificate has been downloaded and extracted.
|
||||
// You can add more specific checks here, e.g., checking for specific files within the directory.
|
||||
Toast.makeText(requireContext(), "NATS certificate already downloaded and extracted.", Toast.LENGTH_SHORT).show()
|
||||
return@observe
|
||||
}
|
||||
val file = downloadFile(url, requireContext(), fileName, downloadDirectory)
|
||||
|
||||
val unzipDirectoryPath =
|
||||
requireContext().getExternalFilesDir(null)?.absolutePath + "/$downloadDirectory"
|
||||
unzip(file.absolutePath, unzipDirectoryPath)
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"NATS certificate Extracted",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
@@ -393,44 +523,23 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
it.data.data?.forEach { id ->
|
||||
id.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
//Remove this line of code while deploying to IOCL
|
||||
it.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun isTokenExpired(token: String): Boolean {
|
||||
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
||||
val jsonPayload = JSONObject(decodedPayload)
|
||||
if(token.isNotEmpty()) {
|
||||
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
||||
val jsonPayload = JSONObject(decodedPayload)
|
||||
|
||||
val exp = jsonPayload.optLong("exp", 0)
|
||||
val currentTimeSeconds = System.currentTimeMillis() / 1000
|
||||
val exp = jsonPayload.optLong("exp", 0)
|
||||
val currentTimeSeconds = System.currentTimeMillis() / 1000
|
||||
|
||||
return exp <= currentTimeSeconds
|
||||
return exp <= currentTimeSeconds
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTokens(response: Result.Success<LoginResponse>) {
|
||||
@@ -443,6 +552,7 @@ class HomeFragment : Fragment() {
|
||||
apply()
|
||||
}
|
||||
isTokenAvailable = true
|
||||
Log.d("istoken3",isTokenAvailable.toString())
|
||||
}
|
||||
|
||||
private fun createLoginRequestData(userID: String, password: String): LoginRequest {
|
||||
@@ -553,6 +663,7 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun fetchDeviceCredentials() {
|
||||
try {
|
||||
val db = Firebase.firestore
|
||||
@@ -579,12 +690,16 @@ class HomeFragment : Fragment() {
|
||||
)
|
||||
// Save credentials in SharedPreferences
|
||||
with(sharedPreference.edit()) {
|
||||
putString("username", username)
|
||||
putString("password", password)
|
||||
putString(Constants.DEVICE_ID_API, username)
|
||||
putString(Constants.DEVICE_PASSWORD_API, password)
|
||||
putString(Constants.NATS_TOKEN, natsToken)
|
||||
apply()
|
||||
}
|
||||
hemoCubeViewModel.login(createLoginRequestData(username, password))
|
||||
if (!isTokenAvailable ) {
|
||||
Log.d("istoken0", isTokenAvailable.toString())
|
||||
hemoCubeViewModel.login(createLoginRequestData(username, password))
|
||||
}
|
||||
|
||||
} ?: Log.e("fetchDeviceCredentials", "Failed to parse device data.")
|
||||
} else {
|
||||
Log.e("fetchDeviceCredentials", "Document does not exist.")
|
||||
@@ -747,16 +862,16 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkForLocalDBData() {
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility = if (userDataList.isEmpty()) View.GONE else View.VISIBLE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility =
|
||||
if (userDataList.any { !it.localFlag && !it.molbioFlag && it.testStatus == true }) View.VISIBLE else View.GONE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// val uploadDataVisibility = if (userDataList.isEmpty()) View.GONE else View.VISIBLE
|
||||
// binding.uploadData.visibility = uploadDataVisibility
|
||||
// }
|
||||
//
|
||||
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// val uploadDataVisibility =
|
||||
// if (userDataList.any { !it.localFlag && !it.molbioFlag && it.testStatus == true }) View.VISIBLE else View.GONE
|
||||
// binding.uploadData.visibility = uploadDataVisibility
|
||||
// }
|
||||
|
||||
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { bufferData ->
|
||||
val uploadDataVisibility =
|
||||
@@ -766,20 +881,35 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkUnprocessedCSVData() {
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val downloadDataVisibility =
|
||||
if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE
|
||||
binding.downloadCSV.visibility = downloadDataVisibility
|
||||
}
|
||||
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// val downloadDataVisibility =
|
||||
// if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE
|
||||
// binding.downloadCSV.visibility = downloadDataVisibility
|
||||
// }
|
||||
}
|
||||
|
||||
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
||||
hemoCubeTestData::class.java.declaredFields.forEach { field ->
|
||||
if (field.type == Double::class.javaObjectType || field.type == Double::class.javaPrimitiveType) {
|
||||
field.isAccessible = true
|
||||
val value = field.get(hemoCubeTestData) as Double?
|
||||
if (value != null && (value.isInfinite() || value.isNaN())) {
|
||||
field.set(hemoCubeTestData, 0.0) // Replace with a suitable default value
|
||||
}
|
||||
}
|
||||
}
|
||||
return hemoCubeTestData
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun showUploadDialog(context: Context) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.upload_db_registration_title)
|
||||
builder.setMessage(R.string.upload_db_registration_message)
|
||||
|
||||
builder.setPositiveButton(R.string.upload) { dialog, _ ->
|
||||
uploadLocalDBData(dialog)
|
||||
// uploadLocalDBData(dialog)
|
||||
}
|
||||
|
||||
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
@@ -808,53 +938,53 @@ class HomeFragment : Fragment() {
|
||||
// }
|
||||
|
||||
private fun uploadLocalDBData(dialog: DialogInterface) {
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
if (userDataList.isEmpty()) {
|
||||
dialog.dismiss()
|
||||
} else {
|
||||
userDataList.forEach { userData ->
|
||||
viewModel.bulkUploadResultToDatabase(userData)
|
||||
viewModel.deleteById(userData._id)
|
||||
}
|
||||
dialog.dismiss()
|
||||
Toast.makeText(
|
||||
requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// if (userDataList.isEmpty()) {
|
||||
// dialog.dismiss()
|
||||
// } else {
|
||||
// userDataList.forEach { userData ->
|
||||
// viewModel.bulkUploadResultToDatabase(userData)
|
||||
// viewModel.deleteById(userData._id)
|
||||
// }
|
||||
// dialog.dismiss()
|
||||
// Toast.makeText(
|
||||
// requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// }
|
||||
// }
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56", //userData.reportUploadTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
)
|
||||
)
|
||||
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
// userDataList.forEach { userData ->
|
||||
// if (!userData.molbioFlag && isTokenAvailable) {
|
||||
// resultList.results?.add(
|
||||
// MolbioV2Result(
|
||||
// rawData = userData,
|
||||
// analysisId = userData._id,
|
||||
// analysisDate = "2024-02-08 16:33:56", //userData.reportUploadTime,
|
||||
// analysisStatus = userData.classificationResult,
|
||||
// thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
// interpretation = userData.classificationResult,
|
||||
// testId = userData._id,
|
||||
// testTime = userData.testTime,
|
||||
// collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
// expiryTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
// )
|
||||
// )
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
// if (!userData.localFlag) {
|
||||
// userData.localFlag = true
|
||||
// hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
// }
|
||||
// if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
// userData.molbioFlag = true
|
||||
// hemoCubeViewModel.uploadResult(resultList)
|
||||
// }
|
||||
// }
|
||||
// dialog.dismiss()
|
||||
// }
|
||||
|
||||
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
||||
kitDataList.forEach { userData ->
|
||||
@@ -865,37 +995,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||
)
|
||||
)
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
@@ -960,7 +1059,7 @@ class HomeFragment : Fragment() {
|
||||
builder.setMessage(R.string.download_db_registration_message)
|
||||
|
||||
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
||||
downloadLocalDBData(dialog)
|
||||
// downloadLocalDBData(dialog)
|
||||
}
|
||||
|
||||
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
@@ -971,49 +1070,49 @@ class HomeFragment : Fragment() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
var csvDownloaded = false
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
try {
|
||||
if (!csvDownloaded) {
|
||||
val downloadList = mutableListOf<HemoCubeTestData>()
|
||||
|
||||
userDataList.forEach { userData ->
|
||||
if (userData.testStatus == true) {
|
||||
// if (!userData.isCSVCreated) {
|
||||
downloadList.add(userData) // Add the userData to downloadList
|
||||
}
|
||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
// var csvDownloaded = false
|
||||
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
// try {
|
||||
// if (!csvDownloaded) {
|
||||
// val downloadList = mutableListOf<HemoCubeTestData>()
|
||||
//
|
||||
// userDataList.forEach { userData ->
|
||||
// if (userData.testStatus == true) {
|
||||
//// if (!userData.isCSVCreated) {
|
||||
// downloadList.add(userData) // Add the userData to downloadList
|
||||
// }
|
||||
}
|
||||
|
||||
if (downloadList.isNotEmpty()) {
|
||||
// Call ViewModel function to create CSV with filtered data
|
||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||
csvDownloaded = true
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"CSV file downloaded successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"No data to download",
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
} finally {
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// if (downloadList.isNotEmpty()) {
|
||||
// // Call ViewModel function to create CSV with filtered data
|
||||
// hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||
// csvDownloaded = true
|
||||
// Toast.makeText(
|
||||
// requireContext(),
|
||||
// "CSV file downloaded successfully",
|
||||
// Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// } else {
|
||||
// Toast.makeText(
|
||||
// requireContext(),
|
||||
// "No data to download",
|
||||
// Toast.LENGTH_SHORT
|
||||
// )
|
||||
// .show()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT)
|
||||
// .show()
|
||||
// } finally {
|
||||
// dialog.dismiss()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun getDeviceId() {
|
||||
Log.d("HomeFragmentUSb","getDeviceId")
|
||||
@@ -1075,7 +1174,7 @@ class HomeFragment : Fragment() {
|
||||
val deviceUpdateAvailableGlobal= deviceData.deviceUpdateAvailable
|
||||
val updatePathGlobal= deviceData.updatePath
|
||||
|
||||
// if(deviceUpdateAvailableGlobal){
|
||||
|
||||
db.collection("devices").whereEqualTo("deviceId", deviceId).get().addOnSuccessListener { documentSnapshotNew ->
|
||||
if (documentSnapshotNew.documents.isNotEmpty()) {
|
||||
documentSnapshotNew.documents.forEach{
|
||||
@@ -1099,14 +1198,24 @@ class HomeFragment : Fragment() {
|
||||
Log.d("HomeFragmentUpdate","Device update not available")
|
||||
}
|
||||
}else{
|
||||
if(!globalUpdateDone){
|
||||
val update = db.collection("devices").document(it.id).update("globalUpdateDone",true)
|
||||
update.addOnSuccessListener {
|
||||
Log.d("HomeFragmentUpdate","Device global update done")
|
||||
if(deviceUpdateAvailableGlobal) {
|
||||
if (!globalUpdateDone) {
|
||||
val update =
|
||||
db.collection("devices").document(it.id)
|
||||
.update("globalUpdateDone", true)
|
||||
update.addOnSuccessListener {
|
||||
Log.d(
|
||||
"HomeFragmentUpdate",
|
||||
"Device global update done"
|
||||
)
|
||||
|
||||
initiateUpdate(updatePathGlobal)
|
||||
}.addOnFailureListener{
|
||||
Log.e("fetchDeviceUpdate", "update fail.")
|
||||
initiateUpdate(updatePathGlobal)
|
||||
}.addOnFailureListener {
|
||||
Log.e(
|
||||
"fetchDeviceUpdate",
|
||||
"update fail."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1128,8 +1237,7 @@ class HomeFragment : Fragment() {
|
||||
"fetchDeviceCredentials",
|
||||
"deviceVersion: $deviceVersion, Password: $deviceUpdateAvailableGlobal, updatePath: $updatePathGlobal"
|
||||
)
|
||||
|
||||
// } ?: Log.e("fetchDeviceUpdate", "Failed to parse device data.")
|
||||
// ?: Log.e("fetchDeviceUpdate", "Failed to parse device data.")
|
||||
} else {
|
||||
Log.e("fetchDeviceUpdate", "Document does not exist.")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -149,6 +150,7 @@ class HemoCubeFragment : Fragment() {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
uploadedToCloud = true
|
||||
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
showToast(R.string.test_upload)
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
@@ -161,6 +163,8 @@ class HemoCubeFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
handleReadingFinish()
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.downloadClientCertificate()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
@@ -169,10 +173,11 @@ class HemoCubeFragment : Fragment() {
|
||||
it.exception.let { message ->
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred: $message",
|
||||
"$message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
Log.d("resultuploadfail1", message.toString())
|
||||
}
|
||||
handleReadingFinish()
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
import com.example.hpostesting.domain.CheckUpdateWorker
|
||||
import com.example.hpostesting.domain.LogFileManager
|
||||
import com.google.gson.GsonBuilder
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
@@ -88,6 +89,7 @@ class HemoCubeViewModel @Inject constructor(
|
||||
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
val allUserData = hemoCubeDao.getAll()
|
||||
val allLocalData = hemoCubeDao.getAll()
|
||||
val allPendingUserToUpload = MutableLiveData<List<HemoCubeTestData>>()
|
||||
val allKitTestData = hemoCubeBufferDao.getAll()
|
||||
val deviceData = MutableLiveData<DeviceData?>()
|
||||
@@ -143,6 +145,14 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun uploadResultfornew(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
||||
resultUpload.postValue(Result.Loading())
|
||||
repository.uploadResults(molbioV2ResultRequest).let {
|
||||
resultUpload.postValue(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
||||
checkUpdate.postValue(Result.Loading())
|
||||
repository.checkUpdate(checkUpdateRequest).let {
|
||||
@@ -325,20 +335,24 @@ class HemoCubeViewModel @Inject constructor(
|
||||
fireBaseUpload.postValue("Success")
|
||||
testDetails.localFlag = true
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
// Sanitize testDetails before using it in the API call
|
||||
val sanitizedTestDetails = sanitizeDoubleValues(testDetails)
|
||||
|
||||
// Now, use sanitizedTestDetails for the API call
|
||||
uploadResult(
|
||||
MolbioV2ResultRequest(
|
||||
mutableListOf(
|
||||
MolbioV2Result(
|
||||
rawData = testDetails,
|
||||
analysisId = testDetails._id,
|
||||
analysisDate = testDetails.testTime,
|
||||
analysisStatus = testDetails.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[testDetails.deviceId].toString(),
|
||||
interpretation = testDetails.classificationResult,
|
||||
testId = testDetails._id,
|
||||
testTime = testDetails.testTime,
|
||||
collectionTime = testDetails.testTime,
|
||||
expiryTime = testDetails.testTime,
|
||||
rawData = sanitizedTestDetails,
|
||||
analysisId = sanitizedTestDetails._id,
|
||||
analysisDate = sanitizedTestDetails.testTime,
|
||||
analysisStatus = sanitizedTestDetails.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[sanitizedTestDetails.deviceId]?.toString(),
|
||||
interpretation = sanitizedTestDetails.classificationResult,
|
||||
testId = sanitizedTestDetails._id,
|
||||
testTime = sanitizedTestDetails.testTime,
|
||||
collectionTime = sanitizedTestDetails.testTime,
|
||||
expiryTime = sanitizedTestDetails.testTime,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -380,6 +394,19 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
||||
hemoCubeTestData::class.java.declaredFields.forEach { field ->
|
||||
if (field.type == Double::class.javaObjectType || field.type == Double::class.javaPrimitiveType) {
|
||||
field.isAccessible = true
|
||||
val value = field.get(hemoCubeTestData) as Double?
|
||||
if (value != null && (value.isInfinite() || value.isNaN())) {
|
||||
field.set(hemoCubeTestData, 0.0) // Replace with a suitable default value
|
||||
}
|
||||
}
|
||||
}
|
||||
return hemoCubeTestData
|
||||
}
|
||||
|
||||
private fun updateLocalFlag(userId: String) = viewModelScope.launch {
|
||||
hemoCubeDao.updateFieldById(id = userId, true)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.get
|
||||
@@ -44,6 +45,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
private val TAG = "HemoCube"
|
||||
|
||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
|
||||
synchronized(this) {
|
||||
@@ -83,6 +85,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
super.attachBaseContext(newBase)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
||||
@@ -107,6 +110,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
open fun connectUsb(permissionGranted: Boolean) {
|
||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||
@@ -126,6 +130,7 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
@SuppressLint("MutableImplicitPendingIntent")
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent
|
||||
@@ -151,11 +156,13 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
|
||||
fun setupService() {
|
||||
val intent = Intent(this, UsbService::class.java)
|
||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
open fun reconnectDevice() {
|
||||
mService.disconnect()
|
||||
unbindService(connection)
|
||||
|
||||
@@ -38,10 +38,20 @@
|
||||
android:visibility="gone"
|
||||
android:padding="24dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btnLogout1"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:src="@drawable/baseline_logout_24"
|
||||
app:layout_constraintTop_toTopOf="@+id/internetNotAvailableCL"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title_no_internet"
|
||||
style="@style/title1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="24dp"
|
||||
@@ -125,6 +135,27 @@
|
||||
<!-- app:layout_constraintBottom_toBottomOf="@+id/rv_order_offline"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label1"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/new_kit"
|
||||
app:layout_constraintBottom_toTopOf="@+id/btnNewKitoffline"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/btnNewKitoffline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:backgroundTint="@color/primary"
|
||||
android:contentDescription="@string/new_kit"
|
||||
android:src="@drawable/ic_add"
|
||||
app:elevation="1dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
@@ -3,9 +3,9 @@ buildscript {
|
||||
kotlin_version = '1.8.21'
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.3.0'
|
||||
classpath 'com.google.gms:google-services:4.4.0'
|
||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
||||
classpath 'com.android.tools.build:gradle:8.2.2'
|
||||
classpath 'com.google.gms:google-services:4.4.1'
|
||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.1.0'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,4 +1,4 @@
|
||||
#Mon Jun 12 17:07:47 IST 2023
|
||||
#Mon Mar 04 17:08:24 IST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
|
||||
Reference in New Issue
Block a user