package mindpop.learnpop;

import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import org.json.JSONObject;


/**
 * Created by montselozanod on 3/20/15.
 */
public class Articles extends Fragment {

    public static final String PREFS_NAME = "UserPrefs";
    private ProgressDialog pDialog;
    //private Learnpop learnApp;
    private LoadResource loadResource;
    ArrayList<Resource> resourceArrayList = new ArrayList<Resource>();
    private RecyclerView mRecyclerView;
    private RecyclerView.LayoutManager mLayoutManager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_article, container, false);
        //restore prefs
        restorePreferences();
        String [] sub = {"Visual Art", "Science"};
        resourceArrayList = new ArrayList<Resource>();
        mRecyclerView = (RecyclerView)rootView.findViewById(R.id.recycler_res);
        mRecyclerView.setHasFixedSize(true);
        mLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(mLayoutManager);
        loadResource = new LoadResource(getActivity(), getActivity(), mRecyclerView, sub ,"LowerElem", 0);

        loadResource.execute();


        //setListAdapter(new ListAdapter(getActivity(), resourceArrayList));
        return rootView;

    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // remove the dividers from the ListView of the ListFragment

    }

    /*@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // retrieve theListView item
        Resource item = resourceArrayList.get(position);
        // do something
        //Toast.makeText(getActivity(), item.getTitle(), Toast.LENGTH_SHORT).show();

        WebViewFragment webFrag = new WebViewFragment();
        webFrag.init(item.getUrl());

        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.drawer_layout, webFrag);
        transaction.addToBackStack(null);
        transaction.commit();
    }*/

    private void restorePreferences(){
        SharedPreferences settings = this.getActivity().getSharedPreferences(PREFS_NAME, 0);
        boolean visual = settings.getBoolean("visual", false);
        boolean drama = settings.getBoolean("drama", false);
        boolean socials = settings.getBoolean("socials", false);
        boolean science = settings.getBoolean("science", false);
        boolean math = settings.getBoolean("math", false);
        boolean movement = settings.getBoolean("movement", false);
        boolean digital = settings.getBoolean("digital", false);
        boolean bilingual = settings.getBoolean("bilingual", false);
        boolean ela = settings.getBoolean("ela", false);
        boolean music = settings.getBoolean("music", false);

        String gradelevel = settings.getString("grade", "LowerElem");
    }

    private void checkResponseForRequest(JSONObject resourceObj){

    }


}

@@ -1953,622 +1953,8 @@
  %7D%0A%0A
-    /*@Override%0A    public void onListItemClick(ListView l, View v, int position, long id) %7B%0A        // retrieve theListView item%0A        Resource item = resourceArrayList.get(position);%0A        // do something%0A        //Toast.makeText(getActivity(), item.getTitle(), Toast.LENGTH_SHORT).show();%0A%0A        WebViewFragment webFrag = new WebViewFragment();%0A        webFrag.init(item.getUrl());%0A%0A        FragmentTransaction transaction = getFragmentManager().beginTransaction();%0A        transaction.replace(R.id.drawer_layout, webFrag);%0A        transaction.addToBackStack(null);%0A        transaction.commit();%0A    %7D*/%0A%0A
     

delete list item method