package com.jamesdube.laravelnewsapp.posts;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jamesdube.laravelnewsapp.App;
import com.jamesdube.laravelnewsapp.R;
import com.jamesdube.laravelnewsapp.adapters.PostAdapter;
import com.jamesdube.laravelnewsapp.http.Client;
import com.jamesdube.laravelnewsapp.models.Post;

import java.util.List;

public class PostsFragment extends Fragment {

    RecyclerView postsRecyclerview;
    PostAdapter postAdapter;

   public static PostsFragment newInstance() {

        Bundle args = new Bundle();

        PostsFragment fragment = new PostsFragment();
        fragment.setArguments(args);
        return fragment;
    }

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

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_posts,container,false);
    }

    private void boot() {
        postsRecyclerview = (RecyclerView) getActivity().findViewById(R.id.postsRecyclerview);
        postsRecyclerview.setLayoutManager(new LinearLayoutManager(App.getAppContext()));
    }

    private void getPosts() {

        Client.getPosts(new Client.requestCallback() {
            @Override
            public void onSuccess(List<Post> posts) {
                setupPosts(posts);
            }

            @Override
            public void onFailure() {

            }
        });
    }

    private void setupPosts(List<Post> posts){
        postAdapter = new PostAdapter(posts);
        postsRecyclerview.setAdapter(postAdapter);
    }
}

@@ -253,33 +253,8 @@
 ew;%0A
-import android.util.Log;%0A
 impo
@@ -570,17 +570,191 @@
 app.
-models.Po
+http.requests.onGetPosts;%0Aimport com.jamesdube.laravelnewsapp.http.requests.rssRequest;%0Aimport com.jamesdube.laravelnewsapp.models.Post;%0Aimport com.jamesdube.laravelnewsapp.util.reque
 st;%0A
@@ -1686,25 +1686,24 @@
 etPosts() %7B%0A
-%0A
         Clie
@@ -1722,30 +1722,18 @@
 new 
-Client.requestCallback
+onGetPosts
 () %7B

use request client