Compare commits
1 Commits
prod
...
Develop_Of
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcc7a921a0 |
@@ -8,6 +8,8 @@ data class HemoCubeTestData(
|
||||
@PrimaryKey
|
||||
var _id: String = "",
|
||||
var name: String = "",
|
||||
var incubationTime: String = "",
|
||||
var bloodGroup: String = "",
|
||||
var birthYear: String = "",
|
||||
var userImageURL: String = "",
|
||||
var location: UserData.Location? = null,
|
||||
|
||||
@@ -9,6 +9,7 @@ data class UserData(
|
||||
@PrimaryKey
|
||||
var _id: String = "",
|
||||
var name: String = "",
|
||||
var bloodGroup: String = "",
|
||||
var incubationTime: String = "",
|
||||
var birthYear: String = "",
|
||||
var userImageURL: String = "",
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.example.hpostesting.presentation.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.AsyncListDiffer
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.OfflineUserListViewBinding
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class OfflineUserListAdapter(private val view: View, private val batLevel: Int) :
|
||||
RecyclerView.Adapter<OfflineUserListAdapter.OfflineUserListViewHolder>() {
|
||||
|
||||
inner class OfflineUserListViewHolder(val binding: OfflineUserListViewBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
private val differCallback = object : DiffUtil.ItemCallback<HemoCubeTestData>() {
|
||||
override fun areItemsTheSame(
|
||||
oldItem: HemoCubeTestData, newItem: HemoCubeTestData
|
||||
): Boolean {
|
||||
return oldItem._id == newItem._id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: HemoCubeTestData, newItem: HemoCubeTestData
|
||||
): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
||||
val differ = AsyncListDiffer(this, differCallback)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OfflineUserListViewHolder {
|
||||
return OfflineUserListViewHolder(
|
||||
OfflineUserListViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return differ.currentList.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: OfflineUserListViewHolder, position: Int) {
|
||||
val userList = differ.currentList[position]
|
||||
holder.binding.apply {
|
||||
userID.text = "User ID: ${userList._id}"
|
||||
bloodGroup.text = "Blood group: ${userList.bloodGroup}"
|
||||
time.text = "Time: ${userList.incubationTime}"
|
||||
userCard.setOnClickListener {
|
||||
if (batLevel < 40) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Battery level is low than 40%, please charge the device to continue testing",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (userList.testStatus != null) {
|
||||
if (userList.testStatus!!) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Test has been already conducted for this user",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
if (userList.incubationTime != "") {
|
||||
if (isBetween15And30Minutes(userList.incubationTime) < 15) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation has not completed 15 minutes",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else if (isBetween15And30Minutes(userList.incubationTime) > 30) {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation crossed 30 minutes, need to repeat the incubation",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
DataHolder.selectedTest = UserData(
|
||||
_id = userList._id,
|
||||
bloodGroup = userList.bloodGroup,
|
||||
incubationTime = userList.incubationTime
|
||||
)
|
||||
view.findNavController()
|
||||
.navigate(R.id.action_nav_home_to_mainActivity)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
view.context,
|
||||
"Incubation not started for this user",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isBetween15And30Minutes(createdAt: String): Long {
|
||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
val createdAtDate: Date = formatter.parse(createdAt)!!
|
||||
|
||||
val currentTime = Calendar.getInstance().time
|
||||
|
||||
val diffMillis = currentTime.time - createdAtDate.time
|
||||
|
||||
return diffMillis / (60 * 1000)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.presentation.KitScanActivity
|
||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||
@@ -33,6 +34,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
@@ -43,7 +45,9 @@ class HomeFragment : Fragment() {
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var rvAdapter: UserListAdapter
|
||||
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||
private var batLevel: Int =
|
||||
0 // Initialize with a default value, or obtain the actual battery level
|
||||
private lateinit var adapter: OfflineUserListAdapter
|
||||
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
@@ -73,6 +77,19 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
deleteHemoCubeIncompleteRegistrations(userData)
|
||||
if (userData.isNotEmpty()) {
|
||||
val userList = mutableListOf<HemoCubeTestData>()
|
||||
userData.forEach {
|
||||
if (it.testStatus == false) {
|
||||
userList.add(it)
|
||||
}
|
||||
}
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
adapter = OfflineUserListAdapter(binding.root, batLevel)
|
||||
adapter.differ.submitList(userList)
|
||||
binding.rvOrderOffline.adapter = adapter
|
||||
}
|
||||
}
|
||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isConnected ->
|
||||
if (isConnected) {
|
||||
@@ -120,10 +137,18 @@ class HomeFragment : Fragment() {
|
||||
private fun setUserId() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val userId = binding.userId.text.toString()
|
||||
if (userId.length >= 18) {
|
||||
val userData = UserData(_id = userId)
|
||||
DataHolder.selectedTest = userData
|
||||
findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||
val bloodGroup = binding.etBloodGroup.text
|
||||
if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
|
||||
hemoCubeViewModel.addUser(
|
||||
HemoCubeTestData(
|
||||
_id = userId, bloodGroup = bloodGroup.toString(), incubationTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time).toString()
|
||||
)
|
||||
)
|
||||
// val userData = UserData(_id = userId)
|
||||
// DataHolder.selectedTest = userData
|
||||
// findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||
} else {
|
||||
val errorMessage = getString(R.string.user_id_error_message)
|
||||
Toast.makeText(requireContext(), errorMessage, Toast.LENGTH_SHORT).show()
|
||||
@@ -155,10 +180,12 @@ class HomeFragment : Fragment() {
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||
it, batLevel, requireActivity())
|
||||
}!!
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(
|
||||
requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||
it, batLevel, requireActivity()
|
||||
)
|
||||
}!!
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
|
||||
rvAdapter.startListening()
|
||||
@@ -206,8 +233,9 @@ class HomeFragment : Fragment() {
|
||||
val partition = dateFormat.format(currentDate)
|
||||
val searchTerm = partition + search
|
||||
val searchField = field + "Search"
|
||||
val query = Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm)
|
||||
.endAt(searchTerm + "\uf8ff")
|
||||
val query =
|
||||
Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm)
|
||||
.endAt(searchTerm + "\uf8ff")
|
||||
query.get().addOnSuccessListener {
|
||||
userSearchTrace.stop()
|
||||
}
|
||||
@@ -218,7 +246,14 @@ class HomeFragment : Fragment() {
|
||||
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel, requireActivity())
|
||||
UserListAdapter(
|
||||
requireContext(),
|
||||
hemoCubeViewModel,
|
||||
recyclerViewOptions,
|
||||
it,
|
||||
batLevel,
|
||||
requireActivity()
|
||||
)
|
||||
}!!
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
@@ -272,7 +307,8 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility = if (userDataList.any { !it.localFlag }) View.VISIBLE else View.GONE
|
||||
val uploadDataVisibility =
|
||||
if (userDataList.any { !it.localFlag }) View.VISIBLE else View.GONE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
}
|
||||
@@ -331,7 +367,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private fun deleteHemoCubeIncompleteRegistrations(userDataList: List<HemoCubeTestData>) {
|
||||
userDataList.forEach { userData ->
|
||||
if (userData.testTime?.isEmpty() == true) {
|
||||
if (userData._id.isEmpty()) {
|
||||
hemoCubeViewModel.deleteById(userData._id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -183,6 +184,10 @@ class HemoCubeViewModel @Inject constructor(
|
||||
hemoCubeDao.updateFieldById(id = userId, true)
|
||||
}
|
||||
|
||||
fun addUser(userData: HemoCubeTestData) = viewModelScope.launch {
|
||||
hemoCubeDao.insertAll(userData)
|
||||
}
|
||||
|
||||
fun deleteById(userId: String) = viewModelScope.launch {
|
||||
hemoCubeDao.deleteById(id = userId)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
android:id="@+id/internetNotAvailableCL"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
android:visibility="visible"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
@@ -57,6 +57,27 @@
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<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"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/til_name">
|
||||
|
||||
<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>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_submit"
|
||||
android:layout_width="match_parent"
|
||||
@@ -66,7 +87,18 @@
|
||||
app:cornerRadius="100dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/til_name" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/til_blood_group" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_order_offline"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn_submit"
|
||||
tools:listitem="@layout/offline_user_list_view" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -74,7 +106,7 @@
|
||||
android:id="@+id/internetAvailableCL"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
android:visibility="gone"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
|
||||
71
app/src/main/res/layout/offline_user_list_view.xml
Normal file
71
app/src/main/res/layout/offline_user_list_view.xml
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/userCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
app:cardBackgroundColor="@color/primary_light"
|
||||
app:cardCornerRadius="25dp"
|
||||
app:cardElevation="0dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/userID"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:gravity="start"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Name: MohamedKaif" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bloodGroup"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:gravity="start"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/userID"
|
||||
tools:text="UserID: MohamedKaif" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
style="@style/title1_1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:gravity="start"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/bloodGroup"
|
||||
tools:text="Test Status: Completed" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -183,8 +183,8 @@
|
||||
<string name="user_list">User List</string>
|
||||
<string name="user_id">User ID</string>
|
||||
<string name="aadhar_id">Aadhar ID</string>
|
||||
<string name="internet_not_available_please_enter_the_user_id_manually">Internet not available, please enter the user ID manually</string>
|
||||
<string name="user_id_error_message">User ID should be 18 digits</string>
|
||||
<string name="internet_not_available_please_enter_the_user_id_manually">Internet not available, please enter the user ID and blood group manually</string>
|
||||
<string name="user_id_error_message">User ID should be 18 digits and please select the blood group</string>
|
||||
<string name="upload_db_registration_title">Upload DB Registration</string>
|
||||
<string name="upload_db_registration_message">Do you want to upload the local DB Registration to the cloud?</string>
|
||||
<string name="upload">Upload</string>
|
||||
|
||||
Reference in New Issue
Block a user