Last active
August 29, 2015 14:16
-
-
Save elihart/dd1815e2aa18656120fd to your computer and use it in GitHub Desktop.
RequestManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestFragment extends AirFragment { | |
private static final int REQUEST_MANAGER_ID = 1; | |
@Inject RequestManager mRequestManager; | |
private RequestListener mListener = new RequestListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
} | |
@Override | |
public void onResponse(Object response) { | |
} | |
}; | |
@Override | |
public void onPause() { | |
super.onPause(); | |
mRequestManager.lockListeners(REQUEST_MANAGER_ID); | |
mRequestManager.removeListeners(REQUEST_MANAGER_ID); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
if (mRequestManager.hasRequest(REQUEST_MANAGER_ID, ListingAvailabilityRequest.class)) { | |
mRequestManager.setListener(REQUEST_MANAGER_ID, ListingAvailabilityRequest.class, mListener); | |
mRequestManager.unlockListeners(REQUEST_MANAGER_ID); | |
} else { | |
mRequestManager.execute(REQUEST_MANAGER_ID, new ListingAvailabilityRequest(mListener)); | |
} | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
if (getActivity().isFinishing()){ | |
mRequestManager.clearRequests(REQUEST_MANAGER_ID); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment