Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Fix rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed May 4, 2017
1 parent 7fe0379 commit bccc1ba
Showing 1 changed file with 12 additions and 56 deletions.
68 changes: 12 additions & 56 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void run() {

Log.v(LOG_TAG, "execute: data=" + data.toString());
SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
String token = null;
String senderID = null;

try {
Expand Down Expand Up @@ -224,8 +225,6 @@ public void run() {
callbackContext.success();
} catch (JSONException e) {
callbackContext.error(e.getMessage());
} catch (IOException e) {
callbackContext.error(e.getMessage());
}
}
});
Expand All @@ -239,8 +238,6 @@ public void run() {
callbackContext.success();
} catch (JSONException e) {
callbackContext.error(e.getMessage());
} catch (IOException e) {
callbackContext.error(e.getMessage());
}
}
});
Expand Down Expand Up @@ -343,52 +340,20 @@ private void clearAllNotifications() {
notificationManager.cancelAll();
}

/**
* Transform `topic name` to `topic path`
* Normally, the `topic` inputed from end-user is `topic name` only.
* We should convert them to GCM `topic path`
* Example:
* when topic name = 'my-topic'
* then topic path = '/topics/my-topic'
*
* @param String topic The topic name
* @return The topic path
*/
private String getTopicPath(String topic) {
if (topic.startsWith("/topics/")) {
return topic;
} else if (topic.startsWith("/topic/")) {
return topic.replace("/topic/", "/topics/");
} else {
return "/topics/" + topic;
}
}

private void subscribeToTopics(JSONArray topics, String registrationToken) throws IOException {
private void subscribeToTopics(JSONArray topics, String registrationToken) {
if (topics != null) {
String topic = null;
for (int i=0; i<topics.length(); i++) {
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Subscribing to topic: " + topic);
FirebaseMessaging.getInstance().subscribeToTopic(topic);
}
subscribeToTopic(topic, registrationToken);
}
}
}

private void subscribeToTopic(String topic, String registrationToken) throws IOException
{
try {
if (topic != null) {
Log.d(LOG_TAG, "Subscribing to topic: " + topic);
GcmPubSub.getInstance(getApplicationContext()).subscribe(registrationToken, getTopicPath(topic), null);
}
} catch (IOException e) {
Log.e(LOG_TAG, "Failed to subscribe to topic: " + topic, e);
throw e;
} catch (IllegalArgumentException argException) {
Log.e(LOG_TAG, "Cannot subscribe to topic [" + topic + "], illegal topic name");
private void subscribeToTopic(String topic, String registrationToken) {
if (topic != null) {
Log.d(LOG_TAG, "Subscribing to topic: " + topic);
FirebaseMessaging.getInstance().subscribeToTopic(topic);
}
}

Expand All @@ -397,24 +362,15 @@ private void unsubscribeFromTopics(JSONArray topics, String registrationToken) {
String topic = null;
for (int i=0; i<topics.length(); i++) {
topic = topics.optString(i, null);
if (topic != null) {
Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
}
unsubscribeFromTopic(topic, registrationToken);
}
}
}

private void unsubscribeFromTopic(String topic, String registrationToken) throws IOException
{
try {
if (topic != null) {
Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
GcmPubSub.getInstance(getApplicationContext()).unsubscribe(registrationToken, getTopicPath(topic));
}
} catch (IOException e) {
Log.e(LOG_TAG, "Failed to unsubscribe to topic: " + topic, e);
throw e;
private void unsubscribeFromTopic(String topic, String registrationToken) {
if (topic != null) {
Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
}
}

Expand Down

0 comments on commit bccc1ba

Please sign in to comment.