Does this:
public static class OperationFiles extends AsyncTask<Void, Integer,Void>
{
public enum Operation
{
Move,
Rename
}
private ProgressDialog progressDialog;
private Context context;
private OnPostExecuteListener onPostExecuteListener;
private List<File> filesList;
private String destino;
private Operation operation;
public OnPostExecuteListener getOnPostExecuteListener() {
return onPostExecuteListener;
}
public void setOnPostExecuteListener(OnPostExecuteListener onPostExecuteListener) {
this.onPostExecuteListener = onPostExecuteListener;
}
//aqui você pode receber a lista de arquivos e o novo local
public OperationFiles(Context context,List<File> filesList, String destino, Operation operation)
{
this.context = context;
this.progressDialog = new ProgressDialog(context);
this.filesList = filesList;
this.destino = destino;
this.operation = operation;
}
@Override
public void onPreExecute()
{
if(operation == Operation.Move)
this.progressDialog.setMessage("Movendo os arquivos...");
else
this.progressDialog.setMessage("Renomeando os arquivos...");
this.progressDialog.setMax(filesList.size());
this.progressDialog.show();
}
@Override
protected Void doInBackground(Void... voids)
{
for(int i = 0; i < filesList.size(); i++)
{
//faz a operação para defina no construtor aqui
if(operation == Operation.Move)
{
}
else
{
}
//itera no progresso
publishProgress(i);
}
return null;
}
@Override
public void onProgressUpdate(Integer... progress)
{
this.progressDialog.setProgress(progress[0]);
}
@Override
public void onPostExecute(Void result)
{
//dismiss do diálogo
this.progressDialog.dismiss();
//chama o callback informando o término do processo
if(getOnPostExecuteListener() != null)
getOnPostExecuteListener().onPostExecute();
}
//Irá fazer um callback para quando o processo terminar
public interface OnPostExecuteListener{
public void onPostExecute();
}
}
Consider that this is an example and you can change it according to your problem.
That way I did, once one operation is finished, it calls the other, making two different dialogs run.
The usage would look like this:
//Faz a operacao de mover os arquivos
OperationFiles operationFiles = new OperationFiles(this, new ArrayList<File>(), "/sdcard...", OperationFiles.Operation.Move );
//informa o callback
operationFiles.setOnPostExecuteListener(new OperationFiles.OnPostExecuteListener()
{
@Override
public void onPostExecute()
{
///aqui a operacao de renomear
OperationFiles operationFilesRename = new OperationFiles(Main.this, new ArrayList<File>(), "/sdcard...", OperationFiles.Operation.Rename);
operationFilesRename.execute();
}
});
operationFiles.execute();