package com.example.prashant.monolith.fragments;

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

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.prashant.monolith.R;
import com.example.prashant.monolith.adapters.GalleryAdapter;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class GalleryFragment extends Fragment {

    public GalleryAdapter adapter;
    public GridView gridView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_gallery, container, false);

        ArrayList<String> imageList = new ArrayList<>();
        adapter = new GalleryAdapter(getContext(), imageList);
        gridView = (GridView) rootView.findViewById(R.id.grid_view);
        gridView.setNumColumns(2);
        gridView.setAdapter(adapter);
        return rootView;
    }

    @Override
    public void onStart() {
        ImageLoadTask();
        super.onStart();
    }

    public void ImageLoadTask() {

        String url = "https://api.nasa.gov/planetary/apod?date=2017-03-04&hd=True&api_key=DEMO_KEY";

        JsonObjectRequest jsObjRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("here goes response", response.toString());
                        String date  = null;
                        try {
                            date = response.getString("date");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        Log.d("----------", "date is : " + date);
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                    }
                });
    }
}

@@ -287,32 +287,72 @@
 volley.Request;%0A
+import com.android.volley.RequestQueue;%0A
 import com.andro
@@ -371,16 +371,16 @@
 sponse;%0A
-
 import c
@@ -455,32 +455,74 @@
 nObjectRequest;%0A
+import com.android.volley.toolbox.Volley;%0A
 import com.examp
@@ -1470,25 +1470,91 @@
 oadTask() %7B%0A
+        RequestQueue queue = Volley.newRequestQueue(getContext());
 %0A
-
         Stri
@@ -2529,32 +2529,32 @@
               %7D%0A
-
                 
@@ -2557,16 +2557,49 @@
     %7D);%0A
+        queue.add(jsObjRequest);%0A
     %7D%0A%7D%0A

add queue request