use default device if the device id is not present
This commit is contained in:
@@ -4,8 +4,10 @@ enum class HemoCubeCommands(val command: String) {
|
||||
START_BUFFER_COMMAND("B\r"),
|
||||
AUTO_DAC_COMMAND("C\r"),
|
||||
DIAGNOSTICS_COMMAND("D\r"),
|
||||
FIRMWARE_INFO_COMMAND("F\r"),
|
||||
START_SAMPLE("S\r"),
|
||||
PRINT_COMMAND("P\r"),
|
||||
READ_DAC_COMMAND("R\r"),
|
||||
DEVICE_CONFIGURATION_COMMAND("I\r"),
|
||||
FIRST_GAIN_COMMAND("T\r"),
|
||||
SECOND_GAIN_COMMAND("U\r"),
|
||||
|
||||
@@ -43,7 +43,7 @@ class GalleryFragment : Fragment() {
|
||||
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
sharedPreferences =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
|
||||
sharedPreference = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
|
||||
|
||||
@@ -53,12 +53,13 @@ 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 val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
|
||||
@@ -71,7 +72,6 @@ class HomeFragment : Fragment() {
|
||||
|
||||
sharedPreference = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
DataHolder.selectedTest = null
|
||||
DataHolder.hemoCubeTestData = HemoCubeTestData()
|
||||
|
||||
return binding.root
|
||||
}
|
||||
@@ -168,6 +168,8 @@ class HomeFragment : Fragment() {
|
||||
requireActivity().finish()
|
||||
}
|
||||
binding.btnQuickCapture.setOnClickListener {
|
||||
DataHolder.hemoCubeTestData = HemoCubeTestData()
|
||||
|
||||
val i = Intent(
|
||||
requireContext().applicationContext, AssuranceControlsActivity::class.java
|
||||
)
|
||||
@@ -209,7 +211,11 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred in login: $message", Toast.LENGTH_LONG)
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred in login: $message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -233,7 +239,11 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred check update: $message", Toast.LENGTH_LONG)
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred check update: $message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -258,7 +268,11 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred in uploading logs: $message", Toast.LENGTH_LONG)
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred in uploading logs: $message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -328,7 +342,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()) {
|
||||
if (userId.length >= 10 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) {
|
||||
hemoCubeViewModel.addUser(
|
||||
HemoCubeTestData(
|
||||
_id = userId,
|
||||
@@ -595,7 +609,8 @@ class HomeFragment : Fragment() {
|
||||
val success = homeViewModel.getLocalUserDataForCsv(context)
|
||||
if (success) {
|
||||
// Provide feedback to the user if needed
|
||||
Toast.makeText(context, "CSV file downloaded successfully", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, "CSV file downloaded successfully", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
} else {
|
||||
// Handle the case where CSV file generation failed
|
||||
Toast.makeText(context, "Failed to download CSV file", Toast.LENGTH_SHORT).show()
|
||||
@@ -620,48 +635,44 @@ class HomeFragment : Fragment() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
var csvDownloaded = false
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
try {
|
||||
if (!csvDownloaded) {
|
||||
|
||||
|
||||
val downloadList = mutableListOf<HemoCubeTestData>()
|
||||
|
||||
userDataList.forEach { userData ->
|
||||
if(userData.testStatus == true) {
|
||||
if (userData.testStatus == true) {
|
||||
// if (!userData.isCSVCreated) {
|
||||
downloadList.add(userData) // Add the userData to downloadList
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
if (downloadList.isNotEmpty()) {
|
||||
// Call ViewModel function to create CSV with filtered data
|
||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||
csvDownloaded = true
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"CSV file downloaded successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"No data to download",
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
if (downloadList.isNotEmpty()) {
|
||||
// Call ViewModel function to create CSV with filtered data
|
||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||
csvDownloaded = true
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"CSV file downloaded successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"No data to download",
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
} finally {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
@@ -586,30 +586,37 @@ class HemoCubeFragment : Fragment() {
|
||||
val hardwareId = matchResult?.value
|
||||
|
||||
if (hardwareId?.length == expectedLength) {
|
||||
deviceHardwareId += hardwareId
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceHardwareId)
|
||||
apply()
|
||||
}
|
||||
this.testStatusCode = TestStatus.CONFIG_COMPLETED.code
|
||||
updateDeviceId(hardwareId)
|
||||
activity?.runOnUiThread {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.messages.postValue(getString(R.string.start))
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
deviceHardwareId = "HCV-000-3001"
|
||||
allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
Toast.makeText(requireContext(), "Calibration configuration for this device id is not found", Toast.LENGTH_SHORT).show()
|
||||
// Toast.makeText(requireContext(), "Calibration configuration for this device id is not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
Toast.makeText(requireContext(), "ADC thresholds for this device id are not found", Toast.LENGTH_SHORT).show()
|
||||
// Toast.makeText(requireContext(), "ADC thresholds for this device id are not found", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.messages.postValue("Config error")
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDeviceId(hardwareId: String?) {
|
||||
hardwareId?.let {
|
||||
deviceHardwareId += it
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceHardwareId)
|
||||
apply()
|
||||
}
|
||||
testStatusCode = TestStatus.CONFIG_COMPLETED.code
|
||||
}
|
||||
}
|
||||
|
||||
fun handleBackButtonPress() {
|
||||
if (isTestOngoing) {
|
||||
showToast(R.string.test_go_noback)
|
||||
|
||||
Reference in New Issue
Block a user