Added Blood group pop up dialog in user card
This commit is contained in:
@@ -156,41 +156,57 @@ class UserListAdapter(
|
||||
|
||||
builder.setPositiveButton("OK") { dialog, which ->
|
||||
val bloodGroup = etBloodGroup.text.toString()
|
||||
if (bloodGroup.isEmpty()) {
|
||||
if (bloodGroup.equals("Select Blood Group") || bloodGroup.isNullOrBlank()) {
|
||||
etBloodGroup.error = "Please enter your blood group"
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Please enter your blood group",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
// Check if hemoCubeViewModel and testDetails are not null
|
||||
val testDetails = hemoCubeViewModel.testDetails
|
||||
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
|
||||
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
|
||||
|
||||
db.collection("patientData")
|
||||
.whereEqualTo("_id", testDetails?._id)
|
||||
.get()
|
||||
.addOnSuccessListener { userdata ->
|
||||
if (userdata.documents.isNotEmpty()) {
|
||||
db.collection("patientData")
|
||||
.document(userdata.documents[0].id)
|
||||
.update("bloodGroup", bloodGroup)
|
||||
.addOnSuccessListener {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Blood group updated successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
db.collection("patientData")
|
||||
.whereEqualTo("_id", testDetails?._id)
|
||||
.get()
|
||||
.addOnSuccessListener { userdata ->
|
||||
if (userdata.isEmpty) {
|
||||
// Handle the case when no documents are found (e.g., display a message)
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Failed to update blood group: ${e.message}",
|
||||
"No user data found for the specified ID",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
val document = userdata.documents[0]
|
||||
db.collection("patientData")
|
||||
.document(document.id)
|
||||
.update("bloodGroup", bloodGroup)
|
||||
.addOnSuccessListener {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Blood group updated successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Failed to update blood group: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Error fetching user data: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
// Handle the selected blood group here
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user