Updated error message from string to object with message and code.
This commit is contained in:
@@ -4,7 +4,9 @@ import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpos.data.model.TestRightDeviceConstants
|
||||
|
||||
object DataHolder {
|
||||
// var usbConnected: Boolean = false
|
||||
|
||||
|
||||
// var usbConnected: Boolean = false
|
||||
// val usbConnected = MutableLiveData(false)
|
||||
val usbConnected = MutableLiveData(true)
|
||||
|
||||
@@ -15,6 +17,7 @@ object DataHolder {
|
||||
var sampleReadCounter = 0
|
||||
|
||||
var deviceConstant: TestRightDeviceConstants? = null
|
||||
var deviceSerialNumber: String = "ABCD"
|
||||
|
||||
/* Contains wavelength -> pixel no.*/
|
||||
val wavelengthToPixelArray = ArrayList<Double>()
|
||||
|
||||
19
app/src/main/java/com/example/hpos/data/PreferenceUtility.kt
Normal file
19
app/src/main/java/com/example/hpos/data/PreferenceUtility.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.example.hpos.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
object PreferenceUtility {
|
||||
|
||||
private const val PREFS_NAME = "keys_prefs"
|
||||
private const val KEY_COUNTER = "counter"
|
||||
|
||||
fun generateId(context: Context, prefix: String): String {
|
||||
val prefs: SharedPreferences =
|
||||
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val counter = prefs.getInt(KEY_COUNTER, 100)
|
||||
prefs.edit().putInt(KEY_COUNTER, counter + 1).apply()
|
||||
return prefix + counter
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,4 +21,7 @@ object Constants {
|
||||
|
||||
const val DEVICE_PRODUCT_ID = 24597
|
||||
const val DEVICE_VENDOR_ID = 1027
|
||||
|
||||
const val ERROR_NORMAL = 400
|
||||
const val ERROR_CRITICAL = 401
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.hpos.data.model
|
||||
|
||||
data class ErrorMessage (
|
||||
val message: String,
|
||||
val code: Int
|
||||
)
|
||||
@@ -119,7 +119,7 @@ class TestRightActivity : AppCompatActivity() {
|
||||
onBackPressed()
|
||||
return
|
||||
}
|
||||
|
||||
DataHolder.deviceSerialNumber = mDriver.device.serialNumber.toString()
|
||||
mConnection = manager.openDevice(mDriver.device)
|
||||
|
||||
if (mConnection == null) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.constant.TestRightCommands
|
||||
import com.example.hpos.data.model.ErrorMessage
|
||||
import com.example.hpos.databinding.FragmentTestRightExpReferenceBinding
|
||||
import com.example.hpos.presentation.UsbServiceListener
|
||||
import com.example.hpos.presentation.utils.MyDialogListener
|
||||
@@ -75,8 +76,11 @@ class TestRightExpReference : Fragment() {
|
||||
}
|
||||
|
||||
viewModel.errorTriggered.observe(viewLifecycleOwner) {
|
||||
if (!it.isNullOrEmpty()){
|
||||
UIUtils.onShowErrorToast(requireContext(), it)
|
||||
if (it != null){
|
||||
UIUtils.onShowErrorToast(requireContext(), it.message)
|
||||
if (it.code == Constants.ERROR_CRITICAL){
|
||||
activity?.onBackPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +126,7 @@ class TestRightExpReference : Fragment() {
|
||||
val stringData = String(it)
|
||||
fullReadOutput.append(stringData)
|
||||
Log.d(TAG, "fullReadOutput = $fullReadOutput")
|
||||
|
||||
if (stringData.contains("OK", true)) {
|
||||
Log.d(
|
||||
TAG,
|
||||
@@ -133,14 +138,16 @@ class TestRightExpReference : Fragment() {
|
||||
Log.d(TAG, "results = FINE")
|
||||
viewModel.progressBar.postValue(false)
|
||||
|
||||
viewModel.errorTriggered.postValue("Please Try Again this step")
|
||||
viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again!!", Constants.ERROR_CRITICAL))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
Log.e(TAG, "onUsbIoError() called in sendCmdToFetchDeviceConstant() -> $e")
|
||||
viewModel.errorTriggered.postValue("Please Try Again this step")
|
||||
viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL))
|
||||
|
||||
viewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
@@ -278,7 +285,8 @@ class TestRightExpReference : Fragment() {
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
Log.e(TAG, "onUsbIoError() called in sendCmdToFetchLightIntensities() -> $e")
|
||||
viewModel.errorTriggered.postValue("Please Try Again this step")
|
||||
viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL))
|
||||
|
||||
viewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -61,8 +61,8 @@ class TestRightExpSample : Fragment() {
|
||||
}
|
||||
|
||||
viewModel.errorTriggered.observe(viewLifecycleOwner) {
|
||||
if (!it.isNullOrEmpty()){
|
||||
UIUtils.onShowErrorToast(requireContext(), it)
|
||||
if (it != null){
|
||||
UIUtils.onShowErrorToast(requireContext(), it.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.PreferenceUtility
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import com.example.hpos.databinding.FragmentTestRightResultsBinding
|
||||
@@ -107,8 +108,14 @@ class TestRightResults : Fragment() {
|
||||
private fun saveCsv() {
|
||||
Log.d(TAG, "saveCsv() called")
|
||||
|
||||
val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
||||
val fileName: String = sdfDate.format(Date()) + ".csv"
|
||||
// val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
||||
// val fileName: String = sdfDate.format(Date()) + ".csv"
|
||||
|
||||
val prefix = "HPOSSC_${DataHolder.deviceSerialNumber}_"
|
||||
val fileExtension = ".csv"
|
||||
|
||||
val fileName = PreferenceUtility.generateId(requireContext(), prefix) + fileExtension
|
||||
|
||||
|
||||
viewModel.saveCsv(requireContext().applicationContext, fileName)
|
||||
viewModel.saveCsvForTesting(requireContext().applicationContext, "testing$fileName")
|
||||
|
||||
@@ -6,10 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.CalculationVariableForTest
|
||||
import com.example.hpos.data.model.PatientData
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightDeviceConstants
|
||||
import com.example.hpos.data.model.*
|
||||
import com.example.hpos.domain.ResultCalculationWithMaxImpl
|
||||
import com.example.hpos.domain.SaveRawData
|
||||
import com.example.hpos.domain.SaveRawDataTest
|
||||
@@ -28,7 +25,8 @@ class TestRightViewModel : ViewModel() {
|
||||
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
val errorTriggered = MutableLiveData<String>("")
|
||||
// val errorTriggered = MutableLiveData<String>("")
|
||||
val errorTriggered = MutableLiveData<ErrorMessage>()
|
||||
|
||||
lateinit var patientDetails: PatientData
|
||||
|
||||
@@ -59,12 +57,12 @@ class TestRightViewModel : ViewModel() {
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 201: In processing the data from device"
|
||||
errorTriggered.postValue("Error 201: In processing the data from device")
|
||||
errorTriggered.postValue(ErrorMessage("Error 201: In processing the data from device", Constants.ERROR_NORMAL))
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error (showing error if empty by using a mutable error string)
|
||||
// "Error 202: Unable to fetch data from device."
|
||||
errorTriggered.postValue("Error 202: Unable to fetch data from device.")
|
||||
errorTriggered.postValue(ErrorMessage("Error 202: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -88,7 +86,8 @@ class TestRightViewModel : ViewModel() {
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 203: Unable to fetch data from device."
|
||||
errorTriggered.postValue("Error 203: Unable to fetch data from device.")
|
||||
errorTriggered.postValue(ErrorMessage("Error 203: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -114,7 +113,8 @@ class TestRightViewModel : ViewModel() {
|
||||
intensitySampleArray.add(numbers[1].toDouble())
|
||||
} else {
|
||||
// "Error 204: Unable to fetch data from device."
|
||||
errorTriggered.postValue("Error 204: Unable to fetch data from device.")
|
||||
errorTriggered.postValue(ErrorMessage("Error 204: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,8 @@ class TestRightViewModel : ViewModel() {
|
||||
|
||||
fun mapWavelengthToAbsorbance() {
|
||||
if (DataHolder.intensityReferenceArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != DataHolder.intensityReferenceArray.size) {
|
||||
errorTriggered.postValue("Error 205: Unable to fetch data from device, please try again by reopening the app")
|
||||
errorTriggered.postValue(ErrorMessage("Error 205: Unable to fetch data from device, please try again by reopening the app", Constants.ERROR_NORMAL))
|
||||
|
||||
throw Exception("Inconsistency in the data, size of arrays are not same. \nintensityReferenceArray.size = ${DataHolder.intensityReferenceArray.size} ; intensitySampleArray.size = ${intensitySampleArray.size} ; wavelengthToPixelArray.size = ${DataHolder.wavelengthToPixelArray.size}")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user