-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenGMApplication.java
77 lines (63 loc) · 2.09 KB
/
OpenGMApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ch.epfl.sweng.opengm;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseUser;
import ch.epfl.sweng.opengm.parse.PFException;
import ch.epfl.sweng.opengm.parse.PFGroup;
import ch.epfl.sweng.opengm.parse.PFUser;
public class OpenGMApplication extends Application {
// Replace with your own Parse keys
private final static String PARSE_APP_ID = "";
private final static String PARSE_KEY = "";
private static PFUser currentUser = null;
private static PFGroup currentGroup = null;
@Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APP_ID, PARSE_KEY);
ParseUser.enableRevocableSessionInBackground();
}
public static PFUser getCurrentUser() {
return currentUser;
}
public static PFUser setCurrentUser(PFUser user) {
if (currentUser == null) {
currentUser = user;
}
return currentUser;
}
public static PFUser setCurrentUserWithId(String id) throws PFException {
if (currentUser == null && id != null) {
try {
currentUser = PFUser.fetchExistingUser(id);
} catch (PFException e) {
throw new PFException(e);
}
}
return currentUser;
}
public static PFGroup getCurrentGroup() {
return currentGroup;
}
public static void setCurrentGroup(PFGroup group) {
boolean found = false;
for (PFGroup pfGroup : currentUser.getGroups()) {
if (pfGroup.getId().equals(group.getId()))
found = true;
}
currentGroup = found ? group : null;
}
/**
* Set the current group to the value you want
*
* @param pos the position of the group in the user's groups list or -1 to put a null group
*/
public static void setCurrentGroup(int pos) {
currentGroup = (pos == -1 ? null : currentUser.getGroups().get(pos));
}
public static void logOut() {
currentUser = null;
ParseUser.logOut();
}
}