@ -36,6 +36,7 @@ import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import org.mosad.seil0.projectlaogai.controller.CacheController
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaMenu
import org.mosad.seil0.projectlaogai.controller.PreferencesController
import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.cColorAccent
import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.cColorPrimary
@ -45,7 +46,6 @@ import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.
import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.timetableCacheTime
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.fragments.*
import java.sql.Date
import java.util.*
import kotlin.system.measureTimeMillis
@ -171,11 +171,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val currentDay = Calendar . getInstance ( ) . get ( Calendar . DAY _OF _WEEK )
val cal = Calendar . getInstance ( )
// timetable sunday workaround
cal . time = Date ( timetableCacheTime * 1000 )
val timetableCacheDay = cal . get ( Calendar . DAY _OF _WEEK )
// TODO this s ill backfire if someone has to update before the server finished updating the timetable at 0001/0101
// TODO this w ill backfire if someone has to update before the server finished updating the timetable at 0001/0101
// update blocking if a) it`s monday and the last cache was not on a monday or b) the cache is older than 6 days
if ( ( currentDay == Calendar . MONDAY && timetableCacheDay != Calendar . MONDAY ) || ( System . currentTimeMillis ( ) / 1000 ) - timetableCacheTime > 518400 ) {
println ( " updating timetable after sunday! " )
@ -186,16 +187,29 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
jobB . get ( )
}
// mensa sunday workaround
cal . time = Date ( System . currentTimeMillis ( ) ) // reset to current time
// update blocking if it's sunday after 1500
// TODO and the last update was before 1500
if ( currentDay == Calendar . SUNDAY && cal . get ( Calendar . HOUR _OF _DAY ) >= 15 ) {
val jobA = TCoRAPIController . getMensa ( this )
jobA . get ( )
// //mensa sunday workaround
// cal.time = Date(System.currentTimeMillis()) // reset to current time
//
// // update blocking if it's sunday after 1500
// if(currentDay == Calendar.SUNDAY && cal.get(Calendar.HOUR_OF_DAY) >= 15) {
// TCoRAPIController.getMensa(this).get()
// }
// TODO test!!
// new sunday bug fix
CacheController . readMensa ( this )
val mensaUpdateTime = Date ( mensaMenu . meta . updateTime * 1000 )
cal . time = mensaUpdateTime
// if it's monday and the last cache update was on sunday or is older than 24hr, update blocking
if ( ( currentDay == Calendar . MONDAY && cal . get ( Calendar . DAY _OF _WEEK ) == Calendar . SUNDAY ) || currentTime - mensaMenu . meta . updateTime > 86400 ) {
println ( " update blocking " )
TCoRAPIController . getMensa ( this ) . get ( )
}
// get the cached files
val cache = CacheController ( this )
cache . readStartCache ( cCourse . courseName )
@ -211,6 +225,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
TCoRAPIController . getTimetable ( cCourse . courseName , 0 , this )
TCoRAPIController . getTimetable ( cCourse . courseName , 1 , this )
}
}
println ( " startup completed in $startupTime ms " )
}