1 /* VorlesungsplanGroups.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.os.Bundle;
18 import android.support.v4.app.Fragment;
19 import android.text.method.CharacterPickerDialog;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.AdapterView;
24 import android.widget.CheckBox;
25 import android.widget.CompoundButton;
26 import android.widget.ListView;
28 import java.util.ArrayList;
29 import java.util.Date;
31 import de.dhbwloe.campusapp.CampusAppFragment;
32 import de.dhbwloe.campusapp.R;
33 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
36 * A simple {@link Fragment} subclass.
38 public class VorlesungsplanGroups extends CampusAppFragment implements Vorlesungsplan.VorlesungsplanFragment {
39 private String coursename;
41 private VorlesungsplanGroupsListAdapter listAdapter;
42 private ArrayList<VorlesungsplanGroupsListItem> listItems = new ArrayList<VorlesungsplanGroupsListItem>();
43 private boolean showOldCourses = false;
45 public VorlesungsplanGroups() {
46 // Required empty public constructor
51 public View onCreateView(LayoutInflater inflater, ViewGroup container,
52 Bundle savedInstanceState) {
53 String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
54 if(kursTag == null || kursTag.isEmpty())
58 view = inflater.inflate(R.layout.fragment_vorlesungsplan_groups, container, false);
60 ListView listView = (ListView) view.findViewById(R.id.listView);
61 listAdapter = new VorlesungsplanGroupsListAdapter(view.getContext(), R.layout.fragment_vorlesungsplan_groups_course, listItems);
62 listView.setAdapter(listAdapter);
64 CheckBox showOldChkBox = (CheckBox) view.findViewById(R.id.showOldCourses);
65 showOldChkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
67 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
68 showOldCourses = isChecked;
73 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
75 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
76 VorlesungsplanGroupsListItem item = listItems.get(position);
78 Bundle args = new Bundle();
79 args.putString("groupid", Integer.toString(item.getGroupId()));
80 AppContext.getNavigationManager().navigatePage("Vorlesungsplan", args);
88 public void setActive() {
94 public void onResume() {
96 if(coursename != null)
100 private void updateCoursesList() {
105 notBefore = new Date();
107 CourseGroup[] groups = AppContext.getDatabaseManager().getCourseGroups(coursename, notBefore);
109 for(CourseGroup group : groups) {
110 Bundle extraData = group.getExtraData();
111 long nextKlausur = extraData.getLong("NextKlausurEvent");
112 long lastEvent = extraData.getLong("LastEvent");
114 // wenn nextKlausur über 5 jahrevon LastEvent entfernt liegt gibt es in diesem kurs KEINE Klausur.
115 // der fiktive Wert musste zur technischen funktionalität der Datenbankabfrage eingefügt werden.
116 if(nextKlausur - lastEvent > (86400 * 365 * 5))
119 VorlesungsplanGroupsListItem item = new VorlesungsplanGroupsListItem(
122 group.getGroupName(),
123 extraData.getLong("FirstEvent"),
125 extraData.getInt("EventCount"),
126 extraData.getLong("NextEvent"),
131 if(listAdapter != null)
132 listAdapter.notifyDataSetChanged();