Two Android ProgressDialog one after another

0

How do I display two progress Dialog, when one finishes, open the other?

In my case the user clicks on a button, then several files in one folder are moved and renamed to another folder, it first sends everything, then renames it. So I would have to have 2 progress dialogs, one for when sending, and the other for renaming. But only appear when the other disappears ...

I need to progress dialog to rename since there are more than 200 files.

I searched and it looks like it is not possible. Any idea?

    
asked by anonymous 07.07.2014 / 09:14

2 answers

0

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();
    
07.07.2014 / 18:57
0

The way you put it was pretty generic, but you can put at the end of the 1 thread (sending files) call the dismiss () of 1 ProgressDialog, and then immediately call the 2 thread (rename files) that thread will call to 2 ProgressDialog and at the end call the dismiss () of it.

    
07.07.2014 / 16:22