package com.kousenit.icndb;

import android.os.AsyncTask;
import android.widget.TextView;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Query;

public class JokeFinder {
    private TextView jokeView;
    private Retrofit retrofit;
    private AsyncTask<String, Void, String> task;

    public interface ICNDB {
        @GET("/jokes/random")
        Call<IcndbJoke> getJoke(@Query("firstName") String firstName,
                                @Query("lastName") String lastName,
                                @Query("limitTo") String limitTo);
    }

    public JokeFinder() {
        retrofit = new Retrofit.Builder()
                .baseUrl("http://api.icndb.com")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getJoke(TextView textView, String first, String last) {
        this.jokeView = textView;
        new JokeTask().execute(first, last);
    }

    private class JokeTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            ICNDB icndb = retrofit.create(ICNDB.class);
            Call<IcndbJoke> icndbJoke = icndb.getJoke(params[0], params[1], "[nerdy]");
            String joke = "";
            try {
                joke = icndbJoke.execute().body().getJoke();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return joke;
        }

        @Override
        protected void onPostExecute(String result) {
            jokeView.setText(result);
        }
    }
}

@@ -95,29 +95,23 @@
 ort 
-java.io.IOException;%0A
+retrofit2.Call;
 %0Aimp
@@ -120,32 +120,63 @@
 t retrofit2.Call
+back;%0Aimport retrofit2.Response
 ;%0Aimport retrofi
@@ -442,23 +442,16 @@
 k;%0A%0A    
-public 
 interfac
@@ -1026,24 +1026,25 @@
 xtView;%0A
+%0A
         
 new Joke
@@ -1039,121 +1039,138 @@
     
-new JokeTask().execute(first, last
+ICNDB icndb = retrofit.create(ICNDB.class
 );%0A    
-%7D%0A%0A
     
-private class JokeTask extends AsyncTask%3CString, Void, String%3E %7B%0A
+icndb.getJoke(first, last, %22%5Bnerdy%5D%22).enqueue(new Callback%3CIcndbJoke%3E() %7B%0A    
     
@@ -1195,234 +1195,262 @@
     
-protected String doInBackground(String... params) %7B%0A            ICNDB icndb = retrofit.create(ICNDB.class);%0A            Call%3CIcndbJoke%3E icndbJoke = icndb.getJoke(params%5B0%5D, params%5B1%5D, %22%5Bnerdy%5D%22);%0A            String joke = %22%22;%0A
+    public void onResponse(Call%3CIcndbJoke%3E call, Response%3CIcndbJoke%3E response) %7B%0A                if (!response.isSuccessful()) %7B%0A                    System.out.println(call.request().url() + %22 failed: %22 + response.code());%0A                    return;%0A   
     
@@ -1461,13 +1461,11 @@
     
-try %7B
+ %7D%0A
 %0A   
@@ -1485,30 +1485,29 @@
 joke
- = icndbJoke.execute()
+View.setText(response
 .bod
@@ -1519,16 +1519,17 @@
 etJoke()
+)
 ;%0A      
@@ -1539,229 +1539,192 @@
    %7D
- catch (IOException e) %7B%0A                e.printStackTrace();%0A            %7D%0A            return joke;%0A        %7D%0A%0A        @Override%0A        protected void onPostExecute(String result) %7B%0A            jokeView.setText(result);
+%0A%0A            @Override%0A            public void onFailure(Call%3CIcndbJoke%3E call, Throwable t) %7B%0A                System.out.println(call.request().url() + %22 failed: %22 + t);%0A            %7D
 %0A   
@@ -1725,21 +1725,23 @@
  %7D%0A        %7D
+);
 %0A    %7D%0A%7D%0A

Replace AsyncTask with enqueue in Retrofit