Compare commits
6 Commits
dev-Adding
...
Bloodgroup
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94ae7310f4 | ||
|
|
c3810b9a92 | ||
|
|
47c6bba0d7 | ||
|
|
5fe18c9d3d | ||
|
|
5349376815 | ||
|
|
4ca17c0fa6 |
@@ -1,6 +1,8 @@
|
|||||||
package com.example.hpostesting.presentation.adapter
|
package com.example.hpostesting.presentation.adapter
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -20,9 +22,19 @@ import java.text.SimpleDateFormat
|
|||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import android.widget.AutoCompleteTextView
|
||||||
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
|
|
||||||
class UserListAdapter(
|
class UserListAdapter(
|
||||||
options: FirestoreRecyclerOptions<UserData>, private val view: View, private val batLevel: Int
|
|
||||||
|
private val context: Context,
|
||||||
|
private val hemoCubeViewModel: HemoCubeViewModel,
|
||||||
|
options: FirestoreRecyclerOptions<UserData>,
|
||||||
|
private val view: View,
|
||||||
|
private val batLevel: Int,
|
||||||
) : FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
) : FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
||||||
|
|
||||||
class OrderItemViewHolder(val binding: UserItemViewBinding) :
|
class OrderItemViewHolder(val binding: UserItemViewBinding) :
|
||||||
@@ -40,7 +52,7 @@ class UserListAdapter(
|
|||||||
userName.text = "Name: ${model.name}"
|
userName.text = "Name: ${model.name}"
|
||||||
userId.text = "User ID:${model._id}"
|
userId.text = "User ID:${model._id}"
|
||||||
if (model.incubationTime == "") {
|
if (model.incubationTime == "") {
|
||||||
btnStartIncubation.visibility = View.VISIBLE
|
|
||||||
} else {
|
} else {
|
||||||
userId.text =
|
userId.text =
|
||||||
"User ID:${model._id} \n Time: ${isBetween15And30Minutes(model.incubationTime)} \n Started at: ${
|
"User ID:${model._id} \n Time: ${isBetween15And30Minutes(model.incubationTime)} \n Started at: ${
|
||||||
@@ -50,7 +62,7 @@ class UserListAdapter(
|
|||||||
).parse(model.incubationTime)!!
|
).parse(model.incubationTime)!!
|
||||||
)
|
)
|
||||||
}"
|
}"
|
||||||
btnStartIncubation.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,8 +73,46 @@ class UserListAdapter(
|
|||||||
} else {
|
} else {
|
||||||
teststatus.text = "Test is Pending"
|
teststatus.text = "Test is Pending"
|
||||||
}
|
}
|
||||||
btnStartIncubation.setOnClickListener {
|
|
||||||
it.visibility = View.GONE
|
holder.binding.btnBlood.setOnClickListener {
|
||||||
|
val inflater = LayoutInflater.from(context)
|
||||||
|
val dialogView = inflater.inflate(R.layout.dialog_custom, null)
|
||||||
|
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
.setView(dialogView)
|
||||||
|
.setTitle("Add Blood Group")
|
||||||
|
|
||||||
|
val etBloodGroup = dialogView.findViewById<AutoCompleteTextView>(R.id.et_blood_group)
|
||||||
|
|
||||||
|
builder.setPositiveButton("OK") { dialog, which ->
|
||||||
|
val bloodGroup = etBloodGroup.text.toString()
|
||||||
|
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 db: FirebaseFirestore = FirebaseFirestore.getInstance()
|
||||||
|
|
||||||
|
db.collection("patientData")
|
||||||
|
.whereEqualTo("_id", model._id)
|
||||||
|
.get()
|
||||||
|
.addOnSuccessListener { userdata ->
|
||||||
|
try {
|
||||||
|
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()
|
||||||
|
btnBlood.visibility = View.GONE
|
||||||
Firebase.firestore.collection("patientData").whereEqualTo("_id", model._id).get()
|
Firebase.firestore.collection("patientData").whereEqualTo("_id", model._id).get()
|
||||||
.addOnSuccessListener { data ->
|
.addOnSuccessListener { data ->
|
||||||
if (data.documents.isNotEmpty()) {
|
if (data.documents.isNotEmpty()) {
|
||||||
@@ -82,6 +132,43 @@ class UserListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.addOnFailureListener { e ->
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"Failed to update blood group: ${e.message}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
} catch (e: IndexOutOfBoundsException) {
|
||||||
|
// Handle the case where no documents are found for the specified ID
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"No user data found for the specified ID",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setNegativeButton("Cancel") { dialog, which ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
val alertDialog = builder.create()
|
||||||
|
alertDialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
userCard.setOnClickListener {
|
userCard.setOnClickListener {
|
||||||
if (batLevel < 40) {
|
if (batLevel < 40) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@@ -130,6 +217,8 @@ class UserListAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun isBetween15And30Minutes(createdAt: String): Long {
|
private fun isBetween15And30Minutes(createdAt: String): Long {
|
||||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||||
val createdAtDate: Date = formatter.parse(createdAt)!!
|
val createdAtDate: Date = formatter.parse(createdAt)!!
|
||||||
@@ -142,4 +231,9 @@ class UserListAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,9 @@ class HomeFragment : Fragment() {
|
|||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
private lateinit var rvAdapter: UserListAdapter
|
private lateinit var rvAdapter: UserListAdapter
|
||||||
|
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||||
|
|
||||||
|
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
@@ -151,8 +154,12 @@ class HomeFragment : Fragment() {
|
|||||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
|
|
||||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root, batLevel)
|
rvAdapter = view?.let {
|
||||||
|
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||||
|
it, batLevel)
|
||||||
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
|
|
||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Firebase.crashlytics.recordException(e)
|
Firebase.crashlytics.recordException(e)
|
||||||
@@ -195,11 +202,12 @@ class HomeFragment : Fragment() {
|
|||||||
val recyclerViewOptions =
|
val recyclerViewOptions =
|
||||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
|
|
||||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root, batLevel)
|
rvAdapter = view?.let {
|
||||||
|
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel)
|
||||||
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
}
|
}
|
||||||
|
|||||||
24
app/src/main/res/layout/dialog_custom.xml
Normal file
24
app/src/main/res/layout/dialog_custom.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/til_blood_group"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/et_blood_group"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/select_blood_group"
|
||||||
|
android:inputType="none"
|
||||||
|
android:labelFor="@id/til_blood_group"
|
||||||
|
app:simpleItems="@array/blood_group" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
</LinearLayout>
|
||||||
@@ -72,16 +72,15 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/userId"
|
app:layout_constraintTop_toBottomOf="@id/userId"
|
||||||
tools:text="Test Status: Completed"/>
|
tools:text="Test Status: Completed"/>
|
||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_startIncubation"
|
android:id="@+id/btn_blood"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="16dp"
|
android:layout_marginHorizontal="16dp"
|
||||||
android:text="@string/start_incubation"
|
android:text="@string/blood_group"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
app:layout_constraintStart_toEndOf="@+id/userImage"
|
app:layout_constraintTop_toBottomOf="@id/teststatus" />
|
||||||
app:layout_constraintTop_toBottomOf="@+id/teststatus" />
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user