HemoCubeFragment firebase upload committed

This commit is contained in:
chandrashekhar reddy
2024-03-30 14:06:57 +05:30
parent 31e92a0cbb
commit d5955507b8
3 changed files with 85 additions and 77 deletions

View File

@@ -321,7 +321,7 @@ class HomeFragment : Fragment() {
}*/
hemoCubeViewModel.sendDataToMolbio()
hemoCubeViewModel.sendDataToFirebase()
// hemoCubeViewModel.sendDataToFirebase()
} else {
binding.internetAvailableCL.visibility = View.GONE

View File

@@ -195,11 +195,6 @@ class HemoCubeFragment : Fragment() {
}
private fun observeViewModel() {
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) {
when (it) {
@@ -236,6 +231,12 @@ class HemoCubeFragment : Fragment() {
} else {
handleReadingFinish()
}
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
if (result == "Success") {
uploadedToCloud = true
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
showToast(R.string.test_upload)
}
if (result == "Local") {
showToast(R.string.internt_not_local)

View File

@@ -424,17 +424,34 @@ class HemoCubeViewModel @Inject constructor(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
).format(Calendar.getInstance().time)
when (val response = repository.addTestToDatabase(testDetails)) {
is Response.Success -> {
// when (val response = repository.addTestToDatabase(testDetails)) {
// is Response.Success -> {
// val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
// with(sharedPreference.edit()) {
// putInt(Constants.KIT_COUNT, kitCount.plus(1))
// apply()
// }
// Log.i("Testdb", "Data uploaded to Firestore successfully")
// fireBaseUpload.postValue("Success")
// testDetails.localFlag = true
//
// hemoCubeDao.insertAll(testDetails)
// }
//
// is Response.Error -> {
// Log.e("Testdb", "Error uploading data to Firestore: $response")
// fireBaseUpload.postValue("Error")
// hemoCubeDao.insertAll(testDetails)
// }
//
// else -> {}
// }
if (Constants.MOLBIO_INTEGRATION) {
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
with(sharedPreference.edit()) {
putInt(Constants.KIT_COUNT, kitCount.plus(1))
apply()
}
Log.i("Testdb", "Data uploaded to Firestore successfully")
fireBaseUpload.postValue("Success")
testDetails.localFlag = true
if (Constants.MOLBIO_INTEGRATION) {
// Sanitize testDetails before using it in the API call
val sanitizedTestDetails = sanitizeDoubleValues(testDetails)
@@ -457,18 +474,8 @@ class HemoCubeViewModel @Inject constructor(
)
)
)
}
hemoCubeDao.insertAll(testDetails)
}
is Response.Error -> {
Log.e("Testdb", "Error uploading data to Firestore: $response")
fireBaseUpload.postValue("Error")
hemoCubeDao.insertAll(testDetails)
}
else -> {}
}
} catch (e: Exception) {
Log.e("Testdb", "Exception during data upload: ${e.message}")
fireBaseUpload.postValue("Error")