Skip to content

Commit

Permalink
Release 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gbhrdt committed Jun 19, 2023
1 parent 37a8367 commit 481e089
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 99 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.5.0
* Updated to latest iOS + Android SDKs
* Implemented new topic-related methods
* Fixed callback arguments for some Android methods

## 1.4.11
* Updated to latest iOS + Android SDKs

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"

implementation('com.cleverpush:cleverpush:1.29.4') {
implementation('com.cleverpush:cleverpush:1.30.15') {
exclude group: 'com.android.support'
}
}
205 changes: 109 additions & 96 deletions android/src/main/java/com/cleverpush/reactnative/RNCleverPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,33 @@
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.util.Log;

import com.cleverpush.ActivityLifecycleListener;
import com.cleverpush.ChannelTag;
import com.cleverpush.ChannelTopic;
import com.cleverpush.CleverPush;
import com.cleverpush.CustomAttribute;
import com.cleverpush.Notification;
import com.cleverpush.Subscription;
import com.cleverpush.listener.SubscribedListener;
import com.cleverpush.listener.AppBannerOpenedListener;
import com.cleverpush.banner.models.BannerAction;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;

public class RNCleverPush extends ReactContextBaseJavaModule implements LifecycleEventListener {
public static final String NOTIFICATION_OPENED_INTENT_FILTER = "CPNotificationOpened";
Expand All @@ -47,15 +44,6 @@ public class RNCleverPush extends ReactContextBaseJavaModule implements Lifecycl
private boolean cleverPushInitDone;
private boolean registeredEvents = false;

private Callback pendingGetAvailableTagsCallback;
private Callback pendingGetAvailableAttributesCallback;
private Callback pendingGetSubscriptionTagsCallback;
private Callback pendingGetSubscriptionAttributesCallback;
private Callback pendingHasSubscriptionTagCallback;
private Callback pendingGetSubscriptionAttributeCallback;
private Callback pendingIsSubscribedCallback;
private Callback pendingGetNotificationsCallback;

public RNCleverPush(ReactApplicationContext reactContext) {
super(reactContext);
mReactApplicationContext = reactContext;
Expand Down Expand Up @@ -127,118 +115,123 @@ public void subscribed(String subscriptionId) {
}
});

this.cleverPush.setAppBannerOpenedListener(new AppBannerOpenedListener() {
@Override
public void opened(BannerAction action) {
WritableMap result = new WritableNativeMap();
result.putString("type", action.getType());
result.putString("name", action.getName());
result.putString("url", action.getUrl());
result.putString("urlType", action.getUrlType());
this.cleverPush.setAppBannerOpenedListener(action -> {
WritableMap result = new WritableNativeMap();
result.putString("type", action.getType());
result.putString("name", action.getName());
result.putString("url", action.getUrl());
result.putString("urlType", action.getUrlType());

sendEvent("CleverPush-appBannerOpened", result);
}
});
sendEvent("CleverPush-appBannerOpened", result);
});
}

@ReactMethod
public void getSubscriptionTags(final Callback callback) {
if (pendingGetSubscriptionTagsCallback == null)
pendingGetSubscriptionTagsCallback = callback;

Set<String> tags = this.cleverPush.getSubscriptionTags();
WritableArray writableArray = new WritableNativeArray();
for (String tag : tags) {
writableArray.pushString(tag);
}

if (pendingGetSubscriptionTagsCallback != null)
pendingGetSubscriptionTagsCallback.invoke(writableArray);

pendingGetSubscriptionTagsCallback = null;
if (callback != null) {
callback.invoke(null, writableArray);
}
}

@ReactMethod
public void hasSubscriptionTag(String tagId, final Callback callback) {
if (pendingHasSubscriptionTagCallback == null)
pendingHasSubscriptionTagCallback = callback;

boolean hasTag = this.cleverPush.hasSubscriptionTag(tagId);

if (pendingHasSubscriptionTagCallback != null)
pendingHasSubscriptionTagCallback.invoke(hasTag);
if (callback != null) {
callback.invoke(null, hasTag);
}
}

pendingHasSubscriptionTagCallback = null;
@ReactMethod
public void getSubscriptionTopics(final Callback callback) {
Set<String> topics = this.cleverPush.getSubscriptionTopics();
WritableArray writableArray = new WritableNativeArray();
for (String topic : topics) {
writableArray.pushString(topic);
}

if (callback != null) {
callback.invoke(null, writableArray);
}
}

@ReactMethod
public void getSubscriptionAttributes(final Callback callback) {
if (pendingGetSubscriptionAttributesCallback == null)
pendingGetSubscriptionAttributesCallback = callback;

Map<String, Object> attributes = this.cleverPush.getSubscriptionAttributes();
WritableMap writableMap = new WritableNativeMap();
for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
writableMap.putString(attribute.getKey(), attribute.getValue().toString());
}

if (pendingGetSubscriptionAttributesCallback != null)
pendingGetSubscriptionAttributesCallback.invoke(writableMap);

pendingGetSubscriptionAttributesCallback = null;
if (callback != null) {
callback.invoke(null, writableMap);
}
}

@ReactMethod
public void getSubscriptionAttribute(String attributeId, final Callback callback) {
if (pendingGetSubscriptionAttributeCallback == null)
pendingGetSubscriptionAttributeCallback = callback;

Object value = this.cleverPush.getSubscriptionAttribute(attributeId);

if (pendingGetSubscriptionAttributeCallback != null)
pendingGetSubscriptionAttributeCallback.invoke(value);

pendingGetSubscriptionAttributeCallback = null;
if (callback != null) {
callback.invoke(null, value);
}
}

@ReactMethod
public void getAvailableTags(final Callback callback) {
if (pendingGetAvailableTagsCallback == null)
pendingGetAvailableTagsCallback = callback;
this.cleverPush.getAvailableTags(tags -> {
WritableArray writableArray = new WritableNativeArray();
for (ChannelTag tag : tags) {
WritableMap writeableMapTag = new WritableNativeMap();
writeableMapTag.putString("id", tag.getId());
writeableMapTag.putString("name", tag.getName());
writableArray.pushMap(writeableMapTag);
}

Set<ChannelTag> tags = this.cleverPush.getAvailableTags();
WritableArray writableArray = new WritableNativeArray();
for (ChannelTag tag : tags) {
WritableMap writeableMapTag = new WritableNativeMap();
writeableMapTag.putString("id", tag.getId());
writeableMapTag.putString("name", tag.getName());
writableArray.pushMap(writeableMapTag);
}
if (callback != null) {
callback.invoke(null, writableArray);
}
});
}

if (pendingGetAvailableTagsCallback != null)
pendingGetAvailableTagsCallback.invoke(writableArray);
@ReactMethod
public void getAvailableTopics(final Callback callback) {
this.cleverPush.getAvailableTopics(topics -> {
WritableArray writableArray = new WritableNativeArray();
for (ChannelTopic topic : topics) {
WritableMap writeableMapTopic = new WritableNativeMap();
writeableMapTopic.putString("id", topic.getId());
writeableMapTopic.putString("name", topic.getName());
writableArray.pushMap(writeableMapTopic);
}

pendingGetAvailableTagsCallback = null;
if (callback != null) {
callback.invoke(null, writableArray);
}
});
}

@ReactMethod
public void getAvailableAttributes(final Callback callback) {
if (pendingGetAvailableAttributesCallback == null)
pendingGetAvailableAttributesCallback = callback;

Set<CustomAttribute> attributes = this.cleverPush.getAvailableAttributes();
WritableArray writableArray = new WritableNativeArray();
for (CustomAttribute attribute : attributes) {
WritableMap writeableMapTag = new WritableNativeMap();
writeableMapTag.putString("id", attribute.getId());
writeableMapTag.putString("name", attribute.getName());
writableArray.pushMap(writeableMapTag);
}

if (pendingGetAvailableAttributesCallback != null)
pendingGetAvailableAttributesCallback.invoke(writableArray);
this.cleverPush.getAvailableAttributes(attributes -> {
WritableArray writableArray = new WritableNativeArray();
for (CustomAttribute attribute : attributes) {
WritableMap writeableMapTag = new WritableNativeMap();
writeableMapTag.putString("id", attribute.getId());
writeableMapTag.putString("name", attribute.getName());
writableArray.pushMap(writeableMapTag);
}

pendingGetAvailableAttributesCallback = null;
if (callback != null) {
callback.invoke(null, writableArray);
}
});
}

@ReactMethod
Expand All @@ -257,6 +250,34 @@ public void removeSubscriptionTag(String tagId) {
this.cleverPush.removeSubscriptionTag(tagId);
}

@ReactMethod
public void setSubscriptionTopics(ReadableArray topicIdsReadableArray) {
if (this.cleverPush == null) {
return;
}
String[] topicIds = new String[topicIdsReadableArray.size()];
for (int i = 0; i < topicIdsReadableArray.size(); i++) {
topicIds[i] = topicIdsReadableArray.getString(i);
}
this.cleverPush.setSubscriptionTopics(topicIds);
}

@ReactMethod
public void addSubscriptionTopic(String topicId) {
if (this.cleverPush == null) {
return;
}
this.cleverPush.addSubscriptionTopic(topicId);
}

@ReactMethod
public void removeSubscriptionTopic(String topicId) {
if (this.cleverPush == null) {
return;
}
this.cleverPush.removeSubscriptionTopic(topicId);
}

@ReactMethod
public void setSubscriptionAttribute(String attributeId, String value) {
if (this.cleverPush == null) {
Expand All @@ -267,15 +288,11 @@ public void setSubscriptionAttribute(String attributeId, String value) {

@ReactMethod
public void isSubscribed(final Callback callback) {
if (pendingIsSubscribedCallback == null)
pendingIsSubscribedCallback = callback;

boolean isSubscribed = this.cleverPush.isSubscribed();

if (pendingIsSubscribedCallback != null)
pendingIsSubscribedCallback.invoke(null, isSubscribed);

pendingIsSubscribedCallback = null;
if (callback != null) {
callback.invoke(null, isSubscribed);
}
}

@ReactMethod
Expand Down Expand Up @@ -333,9 +350,6 @@ public void showAppBanners(final Callback callback) {

@ReactMethod
public void getNotifications(final Callback callback) {
if (pendingGetNotificationsCallback == null)
pendingGetNotificationsCallback = callback;

Set<Notification> notifications = this.cleverPush.getNotifications();
WritableArray writableArray = new WritableNativeArray();
for (Notification notification : notifications) {
Expand All @@ -350,10 +364,9 @@ public void getNotifications(final Callback callback) {
writableArray.pushMap(writeableMap);
}

if (pendingGetNotificationsCallback != null)
pendingGetNotificationsCallback.invoke(null, writableArray);

pendingGetNotificationsCallback = null;
if (callback != null) {
callback.invoke(null, writableArray);
}
}

@ReactMethod
Expand Down
2 changes: 1 addition & 1 deletion cleverpush-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Pod::Spec.new do |s|
s.source_files = 'ios/RCTCleverPush/*.{h,m}'

s.dependency 'React'
s.dependency 'CleverPush', '~> 1.26.4'
s.dependency 'CleverPush', '~> 1.27.13'

end
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export default class CleverPush {
RNCleverPush.getAvailableTags(callback);
}

static getAvailableTopics(callback) {
if (!checkIfInitialized()) return;

RNCleverPush.getAvailableTopics(callback);
}

static getAvailableAttributes(callback) {
if (!checkIfInitialized()) return;

Expand Down Expand Up @@ -124,6 +130,30 @@ export default class CleverPush {
RNCleverPush.hasSubscriptionTag(tagId, callback);
}

static getSubscriptionTopics(callback) {
if (!checkIfInitialized()) return;

RNCleverPush.getSubscriptionTopics(callback);
}

static setSubscriptionTopics(topicIds) {
if (!checkIfInitialized()) return;

RNCleverPush.setSubscriptionTopics(topicIds);
}

static addSubscriptionTopic(topicId) {
if (!checkIfInitialized()) return;

RNCleverPush.addSubscriptionTopic(topicId);
}

static removeSubscriptionTopic(topicId) {
if (!checkIfInitialized()) return;

RNCleverPush.removeSubscriptionTopic(topicId);
}

static getSubscriptionAttributes(callback) {
if (!checkIfInitialized()) return;

Expand Down
Loading

0 comments on commit 481e089

Please sign in to comment.