package com.thebluealliance.androidclient.adapters;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import com.thebluealliance.androidclient.interfaces.RenderableModel;
import com.thebluealliance.androidclient.listitems.LabelValueListItem;
import com.thebluealliance.androidclient.listitems.ListGroup;
import com.thebluealliance.androidclient.listitems.ListItem;
import com.thebluealliance.androidclient.models.Match;
import com.thebluealliance.androidclient.renderers.ModelRendererSupplier;

import java.util.List;

public class MatchListAdapter extends ExpandableListViewAdapter {

    private String mTeamKey;

    public MatchListAdapter(
      Activity a,
      ModelRendererSupplier supplier,
      List<ListGroup> groups,
      String selectedTeam) {
        super(a, supplier, groups);
        mTeamKey = selectedTeam;
    }

    public void setTeamKey(String teamKey) {
        if (teamKey != null) {
            mTeamKey = teamKey;
        }
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        RenderableModel child = mGroups.get(groupPosition).children.get(childPosition);
        if (child instanceof Match) {
            ((Match) child).setSelectedTeam(mTeamKey);
        }
        ListItem renderedChild = child.render(mRendererSupplier);
        if (renderedChild != null) {
            return renderedChild.getView(mActivity, mInflater, convertView);
        } else {
            return new LabelValueListItem("Match", "Unable to render").getView(mActivity, mInflater, convertView);
        }
    }
}

@@ -50,95 +50,8 @@
 s;%0A%0A
-import android.app.Activity;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0A%0A
 impo
@@ -115,16 +115,16 @@
 eModel;%0A
+
 import c
@@ -439,16 +439,103 @@
 plier;%0A%0A
+import android.app.Activity;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0A%0A
 import j
@@ -1006,16 +1006,16 @@
 verride%0A
-
     publ
@@ -1128,24 +1128,324 @@
 p parent) %7B%0A
+        if (groupPosition %3E= mGroups.size()%0A                %7C%7C childPosition %3E= mGroups.get(groupPosition).children.size()) %7B%0A            // Can't render due to bounds errors%0A            return new LabelValueListItem(%22Match%22, %22Unable to render%22).getView(mActivity, mInflater, convertView);%0A        %7D%0A
         Rend

Fix MatchListAdapter Bounds errors