What you want to do first is to configure the interface correctly, it should be (in terms of modification 2):
Call<object> getEvents(@Body JsonObject events)**
** Please note that the type parameter objectshould be replaced with the model that you expect to receive from the service. If you don’t care about the answer, you can leave it as an object that I consider.
, :
final RF_Calls service =
Call c = service.getEvents(json);
[Your progress view].show();
c.enqueue(new Callback<object>{
@Override
public void onResponse(Response<object>, Retrofit retrofit){
[Your progress view].hide();
}
@Override
public void onFailure(Throwable t){
[Your progress view].hide();
}
});
- , , .
, :
public interface Act<T> {
void execute(T data);
}
public static <T> void makeServiceCallWithProgress(Call c, final Act<T> success, final Act<Throwable> failure, final ProgressBar progressBar) {
progressBar.setVisibility(View.VISIBLE);
c.enqueue(new Callback<T>() {
@Override
public void onResponse(Response<T> response, Retrofit retrofit) {
progressBar.setVisibility(View.GONE);
success.execute(response.body());
}
@Override
public void onFailure(Throwable t) {
progressBar.setVisibility(View.GONE);
failure.execute(t);
}
});
}
:
makeServiceCallWithProgress(service.getEvents(json),
new Act<MyResponseModel>() {
@Override
public void execute(MyResponseModel data) {
}
},
new Act<Throwable>() {
@Override
public void execute(Throwable data) {
}
},
progressBar);
, , Java Android , .