offline incubation code is added

This commit is contained in:
Mariya
2023-12-07 15:36:28 +05:30
parent dadddfd558
commit 85986c87b1
4 changed files with 27 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
package com.example.hpostesting.presentation.adapter
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
@@ -54,12 +55,19 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
return differ.currentList.size
}
@SuppressLint("SetTextI18n")
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}"
time.text = "Time: ${isBetween15And30Minutes(userList.incubationTime)} \n Started at: ${
SimpleDateFormat("HH:mm:ss").format(
SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
).parse(userList.incubationTime)!!
)
}"
userCard.setOnClickListener {
if (batLevel < 40) {
Toast.makeText(
@@ -109,6 +117,8 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
}
}
}
}
}
@@ -122,4 +132,13 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
return diffMillis / (60 * 1000)
}
private fun saveIncubationLocally(incubationTime: String) {
val sharedPreferences = view.context.getSharedPreferences("LocalData", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
editor.putString("localIncubationTime", incubationTime)
// Add any other necessary data
editor.apply()
}
}

View File

@@ -138,6 +138,7 @@ class HomeFragment : Fragment() {
binding.btnSubmit.setOnClickListener {
val userId = binding.userId.text.toString()
val bloodGroup = binding.etBloodGroup.text
if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
hemoCubeViewModel.addUser(
HemoCubeTestData(

View File

@@ -359,23 +359,11 @@ class HemoCubeFragment : Fragment() {
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
val deviceRatio = led1Average / led2Average
val coefficientsList = Constants.COEFFICIENTS[deviceSerialNo]
if (coefficientsList != null) {
val coefficient1 = coefficientsList.getOrNull(0)?.get(0) ?: 0.0
val coefficient2 = coefficientsList.getOrNull(1)?.get(0) ?: 0.0
coefficient = "$coefficient1,$coefficient2"
// Now, you can use 'coefficients' to store in Firebase.
} else {
coefficient = currentDeviceData?.coefficients?.get(0)
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
}
// if (isOnline) {
// // Online mode, use coefficients from the server
// coefficients = currentDeviceData?.coefficients?.get(0)
// .toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
// } else {
// Offline mode, provide default coefficients or handle as needed
// if (coefficientsList != null) {
val coefficient1 = coefficientsList?.get(0)?.get(0).toString()
val coefficient2 = coefficientsList?.get(1)?.get(0).toString()
val coefficientsString = "$coefficient1,$coefficient2"
// }
// if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
// if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
// if (deviceRatio < 0.08) {
@@ -405,7 +393,7 @@ class HemoCubeFragment : Fragment() {
this.deviceRatio = deviceRatio
this.calculatedRatio = calculateRatio(deviceRatio)
// this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
this.coefficients = coefficient
this.coefficients = coefficientsString
this.classificationResult = findResult(calculatedRatio)
hemoCubeViewModel.messages.postValue(this.classificationResult)
this.resultData = deviceLog

View File

@@ -62,8 +62,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/bloodGroup"
tools:text="Test Status: Completed" />
tools:text="startedAt: yyyy-MM-dd HH:mm:ss" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>