some more logging and version 0.4.99 (RC1)

This commit is contained in:
Jannik 2019-08-25 22:45:23 +02:00
parent be916a74ab
commit 75168c6688
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 54 additions and 35 deletions

View File

@ -13,7 +13,7 @@ android {
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 28 targetSdkVersion 28
versionCode 14 versionCode 14
versionName "0.4.95" versionName "0.4.99"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "build_time", buildTime() resValue "string", "build_time", buildTime()
setProperty("archivesBaseName", "projectlaogai-$versionName") setProperty("archivesBaseName", "projectlaogai-$versionName")

View File

@ -23,6 +23,7 @@
package org.mosad.seil0.projectlaogai.controller package org.mosad.seil0.projectlaogai.controller
import android.content.Context import android.content.Context
import android.util.Log
import org.jetbrains.anko.doAsync import org.jetbrains.anko.doAsync
import org.json.JSONObject import org.json.JSONObject
import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.coursesCacheTime import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.coursesCacheTime
@ -32,69 +33,87 @@ import java.io.BufferedWriter
import java.io.File import java.io.File
import java.io.FileWriter import java.io.FileWriter
import java.net.URL import java.net.URL
import kotlin.Exception
class TCoRAPIController { class TCoRAPIController {
companion object { companion object {
private const val className = "TCoRAPIController"
private const val tcorBaseURL = "https://tcor.mosad.xyz"
/** /**
* get the json object from tcor api and write it as file (cache) * get the json object from tcor api and write it as file (cache)
*/ */
fun getCoursesList(context: Context) = doAsync { fun getCoursesList(context: Context) = doAsync {
val url = URL("https://tcor.mosad.xyz/courseList") try {
val file = File(context.filesDir, "courses.json") val url = URL("$tcorBaseURL/courseList")
val file = File(context.filesDir, "courses.json")
// read data from the API // read data from the API
val coursesObject = JSONObject(url.readText()) //JSONObject(inReader.readLine()) val coursesObject = JSONObject(url.readText()) //JSONObject(inReader.readLine())
// write the json object to a file // write the json object to a file
val writer = BufferedWriter(FileWriter(file)) val writer = BufferedWriter(FileWriter(file))
writer.write(coursesObject.toString()) writer.write(coursesObject.toString())
writer.close() writer.close()
// update cache time
coursesCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} catch (ex: Exception) {
Log.e(className, "failed to get /courseList", ex)
}
// update cache time
coursesCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} }
/** /**
* get the json object from tcor api and write it as file (cache) * get the json object from tcor api and write it as file (cache)
*/ */
fun getMensa(context: Context) = doAsync { fun getMensa(context: Context) = doAsync {
val url = URL("https://tcor.mosad.xyz/mensamenu") try {
val file = File(context.filesDir, "mensa.json") val url = URL("$tcorBaseURL/mensamenu")
val file = File(context.filesDir, "mensa.json")
// read data from the API // read data from the API
val mensaObject = JSONObject(url.readText()) //JSONObject(inReader.readLine()) val mensaObject = JSONObject(url.readText()) //JSONObject(inReader.readLine())
// write the json object to a file // write the json object to a file
val writer = BufferedWriter(FileWriter(file)) val writer = BufferedWriter(FileWriter(file))
writer.write(mensaObject.toString()) writer.write(mensaObject.toString())
writer.close() writer.close()
// update cache time
mensaCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} catch (ex: Exception) {
Log.e(className, "failed to get /mensamenu", ex)
}
// update cache time
mensaCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} }
/** /**
* get the json object from tcor api and write it as file (cache) * get the json object from tcor api and write it as file (cache)
*/ */
fun getTimetable(courseName: String, week: Int, context: Context) = doAsync { fun getTimetable(courseName: String, week: Int, context: Context) = doAsync {
val url = URL("https://tcor.mosad.xyz/timetable?courseName=$courseName&week=$week") try {
val file = File(context.filesDir, "timetable-$courseName-$week.json") val url = URL("$tcorBaseURL/timetable?courseName=$courseName&week=$week")
val file = File(context.filesDir, "timetable-$courseName-$week.json")
// read data from the API // read data from the API
val mensaObject = JSONObject(url.readText()) //JSONObject(inReader.readLine()) val mensaObject = JSONObject(url.readText()) //JSONObject(inReader.readLine())
// write the json object to a file // write the json object to a file
val writer = BufferedWriter(FileWriter(file)) val writer = BufferedWriter(FileWriter(file))
writer.write(mensaObject.toString()) writer.write(mensaObject.toString())
writer.close() writer.close()
// update cache time
timetableCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} catch (ex: Exception) {
Log.e(className, "failed to get /timetable", ex)
}
// update cache time
timetableCacheTime = System.currentTimeMillis() / 1000
PreferencesController.save(context)
} }
} }

View File

@ -1,6 +1,6 @@
This release 0.5.0 is called "artistical Apollon". This release 0.5.0 is called "artistical Apollon".
* new: it's now possible to choos a theme (light, dark or balck) * new: it's now possible to choose a theme (light, dark or black)
* new: you can now check your current mensa card balance * new: you can now check your current mensa card balance
* change: updated some libs, updated kotlin to 1.3.41 * change: updated some libs, updated kotlin to 1.3.41
* fix: the mensa should now show the correct meals on sunday/monday * fix: the mensa should now show the correct meals on sunday/monday