package com.vinnypalumbo.popularmovies;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import java.util.Arrays;

/**
 * A placeholder fragment containing a simple view.
 */
public class MainActivityFragment extends Fragment {

    private ImageAdapter mMovieAdapter;

    public MainActivityFragment() {
    }

    MoviePoster[] moviePosters = {
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar),
            new MoviePoster(R.drawable.interstellar)
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        mMovieAdapter = new ImageAdapter(
                getActivity(),
                Arrays.asList(moviePosters)
        );

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        // Get a reference to the ListView, and attach the Adapter to it
        GridView gridView = (GridView) rootView.findViewById(R.id.gridview_movie);
        gridView.setAdapter(mMovieAdapter);

        return rootView;
    }
}

@@ -100,16 +100,41 @@
 agment;%0A
+import android.util.Log;%0A
 import a
@@ -161,16 +161,16 @@
 flater;%0A
-
 import a
@@ -251,16 +251,193 @@
 dView;%0A%0A
+import java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0A
 import j
@@ -1847,24 +1847,2441 @@
 eAdapter);%0A%0A
+        // These two need to be declared outside the try/catch%0A        // so that they can be closed in the finally block.%0A        HttpURLConnection urlConnection = null;%0A        BufferedReader reader = null;%0A%0A        // Will contain the raw JSON response as a string.%0A        String movieJsonStr = null;%0A%0A        try %7B%0A            // Construct the URL for the TheMovieDB query%0A            // Possible parameters are avaiable at TMDB's movie API page, at%0A            // http://docs.themoviedb.apiary.io/#reference/discover/discovermovie%0A            URL url = new URL(%22http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc%22);%0A%0A            // Create the request to TheMovieDB, and open the connection%0A            urlConnection = (HttpURLConnection) url.openConnection();%0A            urlConnection.setRequestMethod(%22GET%22);%0A            urlConnection.connect();%0A%0A            // Read the input stream into a String%0A            InputStream inputStream = urlConnection.getInputStream();%0A            StringBuffer buffer = new StringBuffer();%0A            if (inputStream == null) %7B%0A                // Nothing to do.%0A                return null;%0A            %7D%0A            reader = new BufferedReader(new InputStreamReader(inputStream));%0A%0A            String line;%0A            while ((line = reader.readLine()) != null) %7B%0A                // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)%0A                // But it does make debugging a *lot* easier if you print out the completed%0A                // buffer for debugging.%0A                buffer.append(line + %22%5Cn%22);%0A            %7D%0A%0A            if (buffer.length() == 0) %7B%0A                // Stream was empty.  No point in parsing.%0A                return null;%0A            %7D%0A            movieJsonStr = buffer.toString();%0A        %7D catch (IOException e) %7B%0A            Log.e(%22MainActivityFragment%22, %22Error %22, e);%0A            // If the code didn't successfully get the movie data, there's no point in attempting%0A            // to parse it.%0A            return null;%0A        %7D finally%7B%0A            if (urlConnection != null) %7B%0A                urlConnection.disconnect();%0A            %7D%0A            if (reader != null) %7B%0A                try %7B%0A                    reader.close();%0A                %7D catch (final IOException e) %7B%0A                    Log.e(%22MainActivityFragment%22, %22Error closing stream%22, e);%0A                %7D%0A            %7D%0A        %7D%0A%0A
         retu
@@ -4293,16 +4293,17 @@
 otView;%0A
-
     %7D%0A
+%0A
 %7D%0A

Add the network call code