Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanUpcomingDayListItem.java
1 /* VorlesungsplanUpcomingDayListItem.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.widget.LinearLayout;
21 import android.widget.ListView;
22 import android.widget.RelativeLayout;
23 import android.widget.TextView;
24
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.Date;
29
30 import de.dhbwloe.campusapp.CampusAppContext;
31 import de.dhbwloe.campusapp.R;
32 import de.dhbwloe.campusapp.Tools;
33 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
34
35 /**
36  * Created by pk910 on 20.02.2016.
37  */
38 public class VorlesungsplanUpcomingDayListItem {
39     private long cardDate;
40     private ArrayList<VorlesungsplanUpcomingCourseListItem> courses = new ArrayList<VorlesungsplanUpcomingCourseListItem>();
41
42     public VorlesungsplanUpcomingDayListItem(long date) {
43         cardDate = date;
44     }
45
46     public void addCourseEventsToContainer(LinearLayout container) {
47         int courseEntries = container.getChildCount();
48
49         CampusAppContext AppContext = CampusAppContext.getInstance();
50         LayoutInflater inflater = (LayoutInflater) AppContext.getMainActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
51         while(courseEntries < courses.size()) {
52             View view = inflater.inflate(R.layout.fragment_vorlesungsplan_upcoming_course, null);
53             container.addView(view);
54             courseEntries++;
55         }
56
57         int i;
58         for(i = 0; i < courses.size(); i++) {
59             View child = container.getChildAt(i);
60             courses.get(i).updateContainerView(child);
61             child.setVisibility(View.VISIBLE);
62         }
63         for(;i < courseEntries; i++) {
64             View child = container.getChildAt(i);
65             child.setVisibility(View.GONE);
66         }
67     }
68
69     public String getFormatedDate() {
70         SimpleDateFormat dateFormat = new SimpleDateFormat(CampusAppContext.getInstance().getResString(R.string.timeformat_vorlesungsplan_date));
71         Date date = new Date(cardDate * 1000);
72
73         int weekdayResIds[] = new int[] { R.string.week_sunday, R.string.week_monday, R.string.week_tuesday, R.string.week_wednesday, R.string.week_thursday, R.string.week_friday,  R.string.week_saturday };
74         Calendar cal = Calendar.getInstance();
75         cal.setTime(date);
76         int dow = cal.get(Calendar.DAY_OF_WEEK)-1;
77
78         return CampusAppContext.getInstance().getResString(weekdayResIds[dow]) + ", " + dateFormat.format(date);
79     }
80
81     public void addCourseEvent(CourseEvent event) {
82         VorlesungsplanUpcomingCourseListItem courseItem = new VorlesungsplanUpcomingCourseListItem(event);
83         courses.add(courseItem);
84     }
85
86 }