From bce12a4fca034a75d913c50e675e6c22c9a5a1dc Mon Sep 17 00:00:00 2001 From: Mariya Date: Tue, 23 Jan 2024 18:12:05 +0530 Subject: [PATCH] changes added when testing in device provision- and removed unwanted codes --- .../dashboard/DashboardActivity.kt | 21 -------------- .../presentation/dashboard/HomeFragment.kt | 28 ------------------- .../DeviceProvisionFragment.kt | 4 +-- app/src/main/res/layout/fragment_gallery.xml | 2 +- 4 files changed, 3 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt index 331bd23..b65adad 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt @@ -82,24 +82,19 @@ class DashboardActivity : AppCompatActivity(), IDataCollector { "APK UPLOAD ${result.data}", Toast.LENGTH_SHORT ).show() - // The APK URL LiveData will be updated automatically } is Result.Error -> { result.exception.let { message -> Toast.makeText(this, "An error occurred On Updating App: $message", Toast.LENGTH_LONG) .show() - } - } is Result.Loading -> { - } else -> { - } } } @@ -130,12 +125,8 @@ class DashboardActivity : AppCompatActivity(), IDataCollector { } private fun initiateUpdate(responseBody: String) { - // Extract the URL from the ResponseBody val apkUrl = responseBody - - // Check if the extracted APK URL is valid if (!isValidHttpUrl(apkUrl)) { - // Handle the case where the URL is not valid return } @@ -147,20 +138,12 @@ class DashboardActivity : AppCompatActivity(), IDataCollector { val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager downloadId = downloadManager.enqueue(request) - - // Register a BroadcastReceiver to receive the download complete event val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) registerReceiver(downloadReceiver, filter) } - - // Function to check if a URL has a valid HTTP/HTTPS scheme - // Function to extract the APK URL from the ResponseBody private fun extractApkUrl(responseBody: ResponseBody): String { - // Assuming your ResponseBody contains the APK URL as a string return responseBody.string() } - - // Function to check if a URL has a valid HTTP/HTTPS scheme private fun isValidHttpUrl(url: String): Boolean { return url.startsWith("http://") || url.startsWith("https://") } @@ -168,7 +151,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector { override fun onReceive(context: Context?, intent: Intent?) { val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) if (id == downloadId) { - // Install the downloaded APK installApk() } } @@ -204,9 +186,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector { unregisterReceiver(downloadReceiver) } - - - override fun onResume() { super.onResume() 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 695aff0..97d6094 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 @@ -237,34 +237,6 @@ class HomeFragment : Fragment() { } } - hemoCubeViewModel.deviceUpdate.observe(viewLifecycleOwner) { response -> - when (response) { - is Result.Success -> { - Toast.makeText( - requireContext(), response.data.toString(), Toast.LENGTH_SHORT - ).show() - - } - - is Result.Error -> { - response.exception.let { message -> - Toast.makeText( - activity, - "An error occurred check update: $message", - Toast.LENGTH_LONG - ) - .show() - } - } - - is Result.Loading -> { - - } - - else -> {} - } - } - hemoCubeViewModel.uploadLogs.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 bf71402..5ebc428 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 @@ -149,11 +149,11 @@ class DeviceProvisionFragment : Fragment() { private fun handleUsbData() { when { resultData.contains("SNE") -> { - val pattern = Regex("HCV-\\d{3}-\\d{4}") + val pattern = Regex("HPP1-\\d{4}") val matchResult = pattern.find(resultData) val hardwareId = matchResult?.value - if (hardwareId.toString().length == 12) { + if (hardwareId.toString().length == 9) { with(sharedPreferences.edit()) { putString(Constants.DEVICE_ID, hardwareId) apply() diff --git a/app/src/main/res/layout/fragment_gallery.xml b/app/src/main/res/layout/fragment_gallery.xml index 3612d5c..fd82fc3 100644 --- a/app/src/main/res/layout/fragment_gallery.xml +++ b/app/src/main/res/layout/fragment_gallery.xml @@ -92,7 +92,7 @@ app:cornerRadius="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/btn_calibration" /> + app:layout_constraintTop_toBottomOf="@id/btn_deviceInfo" />