Guest User

Fetch Free Agents

a guest
Sep 16th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.     /**
  2.      * An asynchronous task used fetch the current league's free agents.
  3.      * Returns a FantasyLeague object.
  4.      */
  5.     public class GetFreeAgentsTask extends AsyncTask<Void, Void, FantasyLeague> {
  6.  
  7.         private List<Exception> exceptions = new ArrayList<Exception>();
  8.  
  9.         @Override
  10.         protected FantasyLeague doInBackground(Void... params) {
  11.             try {
  12.                 return mLeague.refreshFreeAgents(InDraftActivity.this.getApplicationContext());
  13.             } catch (JSONException e) {
  14.                 exceptions.add(e);
  15.                 return null;
  16.             } catch (ServerErrorException e) {
  17.                 exceptions.add(e);
  18.                 return null;
  19.             }
  20.         }
  21.  
  22.         @Override
  23.         protected void onPostExecute(FantasyLeague league) {
  24.             super.onPostExecute(league);
  25.  
  26.             // If there are any exceptions, display them via toast.
  27.             for (Exception e : exceptions) {
  28.                 if (getApplicationContext() != null) {
  29.                     ErrorHelper.showErrorToast(getApplicationContext(), e.getMessage());
  30.                 }
  31.             }
  32.  
  33.             // Handle a failed request with no exceptions.
  34.             if (league == null && exceptions.isEmpty()) {
  35.                 if (getApplicationContext() != null) {
  36.                     ErrorHelper.showErrorToast(getApplicationContext(), "Failed to retrieve free agents.");
  37.                 }
  38.             }
  39.  
  40.             // Handle the normal result.
  41.             onGetFreeAgentsResult(league);
  42.         }
  43.     }
Add Comment
Please, Sign In to add comment