|
1 | 1 | package com.codepath.debuggingchallenges.activities;
|
2 | 2 |
|
3 | 3 | import android.os.Bundle;
|
4 |
| -import android.support.v7.app.AppCompatActivity; |
5 |
| -import android.support.v7.widget.RecyclerView; |
| 4 | +import android.util.Log; |
6 | 5 |
|
| 6 | +import androidx.appcompat.app.AppCompatActivity; |
| 7 | +import androidx.recyclerview.widget.RecyclerView; |
| 8 | + |
| 9 | +import com.codepath.asynchttpclient.AsyncHttpClient; |
| 10 | +import com.codepath.asynchttpclient.callback.JsonHttpResponseHandler; |
7 | 11 | import com.codepath.debuggingchallenges.R;
|
8 | 12 | import com.codepath.debuggingchallenges.adapters.MoviesAdapter;
|
9 | 13 | import com.codepath.debuggingchallenges.models.Movie;
|
10 |
| -import com.loopj.android.http.AsyncHttpClient; |
11 |
| -import com.loopj.android.http.JsonHttpResponseHandler; |
12 | 14 |
|
13 | 15 | import org.json.JSONArray;
|
14 | 16 | import org.json.JSONException;
|
15 |
| -import org.json.JSONObject; |
16 | 17 |
|
17 | 18 | import java.util.ArrayList;
|
18 | 19 |
|
19 |
| -import cz.msebera.android.httpclient.Header; |
| 20 | +import okhttp3.Headers; |
20 | 21 |
|
21 | 22 | public class MoviesActivity extends AppCompatActivity {
|
22 | 23 |
|
@@ -47,14 +48,19 @@ private void fetchMovies() {
|
47 | 48 | AsyncHttpClient client = new AsyncHttpClient();
|
48 | 49 | client.get(url, null, new JsonHttpResponseHandler() {
|
49 | 50 | @Override
|
50 |
| - public void onSuccess(int statusCode, Header[] headers, JSONObject response) { |
| 51 | + public void onSuccess(int statusCode, Headers headers, JSON response) { |
51 | 52 | try {
|
52 |
| - JSONArray moviesJson = response.getJSONArray("results"); |
| 53 | + JSONArray moviesJson = response.jsonObject.getJSONArray("results"); |
53 | 54 | movies = Movie.fromJSONArray(moviesJson);
|
54 | 55 | } catch (JSONException e) {
|
55 | 56 | e.printStackTrace();
|
56 | 57 | }
|
57 | 58 | }
|
| 59 | + |
| 60 | + @Override |
| 61 | + public void onFailure(int statusCode, Headers headers, String response, Throwable throwable) { |
| 62 | + Log.e(MoviesActivity.class.getSimpleName(), "Error retrieving movies: ", throwable); |
| 63 | + } |
58 | 64 | });
|
59 | 65 | }
|
60 | 66 | }
|
0 commit comments