some lib updates & new sunday-bug fix
This commit is contained in:
parent
e99127a63a
commit
9c1f95ca25
|
@ -13,7 +13,7 @@ android {
|
|||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 13
|
||||
versionName "0.4.1"
|
||||
versionName "0.4.90"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
resValue "string", "build_time", buildTime()
|
||||
setProperty("archivesBaseName", "projectlaogai-$versionName")
|
||||
|
@ -37,7 +37,7 @@ dependencies {
|
|||
implementation 'org.jetbrains.anko:anko-commons:0.10.8'
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
|
@ -47,8 +47,8 @@ dependencies {
|
|||
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
||||
|
||||
static def buildTime() {
|
||||
|
|
|
@ -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 sill backfire if someone has to update before the server finished updating the timetable at 0001/0101
|
||||
// TODO this will 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")
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ package org.mosad.seil0.projectlaogai.controller
|
|||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonParser
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.Course
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.MensaWeek
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.TimetableWeek
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class CacheController(cont: Context) {
|
||||
|
||||
|
@ -39,12 +39,12 @@ class CacheController(cont: Context) {
|
|||
|
||||
companion object {
|
||||
var coursesList = ArrayList<Course>()
|
||||
var mensaCurrentWeek = MensaWeek()
|
||||
var mensaNextWeek = MensaWeek()
|
||||
var timetables = ArrayList<TimetableWeek>()
|
||||
var mensaMenu = MensaMenu(MensaMeta(0, ""), MensaWeek(), MensaWeek())
|
||||
|
||||
/**
|
||||
* read current and next weeks mensa menus from the cached file
|
||||
* get the MensaMenu object from the cached json,
|
||||
* if cache is empty create the cache file
|
||||
*/
|
||||
fun readMensa(context: Context) {
|
||||
val file = File(context.filesDir, "mensa.json")
|
||||
|
@ -54,16 +54,11 @@ class CacheController(cont: Context) {
|
|||
TCoRAPIController.getMensa(context).get()
|
||||
}
|
||||
|
||||
|
||||
val fileReader = FileReader(file)
|
||||
val bufferedReader = BufferedReader(fileReader)
|
||||
val mensaObject = JsonParser().parse(bufferedReader.readLine()).asJsonObject
|
||||
|
||||
val currentWeek = mensaObject.getAsJsonObject("currentWeek")
|
||||
val nextWeek = mensaObject.getAsJsonObject("nextWeek")
|
||||
|
||||
mensaCurrentWeek = Gson().fromJson(currentWeek, MensaWeek().javaClass)
|
||||
mensaNextWeek = Gson().fromJson(nextWeek, MensaWeek().javaClass)
|
||||
mensaMenu = GsonBuilder().create().fromJson(mensaObject, MensaMenu(MensaMeta(0, ""), MensaWeek(), MensaWeek()).javaClass)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ import kotlinx.android.synthetic.main.fragment_home.*
|
|||
import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaCurrentWeek
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaMenu
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.timetables
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.Meal
|
||||
|
@ -78,10 +78,10 @@ class HomeFragment : Fragment() {
|
|||
uiThread {
|
||||
|
||||
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
|
||||
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
|
||||
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
|
||||
mensaCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
|
||||
} else {
|
||||
dayMeals = mensaCurrentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
|
||||
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
|
||||
cal.add(Calendar.DATE, 1)
|
||||
mensaCardView.setDayHeading(resources.getString(R.string.tomorrow_date, formatter.format(cal.time)))
|
||||
}
|
||||
|
|
|
@ -27,12 +27,14 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import kotlinx.android.synthetic.main.fragment_mensa.*
|
||||
import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaCurrentWeek
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaNextWeek
|
||||
import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.mensaMenu
|
||||
import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.cShowBuffet
|
||||
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.MensaWeek
|
||||
|
@ -46,25 +48,43 @@ import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
|
|||
*/
|
||||
class MensaFragment : Fragment() {
|
||||
|
||||
private lateinit var btnCardValue: FloatingActionButton
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
||||
val view: View = inflater.inflate(org.mosad.seil0.projectlaogai.R.layout.fragment_mensa, container, false)
|
||||
val view: View = inflater.inflate(R.layout.fragment_mensa, container, false)
|
||||
|
||||
btnCardValue = view.findViewById(R.id.btnCardValue)
|
||||
|
||||
// init actions
|
||||
refreshAction()
|
||||
initActions()
|
||||
|
||||
// add the current week (week starts on sunday)
|
||||
val dayCurrent = if(NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
|
||||
addWeek(mensaCurrentWeek, dayCurrent).get()
|
||||
addWeek(mensaMenu.currentWeek, dayCurrent).get()
|
||||
|
||||
// add the next week
|
||||
addWeek(mensaNextWeek, 0)
|
||||
addWeek(mensaMenu.nextWeek, 0)
|
||||
|
||||
// TODO should we show a info if there is no more food this & next week?
|
||||
// TODO hide the floating button if we are not on the top end of the scroll pane
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
private fun initActions() {
|
||||
refreshAction() // must be async
|
||||
|
||||
btnCardValue.setOnClickListener {
|
||||
MaterialDialog(context!!)
|
||||
.title(text = "Mensa-Karte")
|
||||
.message(text = "das aktuelle Guthaben beträgt\n\n13,70€")
|
||||
.show()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* add all menus from dayStart to Friday for a given week
|
||||
* @param menusWeek menu of type MensaWeek you want to add
|
||||
|
@ -129,10 +149,10 @@ class MensaFragment : Fragment() {
|
|||
|
||||
// add the refreshed menus
|
||||
val dayCurrent = if (NotRetardedCalendar().getDayOfWeekIndex() == 6) 0 else NotRetardedCalendar().getDayOfWeekIndex()
|
||||
addWeek(mensaCurrentWeek, dayCurrent).get()
|
||||
addWeek(mensaMenu.currentWeek, dayCurrent).get()
|
||||
|
||||
// add the next week
|
||||
addWeek(mensaNextWeek, 0)
|
||||
addWeek(mensaMenu.nextWeek, 0)
|
||||
|
||||
refreshLayout_Mensa.isRefreshing = false
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ import java.util.*
|
|||
import kotlin.collections.ArrayList
|
||||
|
||||
class DataTypes {
|
||||
val times = arrayOf("8.00 - 9.30", "9.45 - 11.15" ,"11.35 - 13.05", "14.00 -15.30", "15.45 - 17.15", "17.30 - 19.00")
|
||||
val times =
|
||||
arrayOf("8.00 - 9.30", "9.45 - 11.15", "11.35 - 13.05", "14.00 -15.30", "15.45 - 17.15", "17.30 - 19.00")
|
||||
|
||||
val primaryColors = intArrayOf(
|
||||
Color.parseColor("#E53935"),
|
||||
|
@ -69,7 +70,7 @@ class DataTypes {
|
|||
Color.parseColor("#FF9100"),
|
||||
Color.parseColor("#FF3D00"),
|
||||
Color.parseColor("#000000")
|
||||
)
|
||||
)
|
||||
|
||||
init {
|
||||
// do something
|
||||
|
@ -85,7 +86,7 @@ class NotRetardedCalendar {
|
|||
private val calendar = Calendar.getInstance()!!
|
||||
|
||||
fun getDayOfWeekIndex(): Int {
|
||||
return when(calendar.get(Calendar.DAY_OF_WEEK)) {
|
||||
return when (calendar.get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.MONDAY -> 0
|
||||
Calendar.TUESDAY -> 1
|
||||
Calendar.WEDNESDAY -> 2
|
||||
|
@ -98,7 +99,7 @@ class NotRetardedCalendar {
|
|||
}
|
||||
|
||||
fun getTomorrowWeekIndex(): Int {
|
||||
return when(calendar.get(Calendar.DAY_OF_WEEK)) {
|
||||
return when (calendar.get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.MONDAY -> 1
|
||||
Calendar.TUESDAY -> 2
|
||||
Calendar.WEDNESDAY -> 3
|
||||
|
@ -111,16 +112,28 @@ class NotRetardedCalendar {
|
|||
}
|
||||
}
|
||||
|
||||
// data classes for the course part
|
||||
data class Course(val courseLink: String, val courseName: String)
|
||||
|
||||
// data classes for the Mensa part
|
||||
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
||||
|
||||
data class Meals(val meals: ArrayList<Meal>)
|
||||
|
||||
data class MensaWeek(val days: Array<Meals> = Array(7) { Meals(ArrayList()) })
|
||||
|
||||
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
|
||||
data class MensaMeta(val updateTime: Long, val mensaName: String)
|
||||
|
||||
data class TimetableDay( val timeslots: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})
|
||||
data class MensaMenu(val meta: MensaMeta, val currentWeek: MensaWeek, val nextWeek: MensaWeek)
|
||||
|
||||
// data classes for the timetable part
|
||||
data class Lesson(
|
||||
val lessonSubject: String,
|
||||
val lessonTeacher: String,
|
||||
val lessonRoom: String,
|
||||
val lessonRemark: String
|
||||
)
|
||||
|
||||
data class TimetableDay(val timeslots: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>() })
|
||||
|
||||
data class TimetableWeek(val days: Array<TimetableDay> = Array(6) { TimetableDay() })
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".fragments.MensaFragment">
|
||||
|
@ -22,6 +22,13 @@
|
|||
android:id="@+id/linLayout_Mensa"/>
|
||||
</ScrollView>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:src="@drawable/ic_local_dining_black_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true" android:id="@+id/btnCardValue" android:visibility="visible"
|
||||
android:layout_gravity="bottom|center|end" android:elevation="7dp" android:focusable="true"
|
||||
android:layout_marginEnd="7dp" android:layout_marginBottom="7dp"/>
|
||||
|
||||
|
||||
</FrameLayout>
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath 'com.android.tools.build:gradle:3.4.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
|
Loading…
Reference in New Issue