device Diagnostics updated the screen with progress bar
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle3" />
|
||||
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarHor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:visibility="gone"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4"/>
|
||||
<Button
|
||||
android:id="@+id/btn_submit"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user