package edu.rpi.cs.yacs.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.truizlop.sectionedrecyclerview.SimpleSectionedAdapter;

import java.util.List;

import edu.rpi.cs.yacs.R;
import edu.rpi.cs.yacs.models.School;
import edu.rpi.cs.yacs.viewholders.ItemViewHolder;

/**
 * Created by Mark Robinson on 10/15/16.
 */
public class SchoolsAdapter extends SimpleSectionedAdapter<ItemViewHolder> {

    private List<School> schoolList = null;

    public SchoolsAdapter(final List<School> schoolList) {
        this.schoolList = schoolList;
    }

    @Override
    protected String getSectionHeaderTitle(int section) {
        if (schoolList != null) {
            return schoolList.get(section).getName();
        }

        return "";
    }

    @Override
    protected int getSectionCount() {
        if (schoolList != null) {
            return schoolList.size();
        }

       return 0;
    }

    @Override
    protected int getItemCountForSection(int section) {
        if (schoolList != null) {
            return schoolList.get(section).getDepartments().size();
        }

        return 0;
    }

    @Override
    protected ItemViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.view_item, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    protected void onBindItemViewHolder(ItemViewHolder holder, int section, int position) {
        String departmentName = schoolList.get(section).getDepartments().get(position).getName();
        String departmentCode = schoolList.get(section).getDepartments().get(position).getCode();

        holder.render(departmentName, departmentCode);
    }
}
@@ -28,16 +28,88 @@
 pters;%0A%0A
+import android.support.v7.widget.RecyclerView;%0Aimport android.util.Log;%0A
 import a
@@ -311,16 +311,58 @@
 yacs.R;%0A
+import edu.rpi.cs.yacs.models.Department;%0A
 import e
@@ -618,67 +618,182 @@
 ll;%0A
-%0A    public SchoolsAdapter(final List%3CSchool%3E schoolList) %7B
+    private RecyclerView recyclerView = null;%0A%0A    public SchoolsAdapter(final RecyclerView recyclerView, List%3CSchool%3E schoolList) %7B%0A        this.recyclerView = recyclerView;
 %0A   
@@ -1771,16 +1771,22 @@
  holder,
+ final
  int sec
@@ -1819,29 +1819,27 @@
     
-String departmentName
+final School school
  = s
@@ -1864,202 +1864,742 @@
 ion)
-.getDepartments().get(position).getName();%0A        String departmentCode = schoolList.get(section).getDepartments().get(position).getCode();%0A%0A        holder.render(departmentName, departmentCode
+;%0A        final Department department = school.getDepartments().get(position);%0A%0A        holder.render(department.getName(), department.getCode());%0A%0A        holder.itemView.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                Log.d(%22Adapter%22, %22Clicked%22);%0A%0A                v.postDelayed(new Runnable() %7B%0A                    @Override%0A                    public void run() %7B%0A                        schoolList.clear();%0A%0A                        recyclerView.getRecycledViewPool().clear();%0A                        recyclerView.removeAllViews();%0A%0A                        notifyDataSetChanged();%0A                    %7D%0A                %7D, 500);%0A            %7D%0A        %7D
 );%0A 

Modify SchoolsAdapter ViewHolder