fix worker crash on grades sync & fix mensa blocking update on start
continuous-integration/drone/push Build is passing Details

* improve qispos logging
This commit is contained in:
Jannik 2020-09-17 23:23:05 +02:00
parent 451f6082ff
commit f40c0503c0
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
4 changed files with 20 additions and 21 deletions

View File

@ -58,7 +58,7 @@ import kotlin.system.measureTimeMillis
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
private var activeFragment: Fragment = HomeFragment() // the currently active fragment, home at the start private var activeFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
private val className = "MainActivity" private val className = this.javaClass.name
private lateinit var adapter: NfcAdapter private lateinit var adapter: NfcAdapter
private lateinit var pendingIntent: PendingIntent private lateinit var pendingIntent: PendingIntent
@ -181,7 +181,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
EncryptedPreferences.load(this) EncryptedPreferences.load(this)
NotificationUtils(this) NotificationUtils(this)
} }
Log.i(className, "startup completed in $startupTime ms") Log.i(className, "Startup completed in $startupTime ms")
} }
private fun initAesthetic() { private fun initAesthetic() {

View File

@ -68,8 +68,10 @@ class QISPOSParser(val context: Context) {
.referrer("https://notenverwaltung.hs-offenburg.de/qispos/rds?state=user&type=0") .referrer("https://notenverwaltung.hs-offenburg.de/qispos/rds?state=user&type=0")
.execute() .execute()
Log.i(className, "Qispos status is: ${res.statusCode()}")
res.statusCode() res.statusCode()
} catch (exHttp: HttpStatusException) { } catch (exHttp: HttpStatusException) {
Log.w(className, "Qispos status is: ${exHttp.statusCode}")
exHttp.statusCode exHttp.statusCode
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(className, "Error while checking status", ex) Log.e(className, "Error while checking status", ex)
@ -152,7 +154,7 @@ class QISPOSParser(val context: Context) {
.data(list) .data(list)
.postDataCharset("UTF-8") .postDataCharset("UTF-8")
.execute() .execute()
Log.i(className, "login status is: ${res.statusMessage()}: ${res.statusCode()}") Log.i(className, "Login status is: ${res.statusCode()} (${res.statusMessage()})")
val loginCookies = res.cookies() val loginCookies = res.cookies()
@ -187,9 +189,10 @@ class QISPOSParser(val context: Context) {
.referrer("https://notenverwaltung.hs-offenburg.de/qispos/rds?state=user&type=0") .referrer("https://notenverwaltung.hs-offenburg.de/qispos/rds?state=user&type=0")
.get() .get()
Log.i(className, "Read html length: ${gradesListHtml.body().html().length}")
gradesListHtml.body() gradesListHtml.body()
} catch (ex: Exception) { } catch (ex: Exception) {
Log.e(className, "error while loading qispos", ex) Log.e(className, "Error while loading Qispos", ex)
null null
} }
} }

View File

@ -49,10 +49,9 @@ import kotlin.collections.HashMap
* It contains the courseList and mensaMenu object, all timetable objects * It contains the courseList and mensaMenu object, all timetable objects
* are located in TimetableController. * are located in TimetableController.
*/ */
class CacheController(cont: Context) { class CacheController(private val context: Context) {
private val className = "CacheController" private val className = this.javaClass.name
private val context = cont
init { init {
val cal = Calendar.getInstance() val cal = Calendar.getInstance()
@ -63,8 +62,8 @@ class CacheController(cont: Context) {
cal.time = Date(mensaCacheTime * 1000) cal.time = Date(mensaCacheTime * 1000)
// if a) it's monday and the last cache update was on sunday or b) the cache is older than 24hr, update blocking // if a) it's monday and the last cache update was on sunday or b) the cache is older than 24hr, update blocking
if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (currentTime - mensaMenu.meta.updateTime) > 86400) { if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (currentTime - mensaCacheTime) > 86400) {
Log.i(className, "update mensa blocking") Log.i(className, "Update mensa blocking")
GlobalScope.launch(Dispatchers.Default) { updateMensaMenu(context).join() } GlobalScope.launch(Dispatchers.Default) { updateMensaMenu(context).join() }
} }
@ -73,7 +72,7 @@ class CacheController(cont: Context) {
// if a) it`s monday and the last cache update was not on a sunday or b) the cache is older than 24hr, update blocking // if a) it`s monday and the last cache update was not on a sunday or b) the cache is older than 24hr, update blocking
if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (currentTime - timetableCacheTime) > 86400) { if ((currentDay == Calendar.MONDAY && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (currentTime - timetableCacheTime) > 86400) {
Log.i(className, "updating timetable after sunday!") Log.i(className, "Updating timetable after sunday!")
GlobalScope.launch(Dispatchers.Default) { GlobalScope.launch(Dispatchers.Default) {
val threads = listOf( val threads = listOf(
@ -95,10 +94,8 @@ class CacheController(cont: Context) {
if (currentTime - mensaCacheTime > 10800) if (currentTime - mensaCacheTime > 10800)
updateMensaMenu(context) updateMensaMenu(context)
if (currentTime - timetableCacheTime > 10800) { if (currentTime - timetableCacheTime > 10800)
TimetableController.update(context) TimetableController.update(context)
}
} }
companion object { companion object {

View File

@ -48,15 +48,14 @@ class GradesUpdateWorker(val context: Context, params: WorkerParameters): Worker
return Result.success() return Result.success()
} }
// TODO show updating notification, for debugging val notificationIdChecking = NotificationUtils.getId()
val notificationIdDBG = NotificationUtils.getId() val builderChecking = NotificationCompat.Builder(context, CHANNEL_ID_GRADES)
val builderDBG = NotificationCompat.Builder(context, CHANNEL_ID_GRADES)
.setSmallIcon(R.drawable.ic_grading_black_24dp) .setSmallIcon(R.drawable.ic_grading_black_24dp)
.setContentTitle(context.getString(R.string.notification_grades)) .setContentTitle(context.getString(R.string.notification_grades))
.setContentText(context.getString(R.string.notification_grades_updating_desc)) .setContentText(context.getString(R.string.notification_grades_updating_desc))
.setNotificationSilent() .setNotificationSilent()
NotificationManagerCompat.from(context).apply { NotificationManagerCompat.from(context).apply {
notify(notificationIdDBG, builderDBG.build()) notify(notificationIdChecking, builderChecking.build())
} }
// get old grades // get old grades
@ -70,7 +69,7 @@ class GradesUpdateWorker(val context: Context, params: WorkerParameters): Worker
val diff = GradesController().diffGrades(oldGrades, newGrades) val diff = GradesController().diffGrades(oldGrades, newGrades)
// show message // show message
if (diff.isNotEmpty() || diff.isEmpty()) { if (diff.isNotEmpty()) {
val text = if (diff.size < 2) { val text = if (diff.size < 2) {
context.getString(R.string.notification_grades_single_desc, diff.first().name) context.getString(R.string.notification_grades_single_desc, diff.first().name)
} else { } else {
@ -100,11 +99,11 @@ class GradesUpdateWorker(val context: Context, params: WorkerParameters): Worker
} }
} }
// TODO remove debug notification // remove scanning notification
NotificationManagerCompat.from(context).apply { NotificationManagerCompat.from(context).apply {
cancel(notificationIdDBG) cancel(notificationIdChecking)
} }
return Result.success() return Result.success()
} }