Skip to content

Commit

Permalink
Fixed dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Mar 5, 2019
1 parent f5da267 commit 89e6044
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Expand Up @@ -180,8 +180,6 @@ private void init(Bundle savedInstanceState) {
}
}

viewModel.setAlertMsg(getString(R.string.please_wait));

downloadButton = findViewById(R.id.add_button);
downloadButton.setEnabled(listView.getCheckedItemCount() > 0);
downloadButton.setOnClickListener(new OnClickListener() {
Expand Down Expand Up @@ -233,7 +231,9 @@ public void onClick(View v) {
downloadFormListTask = (DownloadFormListTask) getLastCustomNonConfigurationInstance();
if (downloadFormListTask.getStatus() == AsyncTask.Status.FINISHED) {
try {
progressDialog.dismiss();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
viewModel.setProgressDialogShowing(false);
} catch (IllegalArgumentException e) {
Timber.i("Attempting to close a dialog that was not previously opened");
Expand All @@ -244,7 +244,9 @@ public void onClick(View v) {
downloadFormsTask = (DownloadFormsTask) getLastCustomNonConfigurationInstance();
if (downloadFormsTask.getStatus() == AsyncTask.Status.FINISHED) {
try {
progressDialog.dismiss();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
viewModel.setProgressDialogShowing(false);
} catch (IllegalArgumentException e) {
Timber.i("Attempting to close a dialog that was not previously opened");
Expand Down Expand Up @@ -302,7 +304,7 @@ private void downloadFormList() {
viewModel.clearFormNamesAndURLs();
if (progressDialog != null) {
// This is needed because onPrepareDialog() is broken in 1.6.
progressDialog.setMessage(getString(R.string.please_wait));
progressDialog.setMessage(viewModel.getProgressDialogMsg());
}
createProgressDialog();

Expand Down Expand Up @@ -467,7 +469,7 @@ protected void onResume() {
downloadFormsTask.setDownloaderListener(this);
}
if (viewModel.isAlertShowing()) {
createAlertDialog(viewModel.getAlertTitle(), viewModel.getAlertMsg(), viewModel.shouldExit());
createAlertDialog(viewModel.getAlertTitle(), viewModel.getAlertDialogMsg(), viewModel.shouldExit());
}
if (viewModel.isProgressDialogShowing() && (progressDialog == null || !progressDialog.isShowing())) {
createProgressDialog();
Expand Down Expand Up @@ -654,7 +656,7 @@ public void onClick(DialogInterface dialog, int i) {
alertDialog.setCancelable(false);
alertDialog.setButton(getString(R.string.ok), quitListener);
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
viewModel.setAlertMsg(message);
viewModel.setAlertDialogMsg(message);
viewModel.setAlertTitle(title);
viewModel.setAlertShowing(true);
viewModel.setShouldExit(shouldExit);
Expand Down Expand Up @@ -693,7 +695,7 @@ public void onClick(DialogInterface dialog, int which) {
}
};
progressDialog.setTitle(getString(R.string.downloading_data));
progressDialog.setMessage(viewModel.getAlertMsg());
progressDialog.setMessage(viewModel.getProgressDialogMsg());
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
Expand Down Expand Up @@ -726,8 +728,8 @@ private void createCancelDialog() {

@Override
public void progressUpdate(String currentFile, int progress, int total) {
viewModel.setAlertMsg(getString(R.string.fetching_file, currentFile, String.valueOf(progress), String.valueOf(total)));
progressDialog.setMessage(viewModel.getAlertMsg());
viewModel.setProgressDialogMsg(getString(R.string.fetching_file, currentFile, String.valueOf(progress), String.valueOf(total)));
progressDialog.setMessage(viewModel.getProgressDialogMsg());
}

@Override
Expand Down
Expand Up @@ -18,6 +18,8 @@

import android.arch.lifecycle.ViewModel;

import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.logic.FormDetails;

import java.util.ArrayList;
Expand All @@ -36,7 +38,8 @@ public class FormDownloadListViewModel extends ViewModel {
private String[] formIdsToDownload;

private String alertTitle;
private String alertMsg;
private String progressDialogMsg;
private String alertDialogMsg;
private String url;
private String username;
private String password;
Expand Down Expand Up @@ -69,12 +72,20 @@ public void setAlertTitle(String alertTitle) {
this.alertTitle = alertTitle;
}

public String getAlertMsg() {
return alertMsg;
public String getProgressDialogMsg() {
return progressDialogMsg == null ? Collect.getInstance().getString(R.string.please_wait) : progressDialogMsg;
}

public void setAlertMsg(String alertMsg) {
this.alertMsg = alertMsg;
public void setProgressDialogMsg(String progressDialogMsg) {
this.progressDialogMsg = progressDialogMsg;
}

public String getAlertDialogMsg() {
return alertDialogMsg;
}

public void setAlertDialogMsg(String alertDialogMsg) {
this.alertDialogMsg = alertDialogMsg;
}

public boolean isAlertShowing() {
Expand Down

0 comments on commit 89e6044

Please sign in to comment.