diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt index 6a9d7e0..2d087f9 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt @@ -138,6 +138,7 @@ class HomeFragment : Fragment() { viewModel.allUserData.observe(viewLifecycleOwner) { userData -> deleteIncompleteRegistrations(userData) } + getLocationIP() hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData -> deleteHemoCubeIncompleteRegistrations(userData) if (userData.isNotEmpty()) { @@ -192,25 +193,26 @@ class HomeFragment : Fragment() { //// showUploadDialog(requireContext()) // } hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData -> - if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") { - val btnSaveLocalVisibility = - if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE - binding.downloadCSV.visibility = btnSaveLocalVisibility - binding.downloadCSV.setOnClickListener { - if (btnSaveLocalVisibility == View.VISIBLE) { - // Execute the action when the button is visible (testStatus is true for at least one user) - showDownloadDialog(requireContext()) - } else { - // Handle the case when the button is not visible - Toast.makeText( - requireContext(), - "No test details stored locally", - Toast.LENGTH_SHORT - ).show() - } +// if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") { +// +// }else{ +// binding.downloadCSV.visibility = View.GONE +// } + val btnSaveLocalVisibility = + if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE + binding.downloadCSV.visibility = btnSaveLocalVisibility + binding.downloadCSV.setOnClickListener { + if (btnSaveLocalVisibility == View.VISIBLE) { + // Execute the action when the button is visible (testStatus is true for at least one user) + showDownloadDialog(requireContext()) + } else { + // Handle the case when the button is not visible + Toast.makeText( + requireContext(), + "No test details stored locally", + Toast.LENGTH_SHORT + ).show() } - }else{ - binding.downloadCSV.visibility = View.GONE } } @@ -256,6 +258,18 @@ class HomeFragment : Fragment() { checkNetworkStatus() } + private fun getLocationIP() { + getPublicIpAddr { ipAddress -> + if(ipAddress != "fail"){ + DataHolder.ipAddress = ipAddress + with(sharedPreference.edit()) { + putString(Constants.IP_ADDRESS, ipAddress) + apply() + } + } + } + } + @RequiresApi(Build.VERSION_CODES.P) private fun checkNetworkStatus() { hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isConnected -> diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index 084d3d2..24fb9d4 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -150,6 +150,7 @@ class HemoCubeFragment : Fragment() { if (isBufferValueAvailable()){ hemoCubeViewModel.messages.postValue("Ready to test") + isUsingExistingBuffer = true binding.btnPlacebuffer.apply { setBackgroundColor(Color.GREEN) // Set button background color to green text = "Refresh Buffer" // Change button text to "Buffer Exists" @@ -997,7 +998,19 @@ class HemoCubeFragment : Fragment() { //used for latest trueheme and v1 val deviceRatio = led2Average / led1Average val borderlineMetric = (led1Average - led2Average) / deviceRatio - +// activity?.runOnUiThread { +// Toast.makeText(requireContext(),"led1Average: $led1Average, led2Average: $led2Average",Toast.LENGTH_LONG).show() +// } + if(led1Average < 0 || led2Average < 0){ + hemoCubeViewModel.messages.postValue("Negative Absorbance - Repeat test with reading Buffer first and sample second") + this.testStatusCode = TestStatus.BUFFER_PRINT_COMPLETED.code + binding.testing.visibility = View.GONE + binding.btnPlacebuffer.visibility = View.GONE + binding.btnSamplestart.visibility = View.VISIBLE + binding.btnSamplestart.isClickable = true + binding.btnSamplestart.isEnabled = true + return + } if(Constants.ABS_FLAGS_ENABLED){ val inRange2mmLed1: Boolean val inRange2mmLed2: Boolean