Skip to content

Commit

Permalink
Merge pull request #64 from pnemonic78/issue_not-attached-to-window-m…
Browse files Browse the repository at this point in the history
…anager

Progress dialog can cancel.
  • Loading branch information
pnemonic78 authored Mar 19, 2024
2 parents 208e910 + 5287815 commit 400afc4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ protected void onPreExecute() {
if (mContext instanceof Activity) {
mProgressDialog = new GnucashProgressDialog((Activity) mContext);
mProgressDialog.setTitle(R.string.title_progress_exporting_transactions);
mProgressDialog.setCancelable(true);
mProgressDialog.setOnCancelListener(dialogInterface -> cancel(true));
mProgressDialog.show();
}
}
Expand Down Expand Up @@ -209,8 +211,9 @@ protected void onPostExecute(Integer exportSuccessful) {

private void dismissProgressDialog() {
if (mContext instanceof Activity) {
if (mProgressDialog != null && mProgressDialog.isShowing())
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
((Activity) mContext).finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new GnucashProgressDialog(mContext);
mProgressDialog.setTitle(R.string.title_progress_importing_accounts);
mProgressDialog.setCancelable(true);
mProgressDialog.setOnCancelListener(dialogInterface -> cancel(true));
mProgressDialog.show();
}

Expand Down Expand Up @@ -130,8 +132,9 @@ public void run() {
@Override
protected void onPostExecute(Boolean importSuccess) {
try {
if (mProgressDialog != null && mProgressDialog.isShowing())
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
} catch (IllegalArgumentException ex) {
//TODO: This is a hack to catch "View not attached to window" exceptions
//FIXME by moving the creation and display of the progress dialog to the Fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public void onStart() {
super.onStart();
if (getDialog() != null) {
((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
final AlertDialog dialog = (AlertDialog) getDialog();
if (dialog != null) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
setUpConfirmCheckBox();
}
}
Expand All @@ -93,6 +94,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
* <p>By default it just dismisses the dialog.</p>
*/
protected void onNegativeButton() {
getDialog().dismiss();
dismiss();
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/org/gnucash/android/util/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ protected void onPreExecute() {
if (activity != null) {
mProgressDialog = new GnucashProgressDialog(activity);
mProgressDialog.setTitle(R.string.title_create_backup_pref);
mProgressDialog.setCancelable(true);
mProgressDialog.setOnCancelListener(dialogInterface -> cancel(true));
mProgressDialog.show();
}
}
Expand Down Expand Up @@ -224,6 +226,8 @@ protected void onPreExecute() {
if (activity != null) {
mProgressDialog = new GnucashProgressDialog(activity);
mProgressDialog.setTitle(R.string.title_create_backup_pref);
mProgressDialog.setCancelable(true);
mProgressDialog.setOnCancelListener(dialogInterface -> cancel(true));
mProgressDialog.show();
}
}
Expand Down

0 comments on commit 400afc4

Please sign in to comment.