api calls managing, and error resolving for molbio
This commit is contained in:
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 117
|
||||
versionName "2.1.117"
|
||||
versionCode 119
|
||||
versionName "2.1.119"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -188,9 +188,14 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||
if (resultList.results?.isNotEmpty() == true) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
if(accessToken.isNotEmpty()) {
|
||||
if (resultList.results?.isNotEmpty() == true) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
Log.d("resultcount1","resultcount")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +222,7 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.uploadData.setOnClickListener {
|
||||
showUploadDialog(requireContext())
|
||||
// showUploadDialog(requireContext())
|
||||
}
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
|
||||
@@ -274,26 +279,23 @@ class HomeFragment : Fragment() {
|
||||
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||
if(userID.isNotEmpty() && password.isNotEmpty()) {
|
||||
Log.d("istoken",isTokenAvailable.toString())
|
||||
if (!isTokenAvailable) {
|
||||
Log.d("istoken1",isTokenAvailable.toString())
|
||||
if(isTokenExpired(accessToken)) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
}
|
||||
}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 {
|
||||
Log.d("istoken1",isTokenAvailable.toString())
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
isTokenAvailable = true
|
||||
}
|
||||
}
|
||||
} else if (userID.isEmpty() && password.isEmpty() && deviceId.isNotEmpty()) {
|
||||
fetchDeviceCredentials()
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
var userID = sharedPreference.getString("username", "").toString()
|
||||
var password = sharedPreference.getString("password", "").toString()
|
||||
if(accessToken.isNotEmpty()){
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
@@ -624,6 +626,7 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun fetchDeviceCredentials() {
|
||||
try {
|
||||
val db = Firebase.firestore
|
||||
@@ -650,13 +653,13 @@ 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()
|
||||
}
|
||||
if (!isTokenAvailable ) {
|
||||
Log.d("istoken1", isTokenAvailable.toString())
|
||||
Log.d("istoken0", isTokenAvailable.toString())
|
||||
hemoCubeViewModel.login(createLoginRequestData(username, password))
|
||||
}
|
||||
|
||||
@@ -854,7 +857,7 @@ class HomeFragment : Fragment() {
|
||||
builder.setMessage(R.string.upload_db_registration_message)
|
||||
|
||||
builder.setPositiveButton(R.string.upload) { dialog, _ ->
|
||||
uploadLocalDBData(dialog)
|
||||
// uploadLocalDBData(dialog)
|
||||
}
|
||||
|
||||
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
@@ -900,34 +903,34 @@ class HomeFragment : Fragment() {
|
||||
|
||||
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,
|
||||
)
|
||||
)
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
// if (!userData.localFlag) {
|
||||
// userData.localFlag = true
|
||||
// hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
// }
|
||||
// if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
// userData.molbioFlag = true
|
||||
// hemoCubeViewModel.uploadResult(resultList)
|
||||
// }
|
||||
// }
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
@@ -940,37 +943,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) {
|
||||
|
||||
@@ -149,8 +149,9 @@ 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) {
|
||||
if (Constants.MOLBIO_INTEGRATION && accessToken.isNotEmpty()) {
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
|
||||
@@ -328,7 +328,8 @@ class HemoCubeViewModel @Inject constructor(
|
||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Success")
|
||||
testDetails.localFlag = true
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
if (Constants.MOLBIO_INTEGRATION && accessToken.isNotEmpty()) {
|
||||
uploadResult(
|
||||
MolbioV2ResultRequest(
|
||||
mutableListOf(
|
||||
|
||||
Reference in New Issue
Block a user