Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / Vorlesungsplan.java
index 6428e632c009c8493e258decd4fdffdb4e3733b7..14a82dbf69af5473f61ea06496d396fa9a4803b4 100644 (file)
@@ -1,6 +1,19 @@
+/* Vorlesungsplan.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
 package de.dhbwloe.campusapp.fragments;
-
-
 import android.os.Bundle;
 import android.support.design.widget.TabLayout;
 import android.support.v4.app.Fragment;
@@ -10,6 +23,9 @@ import android.support.v4.view.ViewPager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -17,9 +33,12 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
+import de.dhbwloe.campusapp.CampusAppContext;
 import de.dhbwloe.campusapp.CampusAppFragment;
 import de.dhbwloe.campusapp.R;
 import de.dhbwloe.campusapp.search.SearchIndices;
+import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
+import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
 
 /**
  * A simple {@link Fragment} subclass.
@@ -35,31 +54,59 @@ public class Vorlesungsplan extends CampusAppFragment {
                 new SearchIndices("Vorlesungsplan", true) {{
                     setUpdateTime(1);
                     setTarget("#Vorlesungsplan");
-                    setTitle("Vorlesungsplan");
-                    setDescription("Vorlesungsplan dienes Kurses");
-                    addKeyWord("vorlesung, vorlesungen, plan, vorlesungsplan, stundenplan, termin, termine, kursplan, blockplan, block, zeit, zeiten");
+                    setTitle(R.string.search_vorlesungsplan_title);
+                    setDescription(R.string.search_vorlesungsplan_description);
+                    addKeyWord(R.string.search_vorlesungsplan_keywords);
                 }},
-                new SearchIndices("Vorlesungsplan", true) {{
+                new SearchIndices("VorlesungsplanExams", true) {{
                     setUpdateTime(1);
                     setTarget("#Vorlesungsplan#view=exams");
-                    setTitle("Vorlesungsplan");
-                    setDescription("Klausurübersicht dienes Kurses");
-                    addKeyWord("klausuren, prüfungen, exams, termine, zeitpunkt, plan, ergebnisse");
+                    setTitle(R.string.search_vorlesungsplan_klausur_title);
+                    setDescription(R.string.search_vorlesungsplan_klausur_description);
+                    addKeyWord(R.string.search_vorlesungsplan_klausur_keywords);
                 }},
         };
     }
 
     @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                             Bundle savedInstanceState) {
-        View view = inflater.inflate(R.layout.fragment_vorlesungsplan, container, false);
-        AppContext.setTitle("Vorlesungsplan");
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        Bundle arguments = getArguments();
+        int showGroupId = 0;
+        boolean showExamsPage = false;
+        if(arguments != null) {
+            String groupid = arguments.getString("groupid");
+            if(groupid != null)
+                showGroupId = Integer.parseInt(groupid);
+            String view = arguments.getString("view");
+            if(view != null && view.equalsIgnoreCase("exams"))
+                showExamsPage = true;
+        }
+
+        View view = null;
+        if(showGroupId > 0) {
+            view = inflater.inflate(R.layout.fragment_vorlesungsplan_group, container, false);
+
+            CourseGroup group = AppContext.getDatabaseManager().getCourseGroup(showGroupId);
+            if(group != null) {
+                AppContext.setTitle(AppContext.getResString(R.string.vorlesungsplan_group_title, group.getGroupName()));
+
+                showGroupEvents(view, group);
+            } else
+                view = null;
+        }
+        if(view == null) {
+            view = inflater.inflate(R.layout.fragment_vorlesungsplan, container, false);
+            AppContext.setTitle(AppContext.getResString(R.string.vorlesungsplan_title));
 
-        ViewPager pager = (ViewPager) view.findViewById(R.id.viewpager);
-        setupViewPager(pager);
+            ViewPager pager = (ViewPager) view.findViewById(R.id.viewpager);
+            setupViewPager(pager);
 
-        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
-        tabLayout.setupWithViewPager(pager);
+            if(showExamsPage)
+                pager.setCurrentItem(2);
+
+            TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
+            tabLayout.setupWithViewPager(pager);
+        }
 
         return view;
     }
@@ -97,6 +144,81 @@ public class Vorlesungsplan extends CampusAppFragment {
         });
     }
 
+    private void showGroupEvents(View view, CourseGroup group) {
+        CourseEvent events[] = AppContext.getDatabaseManager().getCourseEventsByGroup(group);
+
+        CourseEvent nextEvent = null;
+        CourseEvent lastEvent = null;
+        CourseEvent examEvent = null;
+        long now = (new Date()).getTime()/1000;
+        SimpleDateFormat dateFormat = new SimpleDateFormat(AppContext.getResString(R.string.timeformat_vorlesungsplan_fulldate));
+
+        LinearLayout container = (LinearLayout) view.findViewById(R.id.allEventsList);
+        TextView groupName = (TextView) view.findViewById(R.id.courseTitle);
+        TextView nextEventView = (TextView) view.findViewById(R.id.nextEvent);
+        TextView lastEventView = (TextView) view.findViewById(R.id.lastEvent);
+        TextView examEventView = (TextView) view.findViewById(R.id.klausurEvent);
+
+        groupName.setText(group.getGroupName());
+        container.removeAllViews();
+
+        for(CourseEvent event : events) {
+            if(event.getEventFrom() >= now && nextEvent == null)
+                nextEvent = event;
+            if(event.getCourseType() == CourseEvent.CourseType.COURSETYPE_KLAUSUR)
+                examEvent = event;
+            else
+                lastEvent = event;
+
+            LinearLayout eventEntry = new LinearLayout(view.getContext());
+            eventEntry.setLayoutParams(new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
+                    RelativeLayout.LayoutParams.WRAP_CONTENT));
+            eventEntry.setOrientation(LinearLayout.HORIZONTAL);
+
+            TextView dotView = new TextView(view.getContext());
+            dotView.setText(AppContext.getResString(R.string.listDot));
+            eventEntry.addView(dotView);
+
+            if(event.getEventFrom() < now)
+                dotView.setTextColor(AppContext.getMainActivity().getResources().getColor(R.color.color_dhbw_lightgray));
+            else
+                dotView.setTextColor(AppContext.getMainActivity().getResources().getColor(R.color.color_dhbw_darkred));
+
+            TextView nameView = new TextView(view.getContext());
+            LinearLayout.LayoutParams nameViewLayoutParams = new LinearLayout.LayoutParams(
+                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
+            nameViewLayoutParams.setMargins(16,0,0,0);
+            nameView.setLayoutParams(nameViewLayoutParams);
+            nameView.setText(dateFormat.format(new Date(event.getEventFrom() * 1000)));
+            eventEntry.addView(nameView);
+
+            TextView locationView = new TextView(view.getContext());
+            LinearLayout.LayoutParams locationViewLayoutParams = new LinearLayout.LayoutParams(
+                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
+            locationViewLayoutParams.setMargins(32,0,0,0);
+            locationView.setLayoutParams(locationViewLayoutParams);
+            locationView.setText(event.getEventLocation());
+            eventEntry.addView(locationView);
+
+            container.addView(eventEntry);
+        }
+
+        if(nextEvent != null)
+            nextEventView.setText(dateFormat.format(new Date(nextEvent.getEventFrom() * 1000)));
+        else
+            nextEventView.setText(CampusAppContext.getInstance().getResString(R.string.vorlesungsplan_groups_nonext));
+
+        if(lastEvent != null)
+            lastEventView.setText(dateFormat.format(new Date(lastEvent.getEventFrom() * 1000)));
+        else
+            lastEventView.setText(CampusAppContext.getInstance().getResString(R.string.vorlesungsplan_groups_nonext));
+
+        if(examEvent != null)
+            examEventView.setText(dateFormat.format(new Date(examEvent.getEventFrom() * 1000)));
+        else
+            examEventView.setText(CampusAppContext.getInstance().getResString(R.string.vorlesungsplan_groups_noklausur));
+    }
+
     class ViewPagerAdapter extends FragmentPagerAdapter {
         private final List<Fragment> mFragmentList = new ArrayList<>();
         private final List<String> mFragmentTitleList = new ArrayList<>();