Made some internal changes, pritimoi please check and remove unwanted code

This commit is contained in:
Kaif
2024-01-09 18:48:47 +05:30
parent 67559a292d
commit d12881f137
16 changed files with 133 additions and 60 deletions

View File

@@ -13,8 +13,8 @@ object Constants {
const val uid = "NKH5555AH"
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
const val deviceProvisionPassword = "f2ab0e7f9d69"
const val deviceID = "HCV-000-3001"
const val devicePassword = "810516d8f4c7"
const val DEVICE_ID_API = "deviceIDAPI"
const val DEVICE_PASSWORD_API = "devicePasswordAPI"
const val ACCESS_TOKEN = "accessToken"
const val NATS_TOKEN = "natsToken"
@@ -43,8 +43,8 @@ object Constants {
const val DEVICE_VENDOR_ID = 1027
const val HOMO_CUBE_ID = 29987
const val VENDOR_ID = 6790
const val HEMO_CUBE_V2_PRODUCT_ID = 24577
const val HEMO_CUBE_V2_VENDOR_ID = 1027
const val HEMO_CUBE_V2_PRODUCT_ID = 60000
const val HEMO_CUBE_V2_VENDOR_ID = 4292
const val ERROR_NORMAL = 400
const val ERROR_CRITICAL = 401
@@ -54,6 +54,7 @@ object Constants {
const val USER_ID = "usernameId"
val STATICID = listOf(
"FACTORY",
"ADMIN",
"VIZ-1000-0004",
"VIZ-1000-0005",
@@ -97,7 +98,8 @@ object Constants {
"HCV-000-3017",
"HCV-000-3018",
"HCV-000-3019",
"HCV-000-3020"
"HCV-000-3020",
"HPP1-1024-0001"
)
const val password = "SMI@12345"
@@ -149,7 +151,7 @@ object Constants {
listOf(0.2012, 0.0092), // LED3, 555nm
listOf(1.0, 0.0) // LED4, 560nm
),
"HCV-000-3002" to listOf(
"HPP1-0124-0001" to listOf(
listOf(0.723142, -0.09135), // LED1, 435nm
listOf(0.581462456, -0.58502), // LED2, 415nm
listOf(0.1964, 0.011565), // LED3, 555nm
@@ -158,7 +160,7 @@ object Constants {
)
val DEVICE_HB_PARAMETERS: Map<String, List<List<Double>>> = mapOf<String, List<List<Double>>>(
"HCV-000-3001" to listOf(
"HPP1-0124-0001" to listOf(
listOf(1.0, 0.0), // LED1, 435nm
listOf(1.0, 0.0), // LED2, 415nm
listOf(42.241, -24.105), // LED3, 555nm
@@ -288,7 +290,7 @@ object Constants {
const val MINIMUM_BATTERY_LEVEL = 0
val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>(
"HCV-000-3001" to listOf(
"HPP1-0124-0001" to listOf(
listOf(20000, 25074),
listOf(20000, 24596),
listOf(20000, 26065),

View File

@@ -8,5 +8,6 @@ data class LoginRequest(
val mode: String? = "",
val password: String? = "",
val serialNumber: String? = "",
val username: String? = ""
val username: String? = "",
val version: String? = ""
)

View File

@@ -15,10 +15,10 @@ class CheckUpdateWorker(
override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
try {
for (i in 1..900){
delay(1000)
Log.d("Work for every second", "doWork: Running")
}
// for (i in 1..900){
// delay(1000)
// Log.d("Work for every second", "doWork: Running")
// }
Result.success()
} catch (e: Exception) {

View File

@@ -116,7 +116,7 @@ object AppModule {
@Provides
@Singleton
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
return context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
return context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
}
@Provides

View File

@@ -24,7 +24,7 @@ class NatsManager(datacollector: DashboardActivity) {
Log.d(TAG, "TRY TO CONNECT")
Thread {
val seedString = "SUAK5IDCMHY4T2WA2LHNXGICGHKR3TPJFNSP6AUQP523RLANO4PSR6IEYA"
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
val seedBytes = seedString.toCharArray()
val theNKey = NKey.fromSeed(seedBytes) // really should load from somewhere

View File

@@ -61,7 +61,7 @@ class OfflineUserListAdapter(private val view: View, private val batLevel: Int)
bloodGroup.text = "Blood group: ${userList.bloodGroup}"
time.text = "Time: ${userList.incubationTime}"
userCard.setOnClickListener {
if (batLevel < 40) {
if (false) {
Toast.makeText(
view.context,
context?.getString(R.string.low_battery_warning),

View File

@@ -49,8 +49,8 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
setContentView(binding.root)
setSupportActionBar(binding.appBarDashboard.toolbar)
nats = NatsManager(this)
// nats.connect()
// nats.pub("server.hpos.HCV-000-3001.ping", "THIS IS A TEST MSG")
nats.connect()
nats.pub("server.hpos.HCV-000-3001.ping", "THIS IS A TEST MSG")
val drawerLayout: DrawerLayout = binding.drawerLayout
val navView: NavigationView = binding.navView

View File

@@ -1,15 +1,20 @@
package com.example.hpostesting.presentation.dashboard
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.presentation.autodac.AutoDacActivity
import com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity
import com.example.hpostesting.presentation.calibration.CalibrationActivity
import com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding
class GalleryFragment : Fragment() {
@@ -20,10 +25,12 @@ class GalleryFragment : Fragment() {
// onDestroyView.
private val binding get() = _binding!!
private lateinit var sharedPreference: SharedPreferences
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
// val galleryViewModel =
// ViewModelProvider(this).get(GalleryViewModel::class.java)
@@ -31,6 +38,23 @@ class GalleryFragment : Fragment() {
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
val root: View = binding.root
sharedPreference = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
if (sharedPreference.getString(
Constants.USER_ID, ""
) == "FACTORY" && sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
.isEmpty() && sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "")
.toString().isEmpty()
) {
binding.btnDeviceProvision.visibility = View.VISIBLE
} else {
binding.btnDeviceProvision.visibility = View.GONE
}
binding.btnDeviceProvision.setOnClickListener {
// hemoCubeViewModel.deviceProvision()
}
binding.btnSubmit.setOnClickListener {
startActivity(Intent(requireContext(), HemocubeBufferCheckActivity::class.java))
}

View File

@@ -24,6 +24,7 @@ import com.example.hpostesting.data.model.login.LoginResponse
import com.example.hpostesting.data.model.patient.HemoCubeTestData
import com.example.hpostesting.data.model.patient.UserData
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
import com.example.hpostesting.presentation.KitScanActivity
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
import com.example.hpostesting.presentation.adapter.UserListAdapter
@@ -69,8 +70,7 @@ class HomeFragment : Fragment() {
return super.onCreateView(inflater, container, savedInstanceState)
}
sharedPreference =
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
sharedPreference = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
DataHolder.selectedTest = null
return binding.root
@@ -130,41 +130,55 @@ class HomeFragment : Fragment() {
showUploadDialog(requireContext())
}
binding.btnNewKit.setOnClickListener {
with(sharedPreference.edit()) {
putString(Constants.KIT_NUMBER, "")
putInt(Constants.KIT_COUNT, 0)
apply()
}
startActivity(Intent(requireContext(), KitScanActivity::class.java))
requireActivity().finish()
// with(sharedPreference.edit()) {
// putString(Constants.KIT_NUMBER, "")
// putInt(Constants.KIT_COUNT, 0)
// apply()
// }
// startActivity(Intent(requireContext(), KitScanActivity::class.java))
// requireActivity().finish()
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "810516d8f4c7").toString()
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "HCV-000-3001").toString()
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
hemoCubeViewModel.login(createLoginRequestData(userID, password))
}
}
private fun checkForTokenAndUpdate() {
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
val natsToken = sharedPreference.getString(Constants.NATS_TOKEN, "").toString()
val natsTokenExpireDate = sharedPreference.getString(Constants.NATS_TOKEN_EXPIRE_DATE, "").toString()
if (accessToken.isEmpty() && natsToken.isEmpty()) {
hemoCubeViewModel.login(createLoginRequestData())
} else {
if (isTokenExpired(accessToken)) {
hemoCubeViewModel.login(createLoginRequestData())
val natsTokenExpireDate =
sharedPreference.getString(Constants.NATS_TOKEN_EXPIRE_DATE, "").toString()
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "810516d8f4c7").toString()
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "HCV-000-3001").toString()
if (userID.isNotEmpty() && password.isNotEmpty()) {
if (accessToken.isEmpty() && natsToken.isEmpty()) {
hemoCubeViewModel.login(createLoginRequestData(userID, password))
} else {
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
hemoCubeViewModel.uploadLogs()
hemoCubeViewModel.startPeriodicCheckUpdate()
if (true) {
hemoCubeViewModel.login(createLoginRequestData(userID, password))
} else {
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
hemoCubeViewModel.uploadLogs()
hemoCubeViewModel.startPeriodicCheckUpdate()
}
}
} else {
Toast.makeText(
requireContext(),
"Contact Help and get your device provision done",
Toast.LENGTH_SHORT
).show()
}
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
when (response) {
is Result.Success -> {
updateTokens(response)
checkForTokenAndUpdate()
}
is Result.Error -> {
response.exception.let { message ->
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
Toast.makeText(activity, "An error occurred in login: $message", Toast.LENGTH_LONG)
.show()
}
}
@@ -177,17 +191,17 @@ class HomeFragment : Fragment() {
}
}
hemoCubeViewModel.checkUpdate.observe(viewLifecycleOwner) { response ->
hemoCubeViewModel.deviceUpdate.observe(viewLifecycleOwner) { response ->
when (response) {
is Result.Success -> {
Toast.makeText(
requireContext(), response.data.data?.version, Toast.LENGTH_SHORT
requireContext(), response.data.toString(), Toast.LENGTH_SHORT
).show()
}
is Result.Error -> {
response.exception.let { message ->
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
Toast.makeText(activity, "An error occurred check update: $message", Toast.LENGTH_LONG)
.show()
}
}
@@ -212,7 +226,7 @@ class HomeFragment : Fragment() {
is Result.Error -> {
response.exception.let { message ->
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
Toast.makeText(activity, "An error occurred in uploading logs: $message", Toast.LENGTH_LONG)
.show()
}
}
@@ -241,16 +255,24 @@ class HomeFragment : Fragment() {
with(sharedPreference.edit()) {
putString(Constants.ACCESS_TOKEN, response.data.data?.accessToken)
putString(Constants.NATS_TOKEN, response.data.data?.deviceUser?.natsToken)
putString(Constants.NATS_TOKEN_EXPIRE_DATE, response.data.data?.deviceUser?.natsTokenExpiry)
putString(
Constants.NATS_TOKEN_EXPIRE_DATE,
response.data.data?.deviceUser?.natsTokenExpiry
)
apply()
}
}
private fun createLoginRequestData(): LoginRequest {
private fun createLoginRequestData(userID: String, password: String): LoginRequest {
val pInfo = requireActivity().packageManager.getPackageInfo(
requireActivity().packageName, 0
)
val version = pInfo.versionName
return LoginRequest(
password = Constants.devicePassword,
serialNumber = Constants.deviceID,
username = Constants.deviceID
password = password,
serialNumber = userID,
username = userID,
version = version
)
}
@@ -264,6 +286,12 @@ class HomeFragment : Fragment() {
)
}
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
return DeviceUpdateRequest(
serial_no = "HPOS-000-3001"
)
}
private fun setUserId() {
binding.btnSubmit.setOnClickListener {
val userId = binding.userId.text.toString()
@@ -448,9 +476,9 @@ class HomeFragment : Fragment() {
binding.uploadData.visibility = uploadDataVisibility
}
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) {bufferData ->
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { bufferData ->
val uploadDataVisibility =
if (bufferData.any { !it.localFlag}) View.VISIBLE else View.GONE
if (bufferData.any { !it.localFlag }) View.VISIBLE else View.GONE
binding.uploadData.visibility = uploadDataVisibility
}
}

View File

@@ -24,7 +24,7 @@ class LoginFragment : Fragment() {
): View {
_binding = FragmentLoginBinding.inflate(inflater, container, false)
sharedPreference =
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
return binding.root
}

View File

@@ -396,17 +396,21 @@ class HemoCubeFragment : Fragment() {
when {
resultData.contains("SNE") && this.testStatusCode < Constants.TEST_STATUS_CODE_CONFIG_COMPLETED -> {
val pattern = Regex("HCV-\\d{3}-\\d{4}")
val pattern = Regex("HPP1-\\d{4}-\\d{4}")
val matchResult = pattern.find(resultData)
val hardwareId = matchResult?.value
if (hardwareId.toString().length == 12) {
if (hardwareId.toString().length == 14) {
deviceHardwareId += hardwareId
with(sharedPreferences.edit()) {
putString(Constants.DEVICE_ID, deviceHardwareId)
apply()
}
this.testStatusCode = Constants.TEST_STATUS_CODE_CONFIG_COMPLETED
activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.VISIBLE
}
hemoCubeViewModel.messages.postValue(getString(R.string.start))
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
allErrorMessages += "Calibration configuration for this device id is not found"
@@ -419,10 +423,6 @@ class HemoCubeFragment : Fragment() {
} else {
hemoCubeViewModel.messages.postValue("Config error")
}
activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.VISIBLE
}
hemoCubeViewModel.messages.postValue(getString(R.string.start))
}
resultData.contains("#BS") && this.testStatusCode < Constants.TEST_STATUS_CODE_BUFFER_STARTED -> {

View File

@@ -16,7 +16,6 @@
android:text="@string/check_buffer"
android:textColor="@color/white"
app:cornerRadius="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -64,4 +63,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_auto_dac" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_deviceProvision"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="24dp"
android:clickable="false"
android:text="@string/deviceProvision"
android:textColor="@color/white"
app:cornerRadius="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_calibration" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -113,6 +113,7 @@
<string name="auto_dac">Auto DAC</string>
<string name="assurance_controls">Quality Assurance</string>
<string name="calibration">Calibration</string>
<string name="deviceProvision">Device Provision</string>
<string name="place_buffer">स्थान</string>
<string name="Start_Sample">सैम्पल शुरू करें</string>
<string name="new_kit">नया किट</string>

View File

@@ -113,6 +113,7 @@
<string name="auto_dac">Auto DAC</string>
<string name="assurance_controls">Quality Controls</string>
<string name="calibration">Calibration</string>
<string name="deviceProvision">Device Provision</string>
<string name="place_buffer">ಪ್ರಾರಂಭಿಸಿ</string>
<string name="Start_Sample">ನಮೂನೆ ಪ್ರಾರಂಭಿಸಿ</string>
<string name="new_kit">ಹೊಸ ಕಿಟ್</string>

View File

@@ -114,6 +114,7 @@
<string name="auto_dac">Auto DAC</string>
<string name="assurance_controls">Quality Assurance</string>
<string name="calibration">Calibration</string>
<string name="deviceProvision">Device Provision</string>
<string name="place_buffer">Start</string>
<string name="Start_Sample">Start Sample</string>
<string name="new_kit">New Kit</string>

View File

@@ -11,6 +11,7 @@
<!-- <usb-device vendor-id="1027" product-id="24596" /> &lt;!&ndash; 0x6014: FT232H &ndash;&gt;-->
<usb-device vendor-id="1027" product-id="24577" /> <!-- 0x6015: FT230X, FT231X, FT234XD -->
<usb-device vendor-id="6790" product-id="29987" /> <!-- 0x6015: FT230X, FT231X, FT234XD -->
<usb-device vendor-id="4292" product-id="60000" /> <!-- 0x6015: FT230X, FT231X, FT234XD -->
<!-- 0x10C4 / 0xEA??: Silabs CP210x -->
<!-- <usb-device vendor-id="4292" product-id="60000" /> &lt;!&ndash; 0xea60: CP2102 and other CP210x single port devices &ndash;&gt;-->