I have a custom Listener
public interface CustomListener {
void processDownload(boolean isSuccess,int process,int total);
}
And the ControllerRequest class where I use the listener , and I have the onProcessDownload method that will be used to overwrite the listener methods used. . As in the active class, the listener customListener.processDownload (true, i, Total);
public class ControllerRequest implements Callback<ResponseClass> {
ActivityMain activity;
Databasedb db;
Context context;
CustomListener customListener;
public void start(Context context, String ps) {
activity = (ActivityMain) context;
db = new Databasedb(context);
APInterfaces interfaces = ApiClient.getClient("").create(APInterfaces.class);
Call<ResponseClass> call = interfaces.doRequest(ps);
call.enqueue(this);
}
@Override
public void onResponse(Call<ResponseClass> call, Response<ResponseClass> response) {
int statusCode = response.code();
if (statusCode == 200) {
if (response.body().getPermission().equals("danger")) {
Toast.makeText(activity, "Error: " + response.body().getMessageWarning(), Toast.LENGTH_SHORT).show();
} else if (response.body().getPermission().equals("isSuccesfull")) {
int Total = response.body().getmyRequest().size();
int i = 0;
for (RequestClass myRequest : response.body().getmyRequest()) {
i++;
db.createTag(myRequest);
customListener.processDownload(true,i,Total);
}
db.close();
}
}
}
@Override
public void onFailure(Call<ResponseClass> call, Throwable t) {
t.printStackTrace();
}
public void onProcessDownload(CustomListener listener){
customListener = listener;
}
}
To finish and use the listener in another activity I use the onProcessDownload method as follows.
private ProgressDialog progress;
......
......
progress = new ProgressDialog(Activity.this);
...................
progress.setMessage("Sincronizando...");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setCancelable(false);
progress.setProgress(0)
progress.show();
................
myinstance.onProcessDownload(new CustomListener() {
@Override
public void processDownload(boolean isSuccess, int process, int total) {
//progress.setProgress(total);
Log.e("processDownload: ", "Descargando: "+process);
progress.setMax(total);
progress.setProgress(process);
}
});
Up to here everything works correctly except:
progress.setProgress (process);
progress.setMax (total);
These two lines are the ones that do not work, they do not update the dialogue.
In the logcat the listener is what it shows me, indicating that the listener is listening to the changes that are generated from the other class, the problem would be only the dialogue.
*11-07 17:07:07.788 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 556
11-07 17:07:07.797 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 557
11-07 17:07:07.806 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 558
11-07 17:07:07.815 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 559
11-07 17:07:07.824 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 560
11-07 17:07:07.833 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 561
11-07 17:07:07.845 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 562
11-07 17:07:07.862 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 563
11-07 17:07:07.872 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 564
11-07 17:07:07.884 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 565
11-07 17:07:07.895 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 566
11-07 17:07:07.906 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 567
11-07 17:07:07.917 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 568
11-07 17:07:07.935 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 569
11-07 17:07:07.947 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 570
11-07 17:07:07.957 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 571
11-07 17:07:07.968 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 572
11-07 17:07:07.979 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 573
11-07 17:07:07.991 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 574
11-07 17:07:08.000 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 575
11-07 17:07:08.009 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 576
11-07 17:07:08.017 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 577
11-07 17:07:08.027 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 578
11-07 17:07:08.038 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 579
11-07 17:07:08.058 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 580
11-07 17:07:08.068 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 581
11-07 17:07:08.079 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 582
11-07 17:07:08.091 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 583
11-07 17:07:08.109 7348-7348/com.myapp.requestcomp E/processDownload:: Descargando: 584*
When closing the dialog and executing it again it shows this, but during the process it does not show anything, and of course when executing it again it does not change the information stays with the same data.