diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt index 71c8476..00e5a3d 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt @@ -1159,7 +1159,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{ @@ -1183,14 +1183,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." + ) + } } } } @@ -1212,8 +1222,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.") }