I've created an application in which I've used a Firestore database.
Now my tasks are this, User can take action of update document within time duration.
I mean if the user tried to update while online mode then there is no problem
But if the user device have connection issue of poor network connection then this update action should be trigger within 20 seconds to save on the Firestore server.
If a user can't do within time duration then the last action should be rolled out I mean cache action should not be push after 20 seconds
For Offline mode restrictions, I've set this setPersistenceEnabled(false) But still document update are sending which there is an issue with a network connection.
In the Realtime Database, there is one way to find out device connectivity https://firebase.google.com/docs/database/android/offline-capabilities
Is there any way in Firestore?
I've tried to disable/enable Network mode but it will not help me to solve this issue
https://cloud.google.com/firestore/docs/manage-data/enable-offline#kotlin+ktxandroid_4
db.disableNetwork
db.enableNetwork
I need this functinality in Android
I've tried this code to clear my ongoing request
val hashMap = HashMap<String, Any>()
hashMap["status"] = "ACCEPTED"
hashMap["time"] = time
app().firestoreDB
.collection("doc")
.document("id")
.update(hashMap)
.addOnSuccessListener {
isStoredOnServer = true
// my action
}
object : CountDownTimer(20000, 1000) {
override fun onTick(millisUntilFinished: Long) {
if(isStoredOnServer){
this.cancel()
}
}
override fun onFinish() {
if(!isStoredOnServer) {
FirebaseFirestore.getInstance().clearPersistence()
.addOnFailureListener { e -> Log.d("Firestore", "Error persistence writing document $e") }
.addOnSuccessListener { Log.d("Could enable persistence:") }
}
}
}.start()