Skip to content

Commit

Permalink
Dialogs should be displayed again after activity recreation if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jan 15, 2019
1 parent b55f18e commit f33ec84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Expand Up @@ -211,6 +211,7 @@ public void onClick(View v) {
refreshButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewModel.setLoadingCanceled(false);
viewModel.clearFormList();
updateAdapter();
clearChoices();
Expand All @@ -233,6 +234,7 @@ public void onClick(View v) {
if (downloadFormListTask.getStatus() == AsyncTask.Status.FINISHED) {
try {
progressDialog.dismiss();
viewModel.setProgressDialogShowing(false);
} catch (IllegalArgumentException e) {
Timber.i("Attempting to close a dialog that was not previously opened");
}
Expand All @@ -243,12 +245,15 @@ public void onClick(View v) {
if (downloadFormsTask.getStatus() == AsyncTask.Status.FINISHED) {
try {
progressDialog.dismiss();
viewModel.setProgressDialogShowing(false);
} catch (IllegalArgumentException e) {
Timber.i("Attempting to close a dialog that was not previously opened");
}
downloadFormsTask = null;
}
} else if (viewModel.getFormNamesAndURLs().isEmpty() && getLastCustomNonConfigurationInstance() == null) {
} else if (viewModel.getFormNamesAndURLs().isEmpty()
&& getLastCustomNonConfigurationInstance() == null
&& !viewModel.wasLoadingCanceled()) {
// first time, so get the formlist
downloadFormList();
}
Expand Down Expand Up @@ -464,6 +469,12 @@ protected void onResume() {
if (viewModel.isAlertShowing()) {
createAlertDialog(viewModel.getAlertTitle(), viewModel.getAlertMsg(), viewModel.shouldExit());
}
if (viewModel.isProgressDialogShowing() && (progressDialog == null || !progressDialog.isShowing())) {
createProgressDialog();
}
if (viewModel.isCancelDialogShowing()) {
createCancelDialog();
}
super.onResume();
}

Expand Down Expand Up @@ -511,6 +522,7 @@ private void selectSupersededForms() {
*/
public void formListDownloadingComplete(HashMap<String, FormDetails> result) {
progressDialog.dismiss();
viewModel.setProgressDialogShowing(false);
downloadFormListTask.setDownloaderListener(null);
downloadFormListTask = null;

Expand Down Expand Up @@ -676,6 +688,8 @@ public void onClick(DialogInterface dialog, int which) {
createCancelDialog();
downloadFormsTask.cancel(true);
}
viewModel.setLoadingCanceled(true);
viewModel.setProgressDialogShowing(false);
}
};
progressDialog.setTitle(getString(R.string.downloading_data));
Expand All @@ -684,6 +698,7 @@ public void onClick(DialogInterface dialog, int which) {
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
viewModel.setProgressDialogShowing(true);
DialogUtils.showDialog(progressDialog, this);
}

Expand All @@ -705,6 +720,7 @@ private void createCancelDialog() {
cancelDialog.setIcon(android.R.drawable.ic_dialog_info);
cancelDialog.setIndeterminate(true);
cancelDialog.setCancelable(false);
viewModel.setCancelDialogShowing(true);
DialogUtils.showDialog(cancelDialog, this);
}

Expand All @@ -725,6 +741,7 @@ public void formsDownloadingComplete(HashMap<FormDetails, String> result) {
if (progressDialog.isShowing()) {
// should always be true here
progressDialog.dismiss();
viewModel.setProgressDialogShowing(false);
}

createAlertDialog(getString(R.string.download_forms_result), getDownloadResultMessage(result), EXIT);
Expand Down Expand Up @@ -769,6 +786,7 @@ public void formsDownloadingCancelled() {

if (cancelDialog != null && cancelDialog.isShowing()) {
cancelDialog.dismiss();
viewModel.setCancelDialogShowing(false);
}

if (viewModel.isDownloadOnlyMode()) {
Expand Down
Expand Up @@ -41,8 +41,11 @@ public class FormDownloadListViewModel extends ViewModel {
private String username;
private String password;

private boolean progressDialogShowing;
private boolean alertShowing;
private boolean cancelDialogShowing;
private boolean shouldExit;
private boolean loadingCanceled;
// Variables for the external app intent call
private boolean isDownloadOnlyMode;

Expand Down Expand Up @@ -169,4 +172,28 @@ public String[] getFormIdsToDownload() {
public void setFormIdsToDownload(String[] formIdsToDownload) {
this.formIdsToDownload = formIdsToDownload;
}

public boolean isProgressDialogShowing() {
return progressDialogShowing;
}

public void setProgressDialogShowing(boolean progressDialogShowing) {
this.progressDialogShowing = progressDialogShowing;
}

public boolean isCancelDialogShowing() {
return cancelDialogShowing;
}

public void setCancelDialogShowing(boolean cancelDialogShowing) {
this.cancelDialogShowing = cancelDialogShowing;
}

public boolean wasLoadingCanceled() {
return loadingCanceled;
}

public void setLoadingCanceled(boolean loadingCanceled) {
this.loadingCanceled = loadingCanceled;
}
}

0 comments on commit f33ec84

Please sign in to comment.