Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanGroupsListAdapter.java
1 /* VorlesungsplanGroupsListAdapter.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.LinearLayout;
23 import android.widget.TextView;
24
25 import java.util.ArrayList;
26
27 import de.dhbwloe.campusapp.CampusAppContext;
28 import de.dhbwloe.campusapp.R;
29
30 /**
31  * Created by pk910 on 20.02.2016.
32  */
33 public class VorlesungsplanGroupsListAdapter extends ArrayAdapter<VorlesungsplanGroupsListItem> {
34     private Context context;
35     private int layoutResourceId;
36     private ArrayList<VorlesungsplanGroupsListItem> data = new ArrayList<VorlesungsplanGroupsListItem>();
37
38     public VorlesungsplanGroupsListAdapter(Context context, int layoutResourceId, ArrayList<VorlesungsplanGroupsListItem> data) {
39         super(context, layoutResourceId, data);
40         this.layoutResourceId = layoutResourceId;
41         this.context = context;
42         this.data = data;
43     }
44
45     @Override
46     public View getView(int position, View convertView, ViewGroup parent) {
47         View row = convertView;
48         RecordHolder holder = null;
49
50         if (row == null) {
51             LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
52             row = inflater.inflate(layoutResourceId, parent, false);
53
54             holder = new RecordHolder(row);
55             row.setTag(holder);
56         } else {
57             holder = (RecordHolder) row.getTag();
58         }
59
60         final VorlesungsplanGroupsListAdapter that = this;
61         final VorlesungsplanGroupsListItem item = data.get(position);
62
63         holder.groupName.setText(item.getGroupName());
64         holder.nextEvent.setText(item.getNextEvent());
65         holder.lastEvent.setText(item.getLastEvent());
66
67         String klausurDate = item.getNextKlausurEvent();
68         if(klausurDate == null)
69             klausurDate = CampusAppContext.getInstance().getResString(R.string.vorlesungsplan_groups_noklausur);
70
71         holder.klausurEvent.setText(klausurDate);
72         
73         return row;
74     }
75
76     static class RecordHolder {
77         TextView groupName;
78         TextView nextEvent;
79         TextView lastEvent;
80         TextView klausurEvent;
81         TextView klausurName;
82
83         public RecordHolder(View view) {
84             this.groupName = (TextView) view.findViewById(R.id.courseTitle);
85             this.nextEvent = (TextView) view.findViewById(R.id.nextEvent);
86             this.lastEvent = (TextView) view.findViewById(R.id.lastEvent);
87             this.klausurEvent = (TextView) view.findViewById(R.id.klausurEvent);
88             this.klausurName = (TextView) view.findViewById(R.id.klausurName);
89         }
90     }
91 }