Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / Dashboard.java
1 /* Dashboard.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 de.dhbwloe.campusapp.CampusAppFragment;
18
19 import android.os.Bundle;
20 import android.support.v4.app.Fragment;
21 import android.support.v4.app.FragmentTransaction;
22 import android.support.v7.widget.CardView;
23 import android.view.InflateException;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ImageView;
28
29 import de.dhbwloe.campusapp.R;
30 import de.dhbwloe.campusapp.search.SearchIndices;
31
32 public class Dashboard extends CampusAppFragment {
33     private static View view;
34     /* implement this for search results ;) */
35     public static SearchIndices[] GetSearchIndices() {
36         return new SearchIndices[] {
37                 new SearchIndices("Dashboard", true) {{
38                     setUpdateTime(1);
39                     setTarget("#Dashboard");
40                     setTitle(R.string.search_dashboard_title);
41                     setDescription(R.string.search_dashboard_description);
42                     addKeyWord(R.string.search_dashboard_keywords);
43                 }},
44         };
45     }
46
47
48     @Override
49     public void onCreate(Bundle savedInstanceState) {
50         super.onCreate(savedInstanceState);
51     }
52
53     @Override
54     public View onCreateView(LayoutInflater inflater, ViewGroup container,
55                              Bundle savedInstanceState) {
56         if (view != null) {
57             ViewGroup parent = (ViewGroup) view.getParent();
58             if (parent != null)
59                 parent.removeView(view);
60         }
61
62         try {
63             view = inflater.inflate(R.layout.fragment_dashboard, container, false);
64         } catch (InflateException e) {
65             if(view == null)
66                 return null;
67         }
68         AppContext.setTitle(AppContext.getResString(R.string.dashboard_title));
69
70         String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
71         if(kursTag == null || kursTag.isEmpty()) {
72             CardView timetable = (CardView) view.findViewById(R.id.card_timetable);
73             timetable.setVisibility(View.GONE);
74         }
75
76         ImageView image;
77         image = (ImageView)view.findViewById(R.id.timetable_image);
78         image.setOnClickListener(new View.OnClickListener() {
79             @Override
80             public void onClick(View v) {
81                 AppContext.getNavigationManager().navigatePage("Vorlesungsplan");
82             }
83         });
84
85         image = (ImageView)view.findViewById(R.id.mensa_image);
86         image.setOnClickListener(new View.OnClickListener() {
87             @Override
88             public void onClick(View v) {
89                 AppContext.getNavigationManager().navigatePage("Mensa");
90             }
91         });
92
93         image = (ImageView)view.findViewById(R.id.news_dhbw_image);
94         image.setOnClickListener(new View.OnClickListener() {
95             @Override
96             public void onClick(View v) {
97                 AppContext.getNavigationManager().navigatePage("News");
98             }
99         });
100
101         image = (ImageView)view.findViewById(R.id.news_stuv_image);
102         image.setOnClickListener(new View.OnClickListener() {
103             @Override
104             public void onClick(View v) {
105                 AppContext.getNavigationManager().navigatePage("News");
106             }
107         });
108
109         return view;
110     }
111 }