Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanExamsListAdapter.java
1 /* VorlesungsplanExamsListAdapter.java
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 package de.dhbwloe.campusapp.fragments;
17 import android.content.Context;
18 import android.view.LayoutInflater;
19 import android.view.View;
20 import android.view.ViewGroup;
21 import android.widget.ArrayAdapter;
22 import android.widget.TextView;
23
24 import java.util.ArrayList;
25
26 import de.dhbwloe.campusapp.CampusAppContext;
27 import de.dhbwloe.campusapp.R;
28
29 /**
30  * Created by pk910 on 27.02.2016.
31  */
32 public class VorlesungsplanExamsListAdapter extends ArrayAdapter<VorlesungsplanExamsListItem> {
33     private Context context;
34     private int layoutResourceId;
35     private ArrayList<VorlesungsplanExamsListItem> data = new ArrayList<VorlesungsplanExamsListItem>();
36
37     public VorlesungsplanExamsListAdapter(Context context, int layoutResourceId, ArrayList<VorlesungsplanExamsListItem> data) {
38             super(context, layoutResourceId, data);
39             this.layoutResourceId = layoutResourceId;
40             this.context = context;
41             this.data = data;
42             }
43
44     @Override
45     public View getView(int position, View convertView, ViewGroup parent) {
46             View row = convertView;
47             RecordHolder holder = null;
48
49             if (row == null) {
50             LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
51             row = inflater.inflate(layoutResourceId, parent, false);
52
53             holder = new RecordHolder(row);
54             row.setTag(holder);
55             } else {
56             holder = (RecordHolder) row.getTag();
57             }
58
59     final VorlesungsplanExamsListAdapter that = this;
60     final VorlesungsplanExamsListItem item = data.get(position);
61
62             holder.groupName.setText(item.getGroupName());
63             holder.eventDate.setText(item.getEventDate());
64             holder.eventStart.setText(item.getEventStart());
65             holder.eventEnd.setText(item.getEventEnd());
66             holder.eventLocation.setText(item.getEventLocation());
67
68             return row;
69             }
70
71     static class RecordHolder {
72         TextView groupName;
73         TextView eventDate;
74         TextView eventLocation;
75         TextView eventStart;
76         TextView eventEnd;
77
78         public RecordHolder(View view) {
79             this.groupName = (TextView) view.findViewById(R.id.courseTitle);
80             this.eventDate = (TextView) view.findViewById(R.id.eventDate);
81             this.eventLocation = (TextView) view.findViewById(R.id.eventLocation);
82             this.eventStart = (TextView) view.findViewById(R.id.eventStart);
83             this.eventEnd = (TextView) view.findViewById(R.id.eventEnd);
84         }
85     }
86 }