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.graphics.Bitmap;
18 import android.graphics.BitmapFactory;
19 import android.graphics.Point;
20 import android.os.Bundle;
21 import android.os.Handler;
22 import android.support.v4.app.Fragment;
23 import android.view.Display;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ImageView;
28 import android.widget.ProgressBar;
29 import android.widget.TextView;
31 import java.util.Date;
33 import de.dhbwloe.campusapp.CampusApp;
34 import de.dhbwloe.campusapp.CampusAppContext;
35 import de.dhbwloe.campusapp.CampusAppFragment;
36 import de.dhbwloe.campusapp.R;
37 import de.dhbwloe.campusapp.coursenames.CourseNameManager;
38 import de.dhbwloe.campusapp.coursenames.CourseNameManagerInterface;
39 import de.dhbwloe.campusapp.mensaplan.MensaplanManager;
40 import de.dhbwloe.campusapp.mensaplan.MensaplanManagerInterface;
41 import de.dhbwloe.campusapp.news.NewsManager;
42 import de.dhbwloe.campusapp.news.NewsManagerInterface;
43 import de.dhbwloe.campusapp.search.SearchIndices;
44 import de.dhbwloe.campusapp.vorlesungen.CalendarManager;
45 import de.dhbwloe.campusapp.vorlesungen.CalendarManagerInterface;
46 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
47 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
50 * A simple {@link Fragment} subclass.
52 public class SplashScreen extends CampusAppFragment {
53 private static final boolean PARALLELIZE_SPLASHTASKS = true;
55 private ProgressBar splashProgress;
56 private int progressCounter;
57 private Handler timerHandler = new Handler();
58 private Runnable timerRunnable;
61 public void onCreate(Bundle savedInstanceState) {
62 super.onCreate(savedInstanceState);
68 public void onSaveInstanceState(Bundle savedInstanceState) {
69 timerHandler.removeCallbacksAndMessages(null);
70 super.onSaveInstanceState(savedInstanceState);
74 public View onCreateView(LayoutInflater inflater, ViewGroup container,
75 Bundle savedInstanceState) {
76 View view = inflater.inflate(R.layout.fragment_splashscreen, container, false);
78 TextView versionView = (TextView) view.findViewById(R.id.version);
79 versionView.setText(CampusAppContext.APPVERSION);
81 splashProgress = (ProgressBar)view.findViewById(R.id.splashProgress);
82 splashProgress.setMax(20);
83 splashProgress.setProgress(0);
86 AppContext.setTitle("DHBW Lörrach");
88 timerRunnable = new Runnable() {
92 splashProgress.setProgress(progressCounter);
93 long now = (new Date()).getTime()/1000;
94 switch(progressCounter) {
96 AppContext.getDatabaseManager().initializeDatabase();
99 AppContext.addDefaultSearchIndexes();
102 String lastCNSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastCNSync");
104 if(lastCNSyncStr != null)
105 lastCNSync = Long.parseLong(lastCNSyncStr);
109 CourseNameManager cnm = new CourseNameManager();
111 if(lastCNSync == 0 || now - lastCNSync > (86400 * 7)) { //sync every 7 days
112 cnm.synchronizeCourseNames(new CourseNameManagerInterface() {
114 public void onCourseNamesSynchronized() {
115 long now = (new Date()).getTime() / 1000;
116 AppContext.getDatabaseManager().setRuntimeCache("LastCNSync", Long.toString(now));
117 timerHandler.postDelayed(timerRunnable, 100);
121 public void onCourseNamesFailed(String errorMessage) {
122 timerHandler.postDelayed(timerRunnable, 100);
131 String startCounter = AppContext.getDatabaseManager().getRuntimeCache("AppStartCounter");
132 if(startCounter == null || Integer.parseInt(startCounter) == 0) {
133 AppContext.getNavigationManager().navigatePage("FirstRun", null, false);
136 AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", Integer.toString(Integer.parseInt(startCounter) + 1));
139 String lastVLMFullSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMFullSync");
140 String lastVLMPartialSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMPartialSync");
141 long lastVLMFullSync, lastVLMPartialSync;
142 if(lastVLMFullSyncStr != null)
143 lastVLMFullSync = Long.parseLong(lastVLMFullSyncStr);
146 if(lastVLMPartialSyncStr != null)
147 lastVLMPartialSync = Long.parseLong(lastVLMPartialSyncStr);
149 lastVLMPartialSync = 0;
151 final String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
152 if(kursTag == null || kursTag.isEmpty())
154 CalendarManager vpm = new CalendarManager(AppContext, kursTag);
156 if(lastVLMFullSync == 0 || now - lastVLMFullSync > (86400 * 14)) { // full sync every 14 days
157 vpm.performFullSynchronisation(new CalendarManagerInterface() {
159 public void onCalendarUpdateDone() {
160 if(!AppContext.getDatabaseManager().haveCourseName(kursTag)) {
161 CourseNameManager cnm = new CourseNameManager();
162 cnm.addCourseName(kursTag);
165 long now = (new Date()).getTime() / 1000;
166 AppContext.getDatabaseManager().setRuntimeCache("LastVLMFullSync", Long.toString(now));
167 AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now));
168 timerHandler.postDelayed(timerRunnable, 100);
172 public void onCalendarUpdateFail(String errorMessage) {
173 timerHandler.postDelayed(timerRunnable, 100);
176 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
177 CourseGroup group = event.getCourseGroup();
178 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
179 indices.setUpdateTime(event.getEventFrom());
180 indices.setTarget("#Vorlesungsplan#groupid=" + group.getGroupId());
181 indices.setTitle("Vorlesungsplan " + event.getCourseName());
182 indices.setDescription("Vorlesung " + event.getEventTitle());
183 indices.addKeyWord(event.getGroupTitle());
184 indices.addKeyWord(event.getEventLocation());
189 else if(lastVLMPartialSync == 0 || now - lastVLMPartialSync > (86400)) { // partial sync every day
190 vpm.performFastSynchronisation(new CalendarManagerInterface() {
192 public void onCalendarUpdateDone() {
193 if(!AppContext.getDatabaseManager().haveCourseName(kursTag)) {
194 CourseNameManager cnm = new CourseNameManager();
195 cnm.addCourseName(kursTag);
198 long now = (new Date()).getTime()/1000;
199 AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now));
200 timerHandler.postDelayed(timerRunnable, 100);
203 public void onCalendarUpdateFail(String errorMessage) {
204 timerHandler.postDelayed(timerRunnable, 100);
207 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
208 CourseGroup group = event.getCourseGroup();
209 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
210 indices.setUpdateTime(event.getEventFrom());
211 indices.setTarget("#Vorlesungsplan#groupid=" + group.getGroupId());
212 indices.setTitle(AppContext.getResString(R.string.search_vorlesungsplan_group_title, event.getCourseName()));
213 indices.setDescription(event.getEventTitle());
214 indices.addKeyWord(event.getGroupTitle());
215 indices.addKeyWord(event.getEventLocation());
224 String lastMPMSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastMPSync");
226 if(lastMPMSyncStr != null)
227 lastMPMSync = Long.parseLong(lastMPMSyncStr);
231 MensaplanManager mpm = new MensaplanManager(AppContext);
233 if(lastMPMSync == 0 || now - lastMPMSync > (86400 * 2)) { //sync every 2 days
234 mpm.performSynchronisation(new MensaplanManagerInterface() {
236 public void onMensaplanUpdateDone() {
237 long now = (new Date()).getTime() / 1000;
238 AppContext.getDatabaseManager().setRuntimeCache("LastMPSync", Long.toString(now));
239 timerHandler.postDelayed(timerRunnable, 100);
243 public void onMensaplanUpdateFail(String errorMessage) {
244 timerHandler.postDelayed(timerRunnable, 100);
253 final String syncSource = (progressCounter == 7 ? "DHBW" : "STUV");
254 String lastNewsSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastNewsSync_"+syncSource);
256 if(lastNewsSyncStr != null)
257 lastNewsSync = Long.parseLong(lastNewsSyncStr);
261 NewsManager nm = new NewsManager(AppContext, syncSource);
263 if(lastNewsSync == 0 || now - lastNewsSync > (86400 * 1)) { //sync every day
264 nm.performSynchronisation(new NewsManagerInterface() {
266 public void onNewsUpdateDone() {
267 long now = (new Date()).getTime() / 1000;
268 AppContext.getDatabaseManager().setRuntimeCache("LastNewsSync_"+syncSource, Long.toString(now));
269 timerHandler.postDelayed(timerRunnable, 100);
273 public void onNewsUpdateFail(String errorMessage) {
274 timerHandler.postDelayed(timerRunnable, 100);
282 String lastStuvSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastStuvSync");
284 if(lastStuvSyncStr != null)
285 lastStuvSync = Long.parseLong(lastStuvSyncStr);
289 final String calendarName = "STUV";
290 CalendarManager stuvsyncmgr = new CalendarManager(AppContext, calendarName);
292 if(lastStuvSync == 0 || now - lastStuvSync > (86400 * 3)) { // full sync every 3 days
293 stuvsyncmgr.performFullSynchronisation(new CalendarManagerInterface() {
295 public void onCalendarUpdateDone() {
296 long now = (new Date()).getTime() / 1000;
297 AppContext.getDatabaseManager().setRuntimeCache("LastStuvSync", Long.toString(now));
298 timerHandler.postDelayed(timerRunnable, 100);
302 public void onCalendarUpdateFail(String errorMessage) {
303 timerHandler.postDelayed(timerRunnable, 100);
307 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
308 CourseGroup group = event.getCourseGroup();
309 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
310 indices.setUpdateTime(event.getEventFrom());
311 indices.setTarget("#News#showevent=" + group.getGroupId() + "&course=" + calendarName);
312 indices.setTitle(calendarName+" Event: " + event.getCourseName());
313 indices.setDescription(event.getEventTitle());
314 indices.addKeyWord(event.getGroupTitle());
315 indices.addKeyWord(event.getEventLocation());
325 // some more tasks to do here?
328 ((CampusApp)AppContext.getMainActivity()).loadMainUi();
329 AppContext.getNavigationManager().navigatePage("Dashboard", null, false);
332 timerHandler.postDelayed(timerRunnable, 100);
340 public void onResume() {
342 timerHandler.postDelayed(timerRunnable, 500);