Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mytfg
mytfg-vplan-app
Commits
62931c5c
Commit
62931c5c
authored
Jan 09, 2017
by
Lennart Bader
Browse files
Added cache clear on additional class change.
Added load from cache when offline even when cache timeout occured
parent
2eefb498
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/mytfg/apps/vplan/api/MyTFGApi.java
View file @
62931c5c
...
...
@@ -42,6 +42,7 @@ import javax.net.ssl.HttpsURLConnection;
import
de.mytfg.apps.vplan.R
;
import
de.mytfg.apps.vplan.objects.User
;
import
de.mytfg.apps.vplan.objects.Vplan
;
/**
* Wrapper for the MyTFG API. Handles Login tokens, authentication errors and result parsing.
...
...
@@ -122,6 +123,9 @@ public class MyTFGApi {
preferences
.
edit
()
.
putStringSet
(
"additional_classes"
,
classSet
)
.
apply
();
Vplan
.
clearCache
(
"heute"
,
context
);
Vplan
.
clearCache
(
"morgen"
,
context
);
}
/**
...
...
app/src/main/java/de/mytfg/apps/vplan/objects/Vplan.java
View file @
62931c5c
...
...
@@ -19,6 +19,8 @@ import de.mytfg.apps.vplan.api.MyTFGApi;
import
de.mytfg.apps.vplan.api.SuccessCallback
;
import
de.mytfg.apps.vplan.tools.JsonFileManager
;
import
static
de
.
mytfg
.
apps
.
vplan
.
R
.
id
.
plan
;
/**
* Represents the Vplan for one day
* Contains multiple entries for different classes and lessons.
...
...
@@ -28,6 +30,7 @@ public class Vplan extends MytfgObject {
private
Context
context
;
private
String
day
;
private
String
date
;
private
List
<
VplanEntry
>
entries
=
new
LinkedList
<>();
private
String
mode
;
private
String
cls_string
;
...
...
@@ -37,6 +40,7 @@ public class Vplan extends MytfgObject {
private
List
<
Pair
<
String
,
String
>>
absent_teachers
=
new
LinkedList
<>();
private
List
<
String
>
absent_strings
=
new
LinkedList
<>();
private
long
timestamp
=
0
;
private
boolean
cacheAvail
=
false
;
private
int
lastCode
;
private
boolean
loaded
;
...
...
@@ -65,6 +69,7 @@ public class Vplan extends MytfgObject {
public
void
load
(
final
SuccessCallback
callback
,
boolean
clearCache
)
{
// Try to load from cache
cacheAvail
=
false
;
if
(!
clearCache
&&
loadFromCache
())
{
if
(
upToDate
())
{
callback
.
callback
(
true
);
...
...
@@ -92,7 +97,12 @@ public class Vplan extends MytfgObject {
callback
.
callback
(
false
);
}
}
else
{
callback
.
callback
(
false
);
if
(
responseCode
==
-
1
&&
loadFromCache
())
{
// No internet connection -> use cache even when cache timed out
callback
.
callback
(
true
);
}
else
{
callback
.
callback
(
false
);
}
}
}
});
...
...
@@ -114,6 +124,7 @@ public class Vplan extends MytfgObject {
try
{
JSONObject
plan
=
result
.
getJSONObject
(
"plan"
);
this
.
day_str
=
plan
.
getString
(
"day_str"
);
date
=
plan
.
getString
(
"date"
);
JSONArray
entries
=
plan
.
getJSONArray
(
"entries"
);
for
(
int
i
=
0
;
i
<
entries
.
length
();
++
i
)
{
...
...
@@ -205,4 +216,8 @@ public class Vplan extends MytfgObject {
}
return
results
;
}
public
static
void
clearCache
(
String
day
,
Context
context
)
{
JsonFileManager
.
clear
(
"vplan_"
+
day
,
context
);
}
}
app/src/main/java/de/mytfg/apps/vplan/tools/JsonFileManager.java
View file @
62931c5c
...
...
@@ -49,4 +49,8 @@ public class JsonFileManager {
}
return
false
;
}
public
static
boolean
clear
(
String
filename
,
Context
context
)
{
return
context
.
deleteFile
(
filename
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment