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