Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanUpcomingDayListAdapter.java
1 /* VorlesungsplanUpcomingDayListAdapter.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.ListView;
24 import android.widget.RelativeLayout;
25 import android.widget.TextView;
26
27 import java.util.ArrayList;
28
29 import de.dhbwloe.campusapp.R;
30
31 /**
32  * Created by pk910 on 20.02.2016.
33  */
34 public class VorlesungsplanUpcomingDayListAdapter extends ArrayAdapter<VorlesungsplanUpcomingDayListItem> {
35     private Context context;
36     private int layoutResourceId;
37     private ArrayList<VorlesungsplanUpcomingDayListItem> data = new ArrayList<VorlesungsplanUpcomingDayListItem>();
38
39     public VorlesungsplanUpcomingDayListAdapter(Context context, int layoutResourceId, ArrayList<VorlesungsplanUpcomingDayListItem> data) {
40         super(context, layoutResourceId, data);
41         this.layoutResourceId = layoutResourceId;
42         this.context = context;
43         this.data = data;
44     }
45
46     @Override
47     public View getView(int position, View convertView, ViewGroup parent) {
48         View row = convertView;
49         RecordHolder holder = null;
50
51         if (row == null) {
52             LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
53             row = inflater.inflate(layoutResourceId, parent, false);
54
55             holder = new RecordHolder(row);
56             row.setTag(holder);
57         } else {
58             holder = (RecordHolder) row.getTag();
59         }
60
61         final VorlesungsplanUpcomingDayListAdapter that = this;
62         final VorlesungsplanUpcomingDayListItem item = data.get(position);
63
64         item.addCourseEventsToContainer(holder.container);
65         holder.cardDate.setText(item.getFormatedDate());
66
67         return row;
68     }
69
70     static class RecordHolder {
71         TextView cardDate;
72         LinearLayout container;
73
74         public RecordHolder(View view) {
75             this.cardDate = (TextView) view.findViewById(R.id.cardDate);
76             this.container = (LinearLayout) view.findViewById(R.id.cardCourses);
77         }
78     }
79 }