HemoCube new Changes
This commit is contained in:
@@ -84,7 +84,7 @@ class KitScanActivity : AppCompatActivity() {
|
||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
"Test" -> {
|
||||
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
DataHolder.deviceType.observe(this) { deviceType ->
|
||||
with(binding) {
|
||||
cvItem1.visibility =
|
||||
if (deviceType == Constants.DEVICE_TYPE_HOMOCUBE) View.VISIBLE else View.GONE
|
||||
cvItem2.visibility =
|
||||
if (deviceType == Constants.DEVICE_TYPE_TEST_RIGHT) View.VISIBLE else View.GONE
|
||||
cvItem3.visibility = View.VISIBLE
|
||||
cvItem4.visibility = View.VISIBLE
|
||||
if (deviceType == Constants.DEVICE_TYPE_HOMOCUBE) {
|
||||
binding.cvItem1.visibility = View.VISIBLE
|
||||
binding.cvItem3.visibility = View.VISIBLE
|
||||
binding.cvItem2.visibility = View.GONE
|
||||
binding.cvItem4.visibility = View.GONE
|
||||
}
|
||||
DataHolder.usbConnected.value = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,16 @@ package com.example.hpostesting.presentation.hemocube
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
@@ -19,7 +23,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private var resultRatio: String? = null
|
||||
private var kitSerial: String? = null
|
||||
private lateinit var binding: FragmentHemoCubeReferenceBinding
|
||||
private val viewModel: HemoCubeViewModel by viewModels()
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private var isOnline = false
|
||||
|
||||
@@ -37,7 +41,7 @@ class HemoCubeFragment : Fragment() {
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
|
||||
viewModel.fireBaseUpload.observe(viewLifecycleOwner) {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) {
|
||||
if (it == "Success") {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
@@ -48,7 +52,7 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
apply {
|
||||
kitSerial = DataHolder.SelectTestType?.kitSerial
|
||||
testTime = DataHolder.SelectTestType?.testTime
|
||||
@@ -63,9 +67,17 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Test Data uploaded",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Log.e("Testdb", "success")
|
||||
if (isOnline) {
|
||||
resultRatio?.let { ratio ->
|
||||
viewModel.uploadHemocubeResultToDatabase(
|
||||
Log.e("Testdb", "upload")
|
||||
hemoCubeViewModel.uploadHemocubeResultToDatabase(
|
||||
requireContext(),
|
||||
isOnline,
|
||||
true,
|
||||
@@ -77,7 +89,7 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
} else {
|
||||
resultRatio?.let { ratio ->
|
||||
viewModel.uploadHemocubeResultToDatabase(
|
||||
hemoCubeViewModel.uploadHemocubeResultToDatabase(
|
||||
requireContext(),
|
||||
isOnline,
|
||||
true,
|
||||
@@ -96,7 +108,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun fetchHemoCubeResult() {
|
||||
viewModel.progressBar.postValue(true)
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
val fullReadOutput = StringBuilder()
|
||||
(activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(object :
|
||||
UsbServiceListener {
|
||||
@@ -106,12 +118,12 @@ class HemoCubeFragment : Fragment() {
|
||||
fullReadOutput.append(stringData)
|
||||
binding.tvSubtitle4.text = fullReadOutput
|
||||
resultRatio = fullReadOutput.toString()
|
||||
viewModel.progressBar.postValue(false)
|
||||
hemoCubeViewModel.progressBar.postValue(false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
viewModel.progressBar.postValue(false)
|
||||
hemoCubeViewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.example.hpostesting.presentation.hemocube
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContentProviderCompat.requireContext
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -17,7 +20,7 @@ import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
@HiltViewModel
|
||||
class HemoCubeViewModel@Inject constructor(
|
||||
class HemoCubeViewModel @Inject constructor(
|
||||
private val hemoCubeDao: HemoCubeDao,
|
||||
private val repository: DatabaseRepository,
|
||||
context: Context
|
||||
@@ -25,7 +28,7 @@ class HemoCubeViewModel@Inject constructor(
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
val testDetails = DataHolder.SelectTestType
|
||||
val testDetailst = DataHolder.selectedTest
|
||||
val testDetailuser = DataHolder.selectedTest
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
val networkStatusLiveData: LiveData<Boolean>
|
||||
get() = _networkStatusLiveData
|
||||
@@ -42,6 +45,7 @@ class HemoCubeViewModel@Inject constructor(
|
||||
testDetails?.testStatus = testStatus
|
||||
if (isOnline) {
|
||||
try {
|
||||
Log.e("Testdb", "upload")
|
||||
addResultTestToDb()
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
@@ -54,7 +58,7 @@ class HemoCubeViewModel@Inject constructor(
|
||||
}
|
||||
private fun addResultTestToDb() {
|
||||
testDetails?.resultRatio = DataHolder.hemocubeResult
|
||||
testDetailst?.location = DataHolder.location
|
||||
testDetailuser?.location = DataHolder.location
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
@@ -64,6 +68,7 @@ class HemoCubeViewModel@Inject constructor(
|
||||
).format(Calendar.getInstance().time)
|
||||
when (repository.addTestToDatabase(testDetails)) {
|
||||
is Response.Success -> {
|
||||
Log.e("Testdb", "success")
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
else -> {}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
android:id="@+id/tv_subtitle4"
|
||||
style="@style/title2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:hint="Result"
|
||||
|
||||
Reference in New Issue
Block a user