forked from avivais/phonegap-parse-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParsePlugin.java
77 lines (66 loc) · 2.36 KB
/
ParsePlugin.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
package org.apache.cordova.core.parse;
import java.util.Set;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class ParsePlugin extends CordovaPlugin {
public static final String ACTION_GET_INSTALLATION_ID = "getInstallationId";
public static final String ACTION_GET_SUBSCRIPTIONS = "getSubscriptions";
public static final String ACTION_SUBSCRIBE = "subscribe";
public static final String ACTION_UNSUBSCRIBE = "unsubscribe";
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals(ACTION_GET_INSTALLATION_ID)) {
this.getInstallationId(callbackContext);
return true;
}
if (action.equals(ACTION_GET_SUBSCRIPTIONS)) {
this.getSubscriptions(callbackContext);
return true;
}
if (action.equals(ACTION_SUBSCRIBE)) {
this.subscribe(args.getString(0), callbackContext);
return true;
}
if (action.equals(ACTION_UNSUBSCRIBE)) {
this.unsubscribe(args.getString(0), callbackContext);
return true;
}
return false;
}
private void getInstallationId(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
String installationId = ParseInstallation.getCurrentInstallation().getInstallationId();
callbackContext.success(installationId);
}
});
}
private void getSubscriptions(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Set<String> subscriptions = PushService.getSubscriptions(MainApplication.getContext());
callbackContext.success(subscriptions.toString());
}
});
}
private void subscribe(final String channel, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
PushService.subscribe(MainApplication.getContext(), channel, MainActivity.class);
callbackContext.success();
}
});
}
private void unsubscribe(final String channel, final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
PushService.unsubscribe(MainApplication.getContext(), channel);
callbackContext.success();
}
});
}
}