beta 0.1.5
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / MensaTagesplanListAdapter.java
1 /* MensaTagesplanListAdapter.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.R;
27 import de.dhbwloe.campusapp.mensaplan.*;
28
29 /**
30  * Created by pk910 on 24.01.2016.
31  */
32
33 public class MensaTagesplanListAdapter  extends ArrayAdapter<de.dhbwloe.campusapp.mensaplan.MensaTagesplan> {
34     private Context context;
35     private int layoutResourceId;
36     private ArrayList<de.dhbwloe.campusapp.mensaplan.MensaTagesplan> data = new ArrayList<de.dhbwloe.campusapp.mensaplan.MensaTagesplan>();
37
38     public MensaTagesplanListAdapter(Context context, int layoutResourceId, ArrayList<de.dhbwloe.campusapp.mensaplan.MensaTagesplan> 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 MensaTagesplanListAdapter that = this;
61         final de.dhbwloe.campusapp.mensaplan.MensaTagesplan item = data.get(position);
62
63         if(holder.txtMenueName != null)
64             holder.txtMenueName.setText(item.getMenuName());
65         if(holder.txtName != null)
66             holder.txtName.setText(item.getName());
67         if(holder.txtPrice != null)
68             holder.txtPrice.setText(item.getFormatedRolePrice());
69
70         return row;
71     }
72
73     static class RecordHolder {
74         TextView txtMenueName;
75         TextView txtName;
76         TextView txtPrice;
77
78         public RecordHolder(View view) {
79             this.txtMenueName = (TextView) view.findViewById(R.id.txtMenueName);
80             this.txtName = (TextView) view.findViewById(R.id.txtName);
81             this.txtPrice = (TextView) view.findViewById(R.id.txtMenuePrice);
82         }
83     }
84 }