Good time of the day.
I'm trying to make application which is supposed to upload files to server and display progress of uploading in ProgressDialog
.
This is the code i have so far:
Create ProgressDialog
for Uploading Procedure
private void createUploadingDialog(int filesCount) {
uploadingDialog = new ProgressDialog(getActivity());
uploadingDialog.setIndeterminate(true);
loadingDialog.setMessage(getString(R.string.upload_progress, 0, filesCount));
loadingDialog.show();
}
Dismiss ProgressDialog
for Uploading Procedure
private void dismissUploadingDialog() {
if (uploadingDialog.isShowing())
uploadingDialog.dismiss();
}
Update ProgressDialog
for Uploading Procedure
private void updateUploadingDialog(final String dialogMessage) {
class UpdateDialog implements Runnable {
private String messageString;
private UpdateDialog(String ms) { messageString = ms; }
public void run() {
uploadingDialog.setMessage(messageString);
}
}
getActivity().runOnUiThread(new UpdateDialog(dialogMessage));
}
Call to create dialog
createUploadingDialog(imagesPathsArray.size());
Call to dismiss dialog
dismissUploadingDialog();
Call to update dialog onSuccess
updateUploadingDialog(getString(R.string.upload_progress, i, imagesPathsArray.size()));
Call to update dialog onFailure
updateUploadingDialog(getString(R.string.retrying_request));
The dialog is displayed in fragment. To send images to server i'm using Retrofit2.
When i do initial setup of dialog, message get set correctly (showing total files and current one), however, message is not updating when the update call is made. For some reason, no error is thrown and if i'm adding Log.d
, it even shows that method was called.
Thank you for any help!