try catch for user data load

This commit is contained in:
Pritimay Sarkar
2023-09-30 09:48:00 +05:30
parent a61aab377e
commit d6ffcba70a
2 changed files with 21 additions and 16 deletions

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DesignSurface"> <component name="DesignSurface">
<option name="filePathToZoomLevelMap"> <option name="filePathToZoomLevelMap">

View File

@@ -109,24 +109,30 @@ class HomeFragment : Fragment() {
} }
} }
private fun loadUserData() { private fun loadUserData() {
val dateFormat = SimpleDateFormat("yyyy-MM-dd") try {
val currentDate = Date() val dateFormat = SimpleDateFormat("yyyy-MM-dd")
val formattedDate = dateFormat.format(currentDate) val currentDate = Date()
val query = Firebase.firestore.collection("patientData").whereGreaterThanOrEqualTo("createdAt", formattedDate).orderBy("createdAt", Query.Direction.DESCENDING) val formattedDate = dateFormat.format(currentDate)
val query = Firebase.firestore.collection("patientData")
.whereGreaterThanOrEqualTo("createdAt", formattedDate)
.orderBy("createdAt", Query.Direction.DESCENDING)
// val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false) // val query = Firebase.firestore.collection("patientData").whereEqualTo("testStatus", false)
query.get().addOnSuccessListener { query.get().addOnSuccessListener {
if (it.documents.isEmpty()) { if (it.documents.isEmpty()) {
binding.pendingTest.visibility = View.VISIBLE binding.pendingTest.visibility = View.VISIBLE
} else { } else {
binding.pendingTest.visibility = View.GONE binding.pendingTest.visibility = View.GONE
}
} }
val recyclerViewOptions =
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
.build()
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
binding.rvOrder.adapter = rvAdapter
rvAdapter.startListening()
} catch (e: Exception) {
Firebase.crashlytics.recordException(e)
} }
val recyclerViewOptions =
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
.build()
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root)
binding.rvOrder.adapter = rvAdapter
rvAdapter.startListening()
} }
private fun saveUserId(userId: String) { private fun saveUserId(userId: String) {
with(sharedPreference.edit()) { with(sharedPreference.edit()) {