1 /* VorlesungsplanUpcomingDayListItem.java
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.
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.
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/>.
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;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.Date;
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;
36 * Created by pk910 on 20.02.2016.
38 public class VorlesungsplanUpcomingDayListItem {
39 private long cardDate;
40 private ArrayList<VorlesungsplanUpcomingCourseListItem> courses = new ArrayList<VorlesungsplanUpcomingCourseListItem>();
42 public VorlesungsplanUpcomingDayListItem(long date) {
46 public void addCourseEventsToContainer(LinearLayout container) {
47 int courseEntries = container.getChildCount();
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);
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);
63 for(;i < courseEntries; i++) {
64 View child = container.getChildAt(i);
65 child.setVisibility(View.GONE);
69 public String getFormatedDate() {
70 SimpleDateFormat dateFormat = new SimpleDateFormat(CampusAppContext.getInstance().getResString(R.string.timeformat_vorlesungsplan_date));
71 Date date = new Date(cardDate * 1000);
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();
76 int dow = cal.get(Calendar.DAY_OF_WEEK)-1;
78 return CampusAppContext.getInstance().getResString(weekdayResIds[dow]) + ", " + dateFormat.format(date);
81 public void addCourseEvent(CourseEvent event) {
82 VorlesungsplanUpcomingCourseListItem courseItem = new VorlesungsplanUpcomingCourseListItem(event);
83 courses.add(courseItem);