Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added a progress dialog while deleting the forms. #1348

Merged
merged 6 commits into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>