I want to show progress bar when I'm moving from the current page to previous page. so my scenario is like in the current page I'm downloading 20-25 images and while downloading the images want to move from the current page to the previous screen and show the progress bar in a RecyclerView and in the upper area of the page(till downloading completed).
So how Can I achieve it? I'm not getting like how we can show the progress from current page to previous page? Please help me out. Any help will be appreciated.
ImageDownload()
private fun downloadImage() {
GlobalScope.launch(dispatcherProvider.io()) {
for (angle in 0..340 step 20) {
dataHandler.MyRequestHandler.getImage(url.replace("340", "%03d".format(angle)), "%03d".format(angle)) { response: Response ->
if (response.body() != null && response.isSuccessful && response.networkResponse()!!.code() == 200) {
if (isDownload) {
activity.lifecycleScope.launch {
try {
isDownload = true
val imageByteArray = response.body()?.source()?.readByteArray()
imageEntity = viewModel.imageEntityConverter(ImageModels("xyz", number, "%03d".format(angle), "ownImage", imageByteArray))
viewModel.insertNumber(imageEntity)
activity.popSubPage()
activity.showSubPage(CarSelectionSite(activity), false)
} catch (e: Exception) {
Timber.e(e, "Failed to download image")
showErrorMessageDialog(R.string.failed, R.string.general_request_error)
}
}
}
} else if (response.networkResponse() != null && response.networkResponse()!!.code() == 404) {
showErrorMessageDialog(R.string.error_fin_not_found_title, R.string.error_fin_not_found_message)
return@getBBDCarImage
} else {
showErrorMessageDialog(R.string.failed, R.string.general_request_error)
return@getBBDCarImage
}
}
}
}
}
