Apk Update Code Added
This commit is contained in:
@@ -146,7 +146,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
}
|
||||
|
||||
private fun downloadApk(responseBody: ResponseBody) {
|
||||
val file = File(getExternalFilesDir(null), "update.apk")
|
||||
val file = File(getExternalFilesDir(null), "Update.apk")
|
||||
var inputStream: InputStream? = null
|
||||
var outputStream: FileOutputStream? = null
|
||||
try {
|
||||
@@ -245,9 +245,9 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
|
||||
responses = responses+response+"\n"
|
||||
println(responses)
|
||||
if (response.contains("checkUpdate")) {
|
||||
hemocubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
}
|
||||
// if (response.contains("checkUpdate")) {
|
||||
// hemocubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
// }
|
||||
}
|
||||
|
||||
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
||||
|
||||
@@ -253,11 +253,11 @@ class HomeFragment : Fragment() {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
isTokenAvailable = true
|
||||
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.downloadClientCertificate()
|
||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||
|
||||
}
|
||||
}
|
||||
} else if (deviceId.isNotEmpty()) {
|
||||
@@ -271,9 +271,9 @@ class HomeFragment : Fragment() {
|
||||
} else {
|
||||
// Continue with your existing logic if the token is not empty.
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
@@ -337,6 +337,40 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.checkUpdate.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
// Handle success
|
||||
val apkUrl = response.data
|
||||
Log.e("ApI", "APK URL: $apkUrl")
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
Toast.makeText(
|
||||
activity,
|
||||
" ${response.data}",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred in uploading logs: $message",
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Loading -> {
|
||||
}
|
||||
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.downloadcertificate.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-files-path name="Updates" path="." />
|
||||
<external-files-path name="Update" path="." />
|
||||
</paths>
|
||||
|
||||
Reference in New Issue
Block a user