Skip to content

Commit

Permalink
fix: Added a progress dialog while deleting the forms. (getodk#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0pdb authored and lognaturel committed Aug 22, 2017
1 parent 0910d8e commit a2ba335
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.odk.collect.android.fragments;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.AsyncTask;
Expand Down Expand Up @@ -55,12 +56,12 @@ public class DataManagerList extends InstanceListFragment
DeleteInstancesTask deleteInstancesTask = null;
private AlertDialog alertDialog;
private InstanceSyncTask instanceSyncTask;
private ProgressDialog progressDialog;

public static DataManagerList newInstance() {
return new DataManagerList();
}


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
Expand Down Expand Up @@ -193,12 +194,24 @@ public void onClick(DialogInterface dialog, int i) {
alertDialog.show();
}

@Override
public void progressUpdate(int progress, int total) {
String message = String.format(getResources().getString(R.string.deleting_form_dialog_update_message),progress,total);
progressDialog.setMessage(message);
}

/**
* Deletes the selected files. Content provider handles removing the files
* from the filesystem.
*/
private void deleteSelectedInstances() {
if (deleteInstancesTask == null) {
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getResources().getString(R.string.form_delete_message));
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.show();

deleteInstancesTask = new DeleteInstancesTask();
deleteInstancesTask.setContentResolver(getActivity().getContentResolver());
deleteInstancesTask.setDeleteListener(this);
Expand Down Expand Up @@ -230,12 +243,15 @@ public void deleteComplete(int deletedInstances) {
String.valueOf(toDeleteCount - deletedInstances),
String.valueOf(toDeleteCount)));
}

deleteInstancesTask = null;
getListView().clearChoices(); // doesn't unset the checkboxes
for (int i = 0; i < getListView().getCount(); ++i) {
getListView().setItemChecked(i, false);
}
deleteButton.setEnabled(false);

progressDialog.dismiss();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
*/
public interface DeleteInstancesListener {
void deleteComplete(int deletedInstances);

void progressUpdate(int progress, int total);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author norman86@gmail.com
* @author mitchellsundt@gmail.com
*/
public class DeleteInstancesTask extends AsyncTask<Long, Void, Integer> {
public class DeleteInstancesTask extends AsyncTask<Long, Integer, Integer> {


private ContentResolver contentResolver;
Expand Down Expand Up @@ -65,6 +65,10 @@ protected Integer doInBackground(Long... params) {
if (wasDeleted > 0) {
Collect.getInstance().getActivityLogger().logAction(this, "delete", deleteForm.toString());
}

successCount++;
publishProgress(successCount,toDeleteCount);

} catch (Exception ex) {
Timber.e("Exception during delete of: %s exception: %s", param.toString(), ex.toString());
}
Expand All @@ -73,6 +77,15 @@ protected Integer doInBackground(Long... params) {
return deleted;
}

@Override
protected void onProgressUpdate(Integer... values) {
synchronized (this) {
if (deleteInstancesListener != null) {
deleteInstancesListener.progressUpdate(values[0],values[1]);
}
}
}

@Override
protected void onPostExecute(Integer result) {
contentResolver = null;
Expand Down
2 changes: 2 additions & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -508,5 +508,7 @@
<string name="invalid_email_address">Invalid email address!</string>
<string name="sort_by">Sort by</string>
<string name="server">Server</string>
<string name="form_delete_message">Deleting selected forms</string>
<string name="deleting_form_dialog_update_message">Deleting form: %1$d out of %2$d </string>
<string name="search">Search</string>
</resources>

0 comments on commit a2ba335

Please sign in to comment.