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.example.prashant.monolith.R;
import com.example.prashant.monolith.adapters.GalleryAdapter;
import com.example.prashant.monolith.objects.GalleryInterface;
import com.example.prashant.monolith.objects.GalleryObject;
import com.example.prashant.monolith.objects.Rss;

import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;

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() {
        ImageFetchTask();
        super.onStart();
    }

    public void ImageFetchTask() {

        String API_BASE_URL = "https://www.nasa.gov/rss/dyn/";

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(API_BASE_URL)
                .client(new OkHttpClient())
                .addConverterFactory(SimpleXmlConverterFactory.create())
                .build();

        Rss service = retrofit.create(Rss.class);

        Call<List<Rss>> call = service.respForphoto();

        // Execute the call asynchronously. Get a positive or negative callback.
        call.enqueue(new Callback<List<Rss>>() {
            @Override
            public void onResponse(Call<List<Rss>> call, Response<List<Rss>> response) {

            }

            @Override
            public void onFailure(Call<List<Rss>> call, Throwable t) {

            }
        });

    }
}

@@ -1923,34 +1923,28 @@
        Call%3C
-List%3C
 Rss%3E
-%3E
  call = serv
@@ -2079,26 +2079,20 @@
 allback%3C
-List%3C
 Rss%3E
-%3E
 () %7B%0A   
@@ -2146,34 +2146,28 @@
 sponse(Call%3C
-List%3C
 Rss%3E
-%3E
  call, Respo
@@ -2170,26 +2170,20 @@
 esponse%3C
-List%3C
 Rss%3E
-%3E
  respons
@@ -2268,18 +2268,12 @@
 all%3C
-List%3C
 Rss%3E
-%3E
  cal

call params