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