From 238debae856030caaea8af43cfbbd1cc8b912393 Mon Sep 17 00:00:00 2001 From: chandrashekhar reddy Date: Tue, 30 Apr 2024 17:56:51 +0530 Subject: [PATCH] device Diagnostics updated the screen with progress bar --- .../presentation/dashboard/HomeFragment.kt | 2 +- .../diagnostics/DiagnosticsFragment.kt | 56 +++++++++++++++++-- .../main/res/layout/fragment_diagnostics.xml | 11 +++- 3 files changed, 62 insertions(+), 7 deletions(-) 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 8356c89..e0fe2ea 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 @@ -375,7 +375,7 @@ class HomeFragment : Fragment() { } } else if (userID == "deviceIDAPI" && password == "devicePasswordAPI" && deviceId.isNotEmpty()) { fetchDeviceCredentials() - } else if (!file.exists()) { + } else if (file.exists()) {// change back without! val encryptedString = file.readText() val encryptionKey = Settings.Secure.getString(context?.contentResolver, Settings.Secure.ANDROID_ID) diff --git a/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt index 4a22868..0939c6f 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/diagnostics/DiagnosticsFragment.kt @@ -18,6 +18,7 @@ import android.content.Intent import android.content.IntentFilter import android.content.SharedPreferences import android.os.Bundle +import android.os.Handler import android.text.method.ScrollingMovementMethod import android.util.Log import android.view.LayoutInflater @@ -35,6 +36,7 @@ import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsReq import com.example.hpostesting.data.model.diagnostics.DiagnosticsData import com.example.hpostesting.data.model.patient.DeviceData import com.example.hpostesting.presentation.autodac.AutoDacActivity +import com.example.hpostesting.presentation.hemocube.HemocubeActivity import com.example.hpostesting.presentation.utils.UsbServiceListener import com.example.hpostesting.util.Result import com.example.hpostesting.util.Result.Success @@ -53,6 +55,9 @@ class DiagnosticsFragment : Fragment() { var led2Dac: Int? = null var led3Dac: Int? = null var led4Dac: Int? = null + private var currentProgress = 0 + private val targetProgress = 95 // Target progress value + private val delayBetweenIncrements = 1500 private var testStatusCode = 0.0 private lateinit var binding: FragmentDiagnosticsBinding private val diagnosticsViewModel: DiagnosticsViewModel by activityViewModels() @@ -88,7 +93,9 @@ class DiagnosticsFragment : Fragment() { getDeviceId() binding.btnSubmit.setOnClickListener { - diagnosticsViewModel.messages.postValue("Processing Diagnostics...") + diagnosticsViewModel.messages.postValue("Processing diagnostics... Please wait.") + binding.progressBarHor.visibility = View.VISIBLE + incrementProgress() binding.btnSubmit.visibility = View.GONE runDeviceDiagnostics() val batteryLevel = "" //diagnosticsViewModel.getBatteryLevel().toString() @@ -219,8 +226,21 @@ class DiagnosticsFragment : Fragment() { } }) } + private fun loadDACValues() { + diagnosticsViewModel.progressBar.postValue(true) + (activity as DiagnosticsActivity).mService.sendAndListenToHemoCube( + HemoCubeCommands.LOAD_DAC_VALUES, + object : UsbServiceListener { + override fun onUsbRead(data: ByteArray?) { + } - private fun listenToHemoCube() { + override fun onUsbError(e: Exception?) { + diagnosticsViewModel.progressBar.postValue(false) + } + }) + } + + private fun listenToHemoCube() { diagnosticsViewModel.messages.postValue("Place cuvette filled with buffer\n and click on start") val fullReadOutput = StringBuilder() startListening.postValue(true) @@ -320,14 +340,25 @@ class DiagnosticsFragment : Fragment() { (resultData.contains("#DC") && this.testStatusCode < 1.4) -> { this.testStatusCode = 1.5 activity?.runOnUiThread { - readCurrentDACValuesCommand() + setProgress(96) + loadDACValues() } - } - (resultData.contains("#RC") && this.testStatusCode < 1.6) -> { + (resultData.contains("#EC") && this.testStatusCode < 1.6) -> { this.testStatusCode = 1.7 + activity?.runOnUiThread { + setProgress(98) + readCurrentDACValuesCommand() + } + } + (resultData.contains("#RC") && this.testStatusCode < 1.8) -> { + this.testStatusCode = 1.9 activity?.runOnUiThread { finalCalculation() + setProgress(100) + binding.progressBarHor.visibility = View.GONE + currentResultData += "\nIf you are facing any issues while using the device \n Contact us for help at support@sminnovations.in" + diagnosticsViewModel.messages.postValue(currentResultData) } } } @@ -456,4 +487,19 @@ class DiagnosticsFragment : Fragment() { private fun showToast(message: String) { Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() } + private fun setProgress(progress: Int) { + binding.progressBarHor.progress = progress + } + private fun incrementProgress() { + val handler = Handler() + handler.postDelayed(object : Runnable { + override fun run() { + if (currentProgress <= targetProgress) { + binding.progressBarHor.progress = currentProgress + currentProgress++ + handler.postDelayed(this, delayBetweenIncrements.toLong()) + } + } + }, delayBetweenIncrements.toLong()) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_diagnostics.xml b/app/src/main/res/layout/fragment_diagnostics.xml index 1c4beec..bf62ded 100644 --- a/app/src/main/res/layout/fragment_diagnostics.xml +++ b/app/src/main/res/layout/fragment_diagnostics.xml @@ -71,7 +71,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tv_subtitle3" /> - +