use cache if qispos is not available
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jannik 2020-08-29 17:21:34 +02:00
parent d6eb1ff1e5
commit cb1f43ec66
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
1 changed files with 11 additions and 13 deletions

View File

@ -62,9 +62,18 @@ class GradesFragment : Fragment() {
parser = QISPOSParser(context!!)// init the parser
// TODO if loading from cache, don't check Qispos state
if (checkCredentials() && checkQisposStatus()) {
if (checkCredentials()) {
GlobalScope.launch(Dispatchers.Default) {
// if the cache is older than 24hr, update blocking
val currentTime = System.currentTimeMillis() / 1000
if ((currentTime - Preferences.gradesCacheTime) > 86400 && checkQisposStatus()) {
withContext(Dispatchers.Main) {
refreshLayout_Grades.isRefreshing = true
}
CacheController.updateGrades(context!!).join()
}
addGrades()
}
}
@ -145,17 +154,6 @@ class GradesFragment : Fragment() {
*/
private fun addGrades() = GlobalScope.launch(Dispatchers.Default) {
val addGradesTime = measureTimeMillis {
withContext(Dispatchers.Main) {
refreshLayout_Grades.isRefreshing = true
}
// if the cache is older than 24hr, update blocking
val currentTime = System.currentTimeMillis() / 1000
if ((currentTime - Preferences.gradesCacheTime) > 86400) {
CacheController.updateGrades(context!!).join()
}
val grades = CacheController(context!!).readGrades()
withContext(Dispatchers.Main) {