offline adapter added
This commit is contained in:
@@ -70,4 +70,11 @@ object Constants {
|
|||||||
const val BUFFER_VALUE_1 = "BufferValue1"
|
const val BUFFER_VALUE_1 = "BufferValue1"
|
||||||
const val BUFFER_VALUE_2 = "BufferValue2"
|
const val BUFFER_VALUE_2 = "BufferValue2"
|
||||||
const val DEVICE_ID = "DEVICE_ID"
|
const val DEVICE_ID = "DEVICE_ID"
|
||||||
|
|
||||||
|
val COEFFICIENTS: Map<String, List<List<Double>>> = mapOf(
|
||||||
|
"HC-V1-001" to listOf(
|
||||||
|
listOf(1.5,0.0),
|
||||||
|
listOf(0.0,0.0)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ data class UserData(
|
|||||||
var name: String = "",
|
var name: String = "",
|
||||||
var incubationTime: String = "",
|
var incubationTime: String = "",
|
||||||
var birthYear: String = "",
|
var birthYear: String = "",
|
||||||
|
var bloodGroup: String = "",
|
||||||
var userImageURL: String = "",
|
var userImageURL: String = "",
|
||||||
var location: Location? = null,
|
var location: Location? = null,
|
||||||
var createdBy: String? = "",
|
var createdBy: String? = "",
|
||||||
@@ -41,6 +42,7 @@ data class UserData(
|
|||||||
fun UserData.toHemoCubeTestData() = HemoCubeTestData(
|
fun UserData.toHemoCubeTestData() = HemoCubeTestData(
|
||||||
_id = _id,
|
_id = _id,
|
||||||
name = name,
|
name = name,
|
||||||
|
bloodGroup = bloodGroup,
|
||||||
birthYear = birthYear,
|
birthYear = birthYear,
|
||||||
userImageURL = userImageURL,
|
userImageURL = userImageURL,
|
||||||
testStatus = testStatus,
|
testStatus = testStatus,
|
||||||
|
|||||||
@@ -73,30 +73,43 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||||
deleteHemoCubeIncompleteRegistrations(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 ->
|
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
||||||
if (isConnected) {
|
// if (isConnected) {
|
||||||
binding.internetAvailableCL.visibility = View.VISIBLE
|
// binding.internetAvailableCL.visibility = View.VISIBLE
|
||||||
binding.internetNotAvailableCL.visibility = View.GONE
|
// binding.internetNotAvailableCL.visibility = View.GONE
|
||||||
loadUserData()
|
// loadUserData()
|
||||||
setSearch()
|
// setSearch()
|
||||||
checkForLocalDBData()
|
// checkForLocalDBData()
|
||||||
} else {
|
// } else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
||||||
setUserId()
|
setUserId()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
"Test Results Uploaded Successfully",
|
R.string.test_upload,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
if (result == "Error") {
|
if (result == "Error") {
|
||||||
Toast.makeText(requireContext(), "Test Results Upload Failed", Toast.LENGTH_SHORT)
|
Toast.makeText(requireContext(), R.string.test_upload_failed, Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,10 +133,19 @@ class HomeFragment : Fragment() {
|
|||||||
private fun setUserId() {
|
private fun setUserId() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
val userId = binding.userId.text.toString()
|
val userId = binding.userId.text.toString()
|
||||||
if (userId.length >= 18) {
|
val bloodGroup = binding.etBloodGroup.text
|
||||||
val userData = UserData(_id = userId)
|
|
||||||
DataHolder.selectedTest = userData
|
if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
|
||||||
findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
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 {
|
} else {
|
||||||
val errorMessage = getString(R.string.user_id_error_message)
|
val errorMessage = getString(R.string.user_id_error_message)
|
||||||
Toast.makeText(requireContext(), errorMessage, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), errorMessage, Toast.LENGTH_SHORT).show()
|
||||||
@@ -155,10 +177,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 = view?.let {
|
rvAdapter = view?.let {
|
||||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
UserListAdapter(
|
||||||
it, batLevel, requireActivity())
|
requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||||
}!!
|
it, batLevel, requireActivity()
|
||||||
|
)
|
||||||
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
|
|
||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
@@ -176,14 +200,14 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun logoutUser(context: Context) {
|
private fun logoutUser(context: Context) {
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle("Log Out")
|
builder.setTitle(R.string.log_out)
|
||||||
builder.setMessage("Do you want to LogOut the Application?")
|
builder.setMessage(R.string.do_log_out)
|
||||||
builder.setPositiveButton("Yes") { dialog, _ ->
|
builder.setPositiveButton(R.string.yes) { dialog, _ ->
|
||||||
saveUserId("")
|
saveUserId("")
|
||||||
findNavController().navigate(R.id.action_nav_home_to_loginFragment)
|
findNavController().navigate(R.id.action_nav_home_to_loginFragment)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
builder.setNegativeButton("No") { dialog, _ ->
|
builder.setNegativeButton(R.string.no) { dialog, _ ->
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +230,9 @@ class HomeFragment : Fragment() {
|
|||||||
val partition = dateFormat.format(currentDate)
|
val partition = dateFormat.format(currentDate)
|
||||||
val searchTerm = partition + search
|
val searchTerm = partition + search
|
||||||
val searchField = field + "Search"
|
val searchField = field + "Search"
|
||||||
val query = Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm)
|
val query =
|
||||||
.endAt(searchTerm + "\uf8ff")
|
Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm)
|
||||||
|
.endAt(searchTerm + "\uf8ff")
|
||||||
query.get().addOnSuccessListener {
|
query.get().addOnSuccessListener {
|
||||||
userSearchTrace.stop()
|
userSearchTrace.stop()
|
||||||
}
|
}
|
||||||
@@ -218,7 +243,14 @@ class HomeFragment : Fragment() {
|
|||||||
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
|
|
||||||
rvAdapter = view?.let {
|
rvAdapter = view?.let {
|
||||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel, requireActivity())
|
UserListAdapter(
|
||||||
|
requireContext(),
|
||||||
|
hemoCubeViewModel,
|
||||||
|
recyclerViewOptions,
|
||||||
|
it,
|
||||||
|
batLevel,
|
||||||
|
requireActivity()
|
||||||
|
)
|
||||||
}!!
|
}!!
|
||||||
binding.rvOrder.adapter = rvAdapter
|
binding.rvOrder.adapter = rvAdapter
|
||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
@@ -272,7 +304,8 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
val uploadDataVisibility = if (userDataList.any { !it.localFlag }) View.VISIBLE else View.GONE
|
val uploadDataVisibility =
|
||||||
|
if (userDataList.any { !it.localFlag && it.testStatus == true}) View.VISIBLE else View.GONE
|
||||||
binding.uploadData.visibility = uploadDataVisibility
|
binding.uploadData.visibility = uploadDataVisibility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,7 +364,7 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun deleteHemoCubeIncompleteRegistrations(userDataList: List<HemoCubeTestData>) {
|
private fun deleteHemoCubeIncompleteRegistrations(userDataList: List<HemoCubeTestData>) {
|
||||||
userDataList.forEach { userData ->
|
userDataList.forEach { userData ->
|
||||||
if (userData.testTime?.isEmpty() == true) {
|
if (userData._id.isEmpty()) {
|
||||||
hemoCubeViewModel.deleteById(userData._id)
|
hemoCubeViewModel.deleteById(userData._id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private var currentDeviceData: DeviceData? = null
|
private var currentDeviceData: DeviceData? = null
|
||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
private var isUsingExistingBuffer = false
|
private var isUsingExistingBuffer = false
|
||||||
|
private var loginId: String = ""
|
||||||
private var isTestOngoing = false
|
private var isTestOngoing = false
|
||||||
private var startListening = MutableLiveData<Boolean>(false)
|
private var startListening = MutableLiveData<Boolean>(false)
|
||||||
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
||||||
@@ -98,7 +99,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
(activity as HemocubeActivity).finish()
|
(activity as HemocubeActivity).finish()
|
||||||
}
|
}
|
||||||
if (result == "Local") {
|
if (result == "Local") {
|
||||||
showToast("Internet not available, test details stored locally")
|
showToast("test details stored locally")
|
||||||
|
// showToast("Internet not available, test details stored locally")
|
||||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||||
}
|
}
|
||||||
if (result == "Error") {
|
if (result == "Error") {
|
||||||
@@ -345,6 +347,10 @@ class HemoCubeFragment : Fragment() {
|
|||||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||||
val deviceRatio = led1Average / led2Average
|
val deviceRatio = led1Average / led2Average
|
||||||
|
val coefficientsList = Constants.COEFFICIENTS[loginId]
|
||||||
|
val coefficient1 = coefficientsList?.get(0)?.get(0)
|
||||||
|
val coefficient2 = coefficientsList?.get(0)?.get(1)
|
||||||
|
val coefficientsString = "$coefficient1,$coefficient2"
|
||||||
// if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
|
// if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
|
||||||
// if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
|
// if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
|
||||||
// if (deviceRatio < 0.08) {
|
// if (deviceRatio < 0.08) {
|
||||||
@@ -373,7 +379,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
this.led2Average = led2Average
|
this.led2Average = led2Average
|
||||||
this.deviceRatio = deviceRatio
|
this.deviceRatio = deviceRatio
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||||
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
// this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||||
|
this.coefficients = coefficientsString
|
||||||
this.classificationResult = findResult(calculatedRatio)
|
this.classificationResult = findResult(calculatedRatio)
|
||||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||||
this.resultData = deviceLog
|
this.resultData = deviceLog
|
||||||
@@ -475,8 +482,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateRatio(ratio: Double): Double {
|
private fun calculateRatio(ratio: Double): Double {
|
||||||
val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0
|
val coefficient1: Double = (Constants.COEFFICIENTS[loginId]?.get(0)?.get(0)) as Double
|
||||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
val coefficient2: Double = (Constants.COEFFICIENTS[loginId]?.get(1)?.get(0)) as Double
|
||||||
return coefficient1 * ratio + coefficient2
|
return coefficient1 * ratio + coefficient2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,4 +515,17 @@ class HemoCubeFragment : Fragment() {
|
|||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,10 +190,23 @@
|
|||||||
<string name="upload">Upload</string>
|
<string name="upload">Upload</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="upload_success_message">Upload done successfully</string>
|
<string name="upload_success_message">Upload done successfully</string>
|
||||||
<string name="test_completed">Test Completed</string>
|
<string name="low_battery_warning">Battery level is low than 40%, please charge the device to continue testing</string>
|
||||||
<string name="select_blood_group">Select Blood Group</string>
|
<string name="test_already_conducted">Test has been already conducted for this user</string>
|
||||||
<string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string>
|
<string name="incubation_not_completed">Incubation has not completed 15 minutes</string>
|
||||||
<string name="start_incubation">Incubate</string>
|
<string name="incubation_crossed_30_minutes">Incubation crossed 30 minutes, need to repeat the incubation</string>
|
||||||
<string name="check_buffer">Check Buffer</string>
|
<string name="incubation_not_started">Incubation not started for this user</string>
|
||||||
|
<string name="test_concluded">Test concluded</string>
|
||||||
|
<string name="test_pending">Test is Pending</string>
|
||||||
|
<string name="blood_group_error">Please enter your blood group</string>
|
||||||
|
<string name="blood_group_toast">Please enter your blood group</string>
|
||||||
|
<string name="blood_group_updated_successfully">Blood group updated successfully</string>
|
||||||
|
<string name="failed_to_update_blood_group">Failed to update blood group: %1$s</string>
|
||||||
|
<string name="no_user_data_found">No user data found for the specified ID</string>
|
||||||
|
<string name="device_disconnected">Device is Disconnected</string>
|
||||||
|
<string name="no_device_found">No device found</string>
|
||||||
|
<string name="invalid_kit_number">Invalid KIT Number</string>
|
||||||
|
<string name="internt_not">Internet is Not Available</string>
|
||||||
|
<string name="internt_not_local">Internet not available, test details stored locally</string>
|
||||||
|
<string name="error_local">Error uploading data, test details stored locally</string>
|
||||||
|
<string name="error_exist">error while getting existing buffer</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user