package zeroturnaround.org.jrebel4androidgettingstarted;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.IOException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.button)
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Super fast hello world from JRebel for Android", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class);
                final Call<List<Contributor>> call =
                        gitHubService.repoContributors("square", "retrofit");
                new NetworkCall().execute(call);
            }
        });
    }

    private class NetworkCall extends AsyncTask<Call, Void, String> {
        @Override
        protected String doInBackground(Call... params) {
            try {
                Call<List<Contributor>> call = params[0];
                Response<List<Contributor>> response = call.execute();
                return response.body().toString();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            final TextView textView = (TextView) findViewById(R.id.textView);
            textView.setText(result);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -55,37 +55,8 @@
 d;%0A%0A
-import android.os.AsyncTask;%0A
 impo
@@ -423,36 +423,8 @@
 w;%0A%0A
-import java.io.IOException;%0A
 impo
@@ -527,16 +527,43 @@
 2.Call;%0A
+import retrofit2.Callback;%0A
 import r
@@ -1745,16 +1745,17 @@
 ofit%22);%0A
+%0A
         
@@ -1766,219 +1766,86 @@
     
-new NetworkCall().execute(call);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private class NetworkCall extends AsyncTask%3CCall, Void, String%3E %7B%0A        @Override%0A        protected String doInBackground(Call... params) %7B
+call.enqueue(new Callback%3CList%3CContributor%3E%3E() %7B%0A                    @Override
 %0A   
@@ -1855,16 +1855,8 @@
     
-  try %7B%0A
     
@@ -1861,22 +1861,39 @@
         
-      
+public void onResponse(
 Call%3CLis
@@ -1916,37 +1916,9 @@
 call
- = params%5B0%5D;%0A               
+,
  Res
@@ -1954,151 +1954,170 @@
 onse
- = call.execute();%0A                return response.body().toString();%0A            %7D catch (IOException e) %7B%0A                e.printStackTrace
+) %7B%0A                        final TextView textView = (TextView) findViewById(R.id.textView);%0A                        textView.setText(response.body().toString
 ()
+)
 ;%0A  
@@ -2126,27 +2126,24 @@
         
-%7D%0A%0A
         
     retu
@@ -2138,36 +2138,22 @@
     
+%7D%0A
     
-return null;%0A
+ 
        
- %7D%0A%0A
     
@@ -2178,49 +2178,82 @@
     
-protected void onPostExecute(String resul
+            public void onFailure(Call%3CList%3CContributor%3E%3E call, Throwable 
 t) %7B
@@ -2257,32 +2257,44 @@
 ) %7B%0A            
+  
+          
 final TextView t
@@ -2335,32 +2335,44 @@
 R.id.textView);%0A
+            
             text
@@ -2388,14 +2388,91 @@
 ext(
-result
+%22Something went wrong: %22 + t.getMessage());%0A                    %7D%0A                %7D
 );%0A 
@@ -2482,15 +2482,32 @@
     
+  
-%7D%0A    %7D
+  %7D%0A        %7D);%0A    %7D%0A
 %0A%0A  

Remove AsyncTask, it's not 1995 anymore