Skip to content

Commit

Permalink
added accent color to push notifications (#225)
Browse files Browse the repository at this point in the history
* added accent color to push notifications

* changelog and versioning

* formatting

* updated the changelogs

* updated the changelogs

* Update CHANGELOG.md

---------

Co-authored-by: Artūrs Kadiķis <kadikis.arturs@gmail.com>
  • Loading branch information
peterBrxwn and ArtursKadikis committed Jul 10, 2023
1 parent 99e6d7d commit d9c73be
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 23.2.4
* Added new method to the Countly Config Object 'setPushNotificationAccentColor' to set notification accent color.
* Added 'setPushTokenType' and 'setPushNotificationChannel' calls to replace deprecated calls to the Countly Config Object.
* Deprecated the following SDK call: 'CountlyConfig.pushTokenType'

## 23.2.3
* Fixed bug where the push notification type was not correctly set during init

Expand Down
11 changes: 9 additions & 2 deletions Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,20 @@ _configToJson = function (config) {
if (config.enableApm) {
json['enableApm'] = config.enableApm;
}
const pushNotification = {};
if (config.tokenType) {
const pushNotification = {};
pushNotification['tokenType'] = config.tokenType;
}
if (config.channelName) {
pushNotification['channelName'] = config.channelName;
}
if (config.channelDescription) {
pushNotification['channelDescription'] = config.channelDescription;
json['pushNotification'] = pushNotification;
}
if (config.accentColor) {
pushNotification['accentColor'] = config.accentColor;
}
json['pushNotification'] = pushNotification;
if (config.allowedIntentClassNames) {
json['allowedIntentClassNames'] = config.allowedIntentClassNames;
}
Expand Down
40 changes: 40 additions & 0 deletions CountlyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class CountlyConfig {

/**
* Method to set the push token type
* @deprecated
* Use setPushTokenType() instead to set pushToken
* Use setPushNotificationChannelInformation() instead to set channel information
*
* @param {TokenType} tokenType token type
* @param {String} channelName channel name
Expand All @@ -144,6 +147,43 @@ class CountlyConfig {
return this;
}

/**
* Method to set the push token type
* NB: ONLY FOR iOS
*
* @param {Countly.messagingMode} tokenType token type
* Possible values include 'DEVELOPMENT', 'PRODUCTION', 'ADHOC'.
*/
setPushTokenType(tokenType) {
this.tokenType = tokenType;
return this;
}

/**
* Method to set the push channel name and description
* NB: ONLY FOR ANDROID
*
* @param {String} name channel name
* @param {String} description channel description
*/
setPushNotificationChannelInformation(name, description) {
this.channelName = name;
this.channelDescription = description;
return this;
}

/**
* Method to set the push notification accent color
* NB: ONLY FOR ANDROID
*
* @param {String} accentColor notification accent color
* example '#000000'
*/
setPushNotificationAccentColor(accentColor) {
this.accentColor = accentColor;
return this;
}

/**
* Method to configure intent redirection check
*
Expand Down
2 changes: 1 addition & 1 deletion CountlyReactNative.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CountlyReactNative'
s.version = '23.2.3'
s.version = '23.2.4'
s.license = {
:type => 'COMMUNITY',
:text => <<-LICENSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ly.count.android.sdk.react;

import android.app.Activity;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
import android.util.Log;
Expand Down Expand Up @@ -83,7 +84,7 @@ public String toString() {
public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener {

public static final String TAG = "CountlyRNPlugin";
private String COUNTLY_RN_SDK_VERSION_STRING = "23.2.3";
private String COUNTLY_RN_SDK_VERSION_STRING = "23.2.4";
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";

private static final CountlyConfig config = new CountlyConfig();
Expand Down Expand Up @@ -228,6 +229,9 @@ private void populateConfig(JSONObject _config) {
int messagingMode = Integer.parseInt(pushObject.getString("tokenType"));
channelName = pushObject.getString("channelName");
channelDescription = pushObject.getString("channelDescription");
if (pushObject.has("accentColor")) {
setHexNotificationAccentColor(pushObject.getString("accentColor"));
}

if (messagingMode == 0) {
CountlyReactNative.messagingMode = Countly.CountlyMessagingMode.PRODUCTION;
Expand Down Expand Up @@ -297,6 +301,33 @@ private void populateConfig(JSONObject _config) {
}
}

private void setHexNotificationAccentColor(final String hex) {
if (hex == null) {
log("setHexNotificationAccentColor: invalid HEX color value. 'null' is not a valid color.", LogLevel.ERROR);
return;
}
if (hex.isEmpty() || hex.charAt(0) != '#') {
log("setHexNotificationAccentColor: invalid HEX color value. Valid colors should start with '#': " + hex, LogLevel.ERROR);
return;
}
if (hex.length() != 7 && hex.length() != 9) {
log("setHexNotificationAccentColor: invalid HEX color value, unexpected size. Hex color should be 7 or 9 in lenght: " + hex, LogLevel.ERROR);
return;
}

try {
int color = Color.parseColor(hex);
CountlyPush.setNotificationAccentColor(
Color.alpha(color),
Color.red(color),
Color.green(color),
Color.blue(color)
);
} catch (IllegalArgumentException e) {
log("setHexNotificationAccentColor: invalid HEX color value: " + hex + " Error: " + e, LogLevel.ERROR);
}
}

public static Map<String, String> toMapString(JSONObject jsonobj) {
Map<String, String> map = new HashMap<>();
try {
Expand Down
2 changes: 1 addition & 1 deletion example/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rm App.js
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js

yarn add countly-sdk-react-native-bridge@23.2.3
yarn add countly-sdk-react-native-bridge@23.2.4

cd ./ios
pod install
Expand Down
2 changes: 1 addition & 1 deletion ios/src/CountlyReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @interface CountlyFeedbackWidget ()
+ (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
@end

NSString *const kCountlyReactNativeSDKVersion = @"23.2.3";
NSString *const kCountlyReactNativeSDKVersion = @"23.2.4";
NSString *const kCountlyReactNativeSDKName = @"js-rnb-ios";

CLYPushTestMode const CLYPushTestModeProduction = @"CLYPushTestModeProduction";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "countly-sdk-react-native-bridge",
"version": "23.2.3",
"version": "23.2.4",
"author": "Countly <hello@count.ly> (https://count.ly/)",
"bugs": {
"url": "https://github.com/Countly/countly-sdk-react-native-bridge/issues"
Expand Down

0 comments on commit d9c73be

Please sign in to comment.