X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2Ffragments%2FSplashScreen.java;h=6ecc333283d5b63178811c996a3a2a3b2f762063;hb=7b6f5756521e901f06f02623d59daf64b5dd19d6;hp=961a32be18645d312a8ff73a3da63fa60798ff15;hpb=783024077bd38c4bede07ca8310fb2daf67751b5;p=DHBWCampusApp.git diff --git a/app/src/main/java/de/dhbwloe/campusapp/fragments/SplashScreen.java b/app/src/main/java/de/dhbwloe/campusapp/fragments/SplashScreen.java index 961a32b..6ecc333 100644 --- a/app/src/main/java/de/dhbwloe/campusapp/fragments/SplashScreen.java +++ b/app/src/main/java/de/dhbwloe/campusapp/fragments/SplashScreen.java @@ -1,6 +1,19 @@ +/* SplashScreen.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 . + */ package de.dhbwloe.campusapp.fragments; - - import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Point; @@ -13,12 +26,16 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ProgressBar; +import android.widget.TextView; import java.util.Date; import de.dhbwloe.campusapp.CampusApp; +import de.dhbwloe.campusapp.CampusAppContext; import de.dhbwloe.campusapp.CampusAppFragment; import de.dhbwloe.campusapp.R; +import de.dhbwloe.campusapp.coursenames.CourseNameManager; +import de.dhbwloe.campusapp.coursenames.CourseNameManagerInterface; import de.dhbwloe.campusapp.mensaplan.MensaplanManager; import de.dhbwloe.campusapp.mensaplan.MensaplanManagerInterface; import de.dhbwloe.campusapp.news.NewsManager; @@ -33,6 +50,8 @@ import de.dhbwloe.campusapp.vorlesungen.CourseGroup; * A simple {@link Fragment} subclass. */ public class SplashScreen extends CampusAppFragment { + private static final boolean PARALLELIZE_SPLASHTASKS = true; + private ProgressBar splashProgress; private int progressCounter; private Handler timerHandler = new Handler(); @@ -56,6 +75,9 @@ public class SplashScreen extends CampusAppFragment { Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_splashscreen, container, false); + TextView versionView = (TextView) view.findViewById(R.id.version); + versionView.setText(CampusAppContext.APPVERSION); + splashProgress = (ProgressBar)view.findViewById(R.id.splashProgress); splashProgress.setMax(20); splashProgress.setProgress(0); @@ -63,22 +85,6 @@ public class SplashScreen extends CampusAppFragment { AppContext.setTitle("DHBW Lörrach"); - ImageView splashImage = (ImageView)view.findViewById(R.id.splashImage); - BitmapFactory.Options dimensions = new BitmapFactory.Options(); - Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dhbw_campus_hd, dimensions); - int height = dimensions.outHeight; - int width = dimensions.outWidth; - Display display = AppContext.getMainActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - display.getSize(size); - float scaleX = (float)size.x / (float)width; - float scaleY = (float)size.y / (float)height; - float scale = Math.max(scaleX, scaleY); - int newWidth = (int)(width*scale); - int newHeight = (int)(height*scale); - Bitmap newBitmap = Bitmap.createScaledBitmap(mBitmap, newWidth, newHeight, true); - splashImage.setImageBitmap(newBitmap); - timerRunnable = new Runnable() { @Override public void run() { @@ -93,6 +99,35 @@ public class SplashScreen extends CampusAppFragment { AppContext.addDefaultSearchIndexes(); break; case 3: + String lastCNSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastCNSync"); + long lastCNSync; + if(lastCNSyncStr != null) + lastCNSync = Long.parseLong(lastCNSyncStr); + else + lastCNSync = 0; + + CourseNameManager cnm = new CourseNameManager(); + + if(lastCNSync == 0 || now - lastCNSync > (86400 * 7)) { //sync every 7 days + cnm.synchronizeCourseNames(new CourseNameManagerInterface() { + @Override + public void onCourseNamesSynchronized() { + long now = (new Date()).getTime() / 1000; + AppContext.getDatabaseManager().setRuntimeCache("LastCNSync", Long.toString(now)); + timerHandler.postDelayed(timerRunnable, 100); + } + + @Override + public void onCourseNamesFailed(String errorMessage) { + timerHandler.postDelayed(timerRunnable, 100); + } + }); + } + else + break; + + return; + case 4: String startCounter = AppContext.getDatabaseManager().getRuntimeCache("AppStartCounter"); if(startCounter == null || Integer.parseInt(startCounter) == 0) { AppContext.getNavigationManager().navigatePage("FirstRun", null, false); @@ -100,7 +135,7 @@ public class SplashScreen extends CampusAppFragment { } AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", Integer.toString(Integer.parseInt(startCounter) + 1)); break; - case 4: + case 5: String lastVLMFullSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMFullSync"); String lastVLMPartialSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMPartialSync"); long lastVLMFullSync, lastVLMPartialSync; @@ -113,7 +148,7 @@ public class SplashScreen extends CampusAppFragment { else lastVLMPartialSync = 0; - String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName"); + final String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName"); if(kursTag == null || kursTag.isEmpty()) break; CalendarManager vpm = new CalendarManager(AppContext, kursTag); @@ -122,6 +157,11 @@ public class SplashScreen extends CampusAppFragment { vpm.performFullSynchronisation(new CalendarManagerInterface() { @Override public void onCalendarUpdateDone() { + if(!AppContext.getDatabaseManager().haveCourseName(kursTag)) { + CourseNameManager cnm = new CourseNameManager(); + cnm.addCourseName(kursTag); + } + long now = (new Date()).getTime() / 1000; AppContext.getDatabaseManager().setRuntimeCache("LastVLMFullSync", Long.toString(now)); AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now)); @@ -150,6 +190,11 @@ public class SplashScreen extends CampusAppFragment { vpm.performFastSynchronisation(new CalendarManagerInterface() { @Override public void onCalendarUpdateDone() { + if(!AppContext.getDatabaseManager().haveCourseName(kursTag)) { + CourseNameManager cnm = new CourseNameManager(); + cnm.addCourseName(kursTag); + } + long now = (new Date()).getTime()/1000; AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now)); timerHandler.postDelayed(timerRunnable, 100); @@ -175,7 +220,7 @@ public class SplashScreen extends CampusAppFragment { else break; return; - case 5: + case 6: String lastMPMSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastMPSync"); long lastMPMSync; if(lastMPMSyncStr != null) @@ -203,9 +248,9 @@ public class SplashScreen extends CampusAppFragment { else break; return; - case 6: case 7: - final String syncSource = (progressCounter == 6 ? "DHBW" : "STUV"); + case 8: + final String syncSource = (progressCounter == 7 ? "DHBW" : "STUV"); String lastNewsSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastNewsSync_"+syncSource); long lastNewsSync; if(lastNewsSyncStr != null) @@ -233,7 +278,7 @@ public class SplashScreen extends CampusAppFragment { else break; return; - case 8: + case 9: String lastStuvSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastStuvSync"); long lastStuvSync; if(lastStuvSyncStr != null)