package org.keyscience.fragments;

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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import org.keyscience.R;
import org.keyscience.adapters.ExpListAdapter;
import org.keyscience.adapters.LectureSeriesAdapter;
import org.keyscience.app.Constants;
import org.keyscience.app.HomeActivity;
import org.keyscience.models.LectureSeriesModel;

public class LectureSeriesFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lectureseries_fragment, container, false);


        // setup recycler view
        RecyclerView recyclerView = view.findViewById(R.id.lecture_series_recycler);
        recyclerView.setFocusable(false);
        LectureSeriesAdapter adapter = new LectureSeriesAdapter(LectureSeriesModel.getData(getContext()), getContext());
        recyclerView.setAdapter(adapter);
        LinearLayoutManager linearVertical = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linearVertical);


        Button learnMore = view.findViewById(R.id.ls_learn_more);
        learnMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (ExpListAdapter.getFragmentMap().get(Constants.EVENTS) != null) {
                    ((HomeActivity) getContext()).setViewPager(ExpListAdapter.getFragmentMap().get(Constants.EVENTS));
                }

            }
        });

        return view;
    }
}
