diff --git a/app/build.gradle b/app/build.gradle index a1fb725..3dfb317 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { applicationId "in.sminnovations.hpostesting.quality" minSdk 21 targetSdk 34 - versionCode 99 - versionName "2.1.99" + versionCode 100 + versionName "2.1.100" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt index bfbbb99..5827dea 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt @@ -253,7 +253,11 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate { //I'm doing mScannerInfoList.get(0) because there's only one scanner which will be at position 0. //I'm doing mScannerInfoList.get(0) because there's only one scanner which will be at position 0. - sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID) + if (mScannerInfoList.isNotEmpty()) { + sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID) + } else { + Toast.makeText(this, "No scanner is Available", Toast.LENGTH_LONG).show() + } } fun pullTrigger() { diff --git a/app/src/main/java/com/example/hpostesting/presentation/NatsManager.kt b/app/src/main/java/com/example/hpostesting/presentation/NatsManager.kt index 4c8f3dc..f45b0db 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/NatsManager.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/NatsManager.kt @@ -23,7 +23,6 @@ class NatsManager(datacollector: DashboardActivity) { fun connect() { Log.d(TAG, "TRY TO CONNECT") Thread { - val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4" val seedBytes = seedString.toCharArray() 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 97d6094..5fe81d4 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 @@ -118,6 +118,8 @@ class HomeFragment : Fragment() { loadUserData() setSearch() checkForLocalDBData() + // This function could be called directly where you need to perform the login operation. + forceLogin() checkForTokenAndUpdate() } else { binding.internetAvailableCL.visibility = View.GONE @@ -188,12 +190,31 @@ class HomeFragment : Fragment() { } } + + + private fun forceLogin() { + val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString() + val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString() + if (userID.isNotEmpty() && password.isNotEmpty() ) { + // Directly call the login API without checking the access token + hemoCubeViewModel.login(createLoginRequestData(userID, password)) + } else { + Toast.makeText( + requireContext(), + "Contact Help and get your device provision done", + Toast.LENGTH_SHORT + ).show() + } + + } + + + private fun checkForTokenAndUpdate() { val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString() val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString() val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString() - if (userID.isNotEmpty() && password.isNotEmpty()) { - if (accessToken.isEmpty()) { + if (accessToken.isEmpty()) { hemoCubeViewModel.login(createLoginRequestData(userID, password)) } else { if (isTokenExpired(accessToken)) { @@ -205,13 +226,6 @@ class HomeFragment : Fragment() { 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 -> { diff --git a/app/src/main/java/com/example/hpostesting/presentation/deviceprovision/DeviceProvisionFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/deviceprovision/DeviceProvisionFragment.kt index 5ebc428..96caede 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/deviceprovision/DeviceProvisionFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/deviceprovision/DeviceProvisionFragment.kt @@ -146,14 +146,40 @@ class DeviceProvisionFragment : Fragment() { } } +// private fun handleUsbData() { +// when { +// resultData.contains("SNE") -> { +// val pattern = Regex("HPP1-\\d{4}") +// val matchResult = pattern.find(resultData) +// val hardwareId = matchResult?.value +// +// if (hardwareId.toString().length == 9) { +// with(sharedPreferences.edit()) { +// putString(Constants.DEVICE_ID, hardwareId) +// apply() +// } +// activity?.runOnUiThread { +// binding.btnSubmit.visibility = View.VISIBLE +// } +// } +// } +// } +// } + + private fun handleUsbData() { when { resultData.contains("SNE") -> { - val pattern = Regex("HPP1-\\d{4}") + // Updated pattern to match all specified formats + val pattern = Regex("HPP1-\\d{4}|HPP1-\\d{3}-\\d{4}|HCV-\\d{3}-\\d{4}") val matchResult = pattern.find(resultData) val hardwareId = matchResult?.value - if (hardwareId.toString().length == 9) { + // Assuming hardwareId validation is based on matching the pattern, + // so no need to check length explicitly here. + // If there are more specific requirements for validation, + // they need to be implemented accordingly. + if (hardwareId != null) { // Check if hardwareId is not null instead with(sharedPreferences.edit()) { putString(Constants.DEVICE_ID, hardwareId) apply() @@ -165,4 +191,5 @@ class DeviceProvisionFragment : Fragment() { } } } + } \ No newline at end of file