sort of worked around the Sunday problem

This commit is contained in:
2019-03-18 19:09:03 +01:00
parent 953185425b
commit a1410f7b80
3 changed files with 23 additions and 6 deletions

View File

@ -45,6 +45,8 @@ import org.mosad.seil0.projectlaogai.controller.CacheController
import org.mosad.seil0.projectlaogai.controller.PreferencesController
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.fragments.*
import java.sql.Date
import java.util.*
import kotlin.system.measureTimeMillis
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
@ -164,15 +166,30 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
PreferencesController.load(this) // this must be finished before doing anything else
val startupTime = measureTimeMillis {
val tcor = TCoRAPIController(this)
val currentTime = System.currentTimeMillis() / 1000
val currentDay = Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
val cal = Calendar.getInstance()
cal.time = Date(timetableCacheTime * 1000)
val timetableCacheDay = cal.get(Calendar.DAY_OF_WEEK)
// if the last update was on moday and now its a sunday, update before displaying the timetable
// TODO this sill backfire if someone has to update before the server finished updateing the timetable at 0001/0101
if(currentDay == Calendar.MONDAY && timetableCacheDay == Calendar.SUNDAY) {
println("updating timetable after sunday!")
val jobA = tcor.getTimetable(cCourse.courseName, 0)
val jobB = tcor.getTimetable(cCourse.courseName, 1)
jobA.get()
jobB.get()
}
// get the cached files
val cache = CacheController(this)
cache.readStartCache(cCourse.courseName)
// check if an update is necessary
val tcor = TCoRAPIController(this)
val currentTime = System.currentTimeMillis() / 1000
if(currentTime - coursesCacheTime > 86400)
tcor.getCoursesList()