Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / VorlesungsplanExams.java
1 /* VorlesungsplanExams.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.os.Bundle;
18 import android.support.v4.app.Fragment;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.ListView;
23
24 import java.util.ArrayList;
25 import java.util.Date;
26
27 import de.dhbwloe.campusapp.CampusAppFragment;
28 import de.dhbwloe.campusapp.R;
29 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
30 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
31
32 /**
33  * A simple {@link Fragment} subclass.
34  */
35 public class VorlesungsplanExams extends CampusAppFragment implements Vorlesungsplan.VorlesungsplanFragment {
36     private String coursename;
37     private View view;
38     private VorlesungsplanExamsListAdapter listAdapter;
39     private ArrayList<VorlesungsplanExamsListItem> listItems = new ArrayList<VorlesungsplanExamsListItem>();
40
41     public VorlesungsplanExams() {
42         // Required empty public constructor
43     }
44
45
46     @Override
47     public View onCreateView(LayoutInflater inflater, ViewGroup container,
48                              Bundle savedInstanceState) {
49         String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
50         if(kursTag == null || kursTag.isEmpty())
51             return null;
52         coursename = kursTag;
53
54         view = inflater.inflate(R.layout.fragment_vorlesungsplan_exams, container, false);
55
56         ListView listView = (ListView) view.findViewById(R.id.listView);
57         listAdapter = new VorlesungsplanExamsListAdapter(view.getContext(), R.layout.fragment_vorlesungsplan_exams_exam, listItems);
58         listView.setAdapter(listAdapter);
59
60         return view;
61     }
62
63     @Override
64     public void setActive() {
65
66     }
67
68     @Override
69     public void onResume() {
70         super.onResume();
71         if(coursename != null)
72             updateCoursesList();
73     }
74
75     private void updateCoursesList() {
76         long now = (new Date()).getTime()/1000;
77
78         CourseEvent[] events = AppContext.getDatabaseManager().getCourseExamEvents(coursename, now, now + (86400 * 30 * 6)); // next 6 month
79         listItems.clear();
80         for(CourseEvent event : events) {
81
82             VorlesungsplanExamsListItem item = new VorlesungsplanExamsListItem(
83                     event.getEventId(),
84                     coursename,
85                     event.getEventTitle(),
86                     event.getEventLocation(),
87                     event.getEventFrom(),
88                     event.getEventTo(),
89                     1
90             );
91             listItems.add(item);
92         }
93         if(listAdapter != null)
94             listAdapter.notifyDataSetChanged();
95     }
96
97 }