From 5691e179b11ca87ee1f5172b14ac560c4ceb138a Mon Sep 17 00:00:00 2001 From: Tomeshwari-02 Date: Fri, 24 Apr 2026 23:13:35 +0530 Subject: [PATCH 1/3] fix: move Toast to main thread to prevent background thread crash --- .../java/org/piramalswasthya/cho/repositories/UserRepo.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt index aec82a02e..7630f3b57 100644 --- a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt +++ b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt @@ -227,7 +227,9 @@ class UserRepo @Inject constructor( val servicePointName = vanSp.getString("servicePointName") user?.servicePointName = servicePointName if (!vanSp.has("facilityID")) { - Toast.makeText(context, "Facility ID not found", Toast.LENGTH_LONG).show() + withContext(Dispatchers.Main) { + Toast.makeText(context, "Facility ID not found", Toast.LENGTH_LONG).show() + } delay(3000) } val facilityId = vanSp.getInt("facilityID") From 4d0233855933db023e65e2409f49ccdd6579c7a6 Mon Sep 17 00:00:00 2001 From: Tomeshwari-02 <179694969+Tomeshwari-02@users.noreply.github.com> Date: Sat, 25 Apr 2026 08:45:30 +0530 Subject: [PATCH 2/3] fix: skip van sp entries missing facility ID --- .../piramalswasthya/cho/repositories/UserRepo.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt index 7630f3b57..13e390ad3 100644 --- a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt +++ b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt @@ -220,18 +220,19 @@ class UserRepo @Inject constructor( for (i in 0 until vanSpDetailsArray.length()) { val vanSp = vanSpDetailsArray.getJSONObject(i) - val vanId = vanSp.getInt("vanID") - user?.vanId = vanId - val servicePointId = vanSp.getInt("servicePointID") - user?.servicePointId = servicePointId - val servicePointName = vanSp.getString("servicePointName") - user?.servicePointName = servicePointName if (!vanSp.has("facilityID")) { withContext(Dispatchers.Main) { Toast.makeText(context, "Facility ID not found", Toast.LENGTH_LONG).show() } delay(3000) + continue } + val vanId = vanSp.getInt("vanID") + user?.vanId = vanId + val servicePointId = vanSp.getInt("servicePointID") + user?.servicePointId = servicePointId + val servicePointName = vanSp.getString("servicePointName") + user?.servicePointName = servicePointName val facilityId = vanSp.getInt("facilityID") user?.facilityID = facilityId user?.parkingPlaceId = vanSp.getInt("parkingPlaceID") @@ -600,4 +601,4 @@ class UserRepo @Inject constructor( return true } -} \ No newline at end of file +} From 4f7f9e6179da0e776f15a81b064ff4640427a337 Mon Sep 17 00:00:00 2001 From: Tomeshwari-02 <179694969+Tomeshwari-02@users.noreply.github.com> Date: Sat, 25 Apr 2026 08:51:00 +0530 Subject: [PATCH 3/3] fix: harden van sp validation flow --- .../cho/repositories/UserRepo.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt index 13e390ad3..1fc793de4 100644 --- a/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt +++ b/app/src/main/java/org/piramalswasthya/cho/repositories/UserRepo.kt @@ -217,16 +217,16 @@ class UserRepo @Inject constructor( val responseJson = JSONObject(responseString) val data = responseJson.getJSONObject("data") val vanSpDetailsArray = data.getJSONArray("UserVanSpDetails") + var validEntryFound = false + var missingFacilityFound = false for (i in 0 until vanSpDetailsArray.length()) { val vanSp = vanSpDetailsArray.getJSONObject(i) if (!vanSp.has("facilityID")) { - withContext(Dispatchers.Main) { - Toast.makeText(context, "Facility ID not found", Toast.LENGTH_LONG).show() - } - delay(3000) + missingFacilityFound = true continue } + validEntryFound = true val vanId = vanSp.getInt("vanID") user?.vanId = vanId val servicePointId = vanSp.getInt("servicePointID") @@ -238,7 +238,13 @@ class UserRepo @Inject constructor( user?.parkingPlaceId = vanSp.getInt("parkingPlaceID") } - true + if (missingFacilityFound) { + withContext(Dispatchers.Main) { + Toast.makeText(context, "Facility ID not found", Toast.LENGTH_LONG).show() + } + delay(3000) + } + validEntryFound } else { false } @@ -331,10 +337,13 @@ class UserRepo @Inject constructor( user?.serviceMapId = serviceMapId TokenInsertTmcInterceptor.setToken(token) preferenceDao.registerPrimaryApiToken(token) - preferenceDao.registerUser(user!!) - getUserVanSpDetails(context) + if (!getUserVanSpDetails(context)) { + user = null + return@withContext + } getLocDetailsBasedOnSpIDAndPsmID() getUserMasterVillage() + preferenceDao.registerUser(user!!) } else { val errorMessage = responseBody.getString("errorMessage") GlobalScope.launch(Dispatchers.Main) {