Skip to main content
Meta information is not needed in a post
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

upate

I marked Simon's answer below as accepted because it was a valid review of my original code. There is an answer that I provide which was an update to what I originally posted. I will incorporate the review items below that still make sense. removing the call to super() and making fields as final.

upate

I marked Simon's answer below as accepted because it was a valid review of my original code. There is an answer that I provide which was an update to what I originally posted. I will incorporate the review items below that still make sense. removing the call to super() and making fields as final.

added 316 characters in body
Source Link
nPn
  • 165
  • 1
  • 1
  • 7

upate

I marked Simon's answer below as accepted because it was a valid review of my original code. There is an answer that I provide which was an update to what I originally posted. I will incorporate the review items below that still make sense. removing the call to super() and making fields as final.

upate

I marked Simon's answer below as accepted because it was a valid review of my original code. There is an answer that I provide which was an update to what I originally posted. I will incorporate the review items below that still make sense. removing the call to super() and making fields as final.

Rollback to Revision 3
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

***** Update *****

Here is what I currently have:

@Subscribe
public void onLeave(LeaveRequest event) {
    System.out.println("inside api repo - making leave request");
    mRailsApi.leave(event.getEmail(), event.getPassword(),
            new RailsApiCallback<LeaveResponse>(mBus, new LeaveResponse() ));
}   

public class RailsApiCallback<T extends BaseResponse> implements Callback<T> {

    private Bus mBus;
    private T mResponse;

    public RailsApiCallback(Bus bus, T response) {
        super();
        mBus = bus;
        mResponse = response; 
    }

    @Override
    public void failure(RetrofitError retrofitError) {
        System.out.println(retrofitError.toString());
        T response = (T) retrofitError.getBody() != null ? (T) retrofitError.getBody() : mResponse  ;
        response.setRawResponse(retrofitError.getResponse());
        response.setSuccessful(false);
        mBus.post(response);
    }

    @Override
    public void success(T convertedResponse, Response rawResponse) {
        System.out.println(rawResponse.getBody());
        T response = convertedResponse != null ? convertedResponse : mResponse ;
        response.setSuccessful(true);
        response.setRawResponse(rawResponse);
        mBus.post(response);

    }
}

***** Update *****

Here is what I currently have:

@Subscribe
public void onLeave(LeaveRequest event) {
    System.out.println("inside api repo - making leave request");
    mRailsApi.leave(event.getEmail(), event.getPassword(),
            new RailsApiCallback<LeaveResponse>(mBus, new LeaveResponse() ));
}   

public class RailsApiCallback<T extends BaseResponse> implements Callback<T> {

    private Bus mBus;
    private T mResponse;

    public RailsApiCallback(Bus bus, T response) {
        super();
        mBus = bus;
        mResponse = response; 
    }

    @Override
    public void failure(RetrofitError retrofitError) {
        System.out.println(retrofitError.toString());
        T response = (T) retrofitError.getBody() != null ? (T) retrofitError.getBody() : mResponse  ;
        response.setRawResponse(retrofitError.getResponse());
        response.setSuccessful(false);
        mBus.post(response);
    }

    @Override
    public void success(T convertedResponse, Response rawResponse) {
        System.out.println(rawResponse.getBody());
        T response = convertedResponse != null ? convertedResponse : mResponse ;
        response.setSuccessful(true);
        response.setRawResponse(rawResponse);
        mBus.post(response);

    }
}
added 1342 characters in body
Source Link
nPn
  • 165
  • 1
  • 1
  • 7
Loading
Source Link
nPn
  • 165
  • 1
  • 1
  • 7
Loading