refactoring hemocube fragment and add tests

This commit is contained in:
Pritimay Sarkar
2024-01-25 12:19:40 +05:30
4 changed files with 3 additions and 50 deletions

View File

@@ -76,24 +76,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 -> {
}
}
}
@@ -124,12 +119,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
}
@@ -146,15 +137,9 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
// 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://")
}
@@ -162,7 +147,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()
}
}
@@ -198,9 +182,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
// unregisterReceiver(downloadReceiver)
}
override fun onResume() {
super.onResume()

View File

@@ -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 -> {

View File

@@ -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()

View File

@@ -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" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_deviceInfo"