Skip to content

Commit d9c73be

Browse files
added accent color to push notifications (#225)
* 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 <[email protected]>
1 parent 99e6d7d commit d9c73be

File tree

8 files changed

+90
-7
lines changed

8 files changed

+90
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 23.2.4
2+
* Added new method to the Countly Config Object 'setPushNotificationAccentColor' to set notification accent color.
3+
* Added 'setPushTokenType' and 'setPushNotificationChannel' calls to replace deprecated calls to the Countly Config Object.
4+
* Deprecated the following SDK call: 'CountlyConfig.pushTokenType'
5+
16
## 23.2.3
27
* Fixed bug where the push notification type was not correctly set during init
38

Countly.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,20 @@ _configToJson = function (config) {
137137
if (config.enableApm) {
138138
json['enableApm'] = config.enableApm;
139139
}
140+
const pushNotification = {};
140141
if (config.tokenType) {
141-
const pushNotification = {};
142142
pushNotification['tokenType'] = config.tokenType;
143+
}
144+
if (config.channelName) {
143145
pushNotification['channelName'] = config.channelName;
146+
}
147+
if (config.channelDescription) {
144148
pushNotification['channelDescription'] = config.channelDescription;
145-
json['pushNotification'] = pushNotification;
146149
}
150+
if (config.accentColor) {
151+
pushNotification['accentColor'] = config.accentColor;
152+
}
153+
json['pushNotification'] = pushNotification;
147154
if (config.allowedIntentClassNames) {
148155
json['allowedIntentClassNames'] = config.allowedIntentClassNames;
149156
}

CountlyConfig.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class CountlyConfig {
132132

133133
/**
134134
* Method to set the push token type
135+
* @deprecated
136+
* Use setPushTokenType() instead to set pushToken
137+
* Use setPushNotificationChannelInformation() instead to set channel information
135138
*
136139
* @param {TokenType} tokenType token type
137140
* @param {String} channelName channel name
@@ -144,6 +147,43 @@ class CountlyConfig {
144147
return this;
145148
}
146149

150+
/**
151+
* Method to set the push token type
152+
* NB: ONLY FOR iOS
153+
*
154+
* @param {Countly.messagingMode} tokenType token type
155+
* Possible values include 'DEVELOPMENT', 'PRODUCTION', 'ADHOC'.
156+
*/
157+
setPushTokenType(tokenType) {
158+
this.tokenType = tokenType;
159+
return this;
160+
}
161+
162+
/**
163+
* Method to set the push channel name and description
164+
* NB: ONLY FOR ANDROID
165+
*
166+
* @param {String} name channel name
167+
* @param {String} description channel description
168+
*/
169+
setPushNotificationChannelInformation(name, description) {
170+
this.channelName = name;
171+
this.channelDescription = description;
172+
return this;
173+
}
174+
175+
/**
176+
* Method to set the push notification accent color
177+
* NB: ONLY FOR ANDROID
178+
*
179+
* @param {String} accentColor notification accent color
180+
* example '#000000'
181+
*/
182+
setPushNotificationAccentColor(accentColor) {
183+
this.accentColor = accentColor;
184+
return this;
185+
}
186+
147187
/**
148188
* Method to configure intent redirection check
149189
*

CountlyReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CountlyReactNative'
3-
s.version = '23.2.3'
3+
s.version = '23.2.4'
44
s.license = {
55
:type => 'COMMUNITY',
66
:text => <<-LICENSE

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ly.count.android.sdk.react;
22

33
import android.app.Activity;
4+
import android.graphics.Color;
45
import android.media.AudioAttributes;
56
import android.net.Uri;
67
import android.util.Log;
@@ -83,7 +84,7 @@ public String toString() {
8384
public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener {
8485

8586
public static final String TAG = "CountlyRNPlugin";
86-
private String COUNTLY_RN_SDK_VERSION_STRING = "23.2.3";
87+
private String COUNTLY_RN_SDK_VERSION_STRING = "23.2.4";
8788
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";
8889

8990
private static final CountlyConfig config = new CountlyConfig();
@@ -228,6 +229,9 @@ private void populateConfig(JSONObject _config) {
228229
int messagingMode = Integer.parseInt(pushObject.getString("tokenType"));
229230
channelName = pushObject.getString("channelName");
230231
channelDescription = pushObject.getString("channelDescription");
232+
if (pushObject.has("accentColor")) {
233+
setHexNotificationAccentColor(pushObject.getString("accentColor"));
234+
}
231235

232236
if (messagingMode == 0) {
233237
CountlyReactNative.messagingMode = Countly.CountlyMessagingMode.PRODUCTION;
@@ -297,6 +301,33 @@ private void populateConfig(JSONObject _config) {
297301
}
298302
}
299303

304+
private void setHexNotificationAccentColor(final String hex) {
305+
if (hex == null) {
306+
log("setHexNotificationAccentColor: invalid HEX color value. 'null' is not a valid color.", LogLevel.ERROR);
307+
return;
308+
}
309+
if (hex.isEmpty() || hex.charAt(0) != '#') {
310+
log("setHexNotificationAccentColor: invalid HEX color value. Valid colors should start with '#': " + hex, LogLevel.ERROR);
311+
return;
312+
}
313+
if (hex.length() != 7 && hex.length() != 9) {
314+
log("setHexNotificationAccentColor: invalid HEX color value, unexpected size. Hex color should be 7 or 9 in lenght: " + hex, LogLevel.ERROR);
315+
return;
316+
}
317+
318+
try {
319+
int color = Color.parseColor(hex);
320+
CountlyPush.setNotificationAccentColor(
321+
Color.alpha(color),
322+
Color.red(color),
323+
Color.green(color),
324+
Color.blue(color)
325+
);
326+
} catch (IllegalArgumentException e) {
327+
log("setHexNotificationAccentColor: invalid HEX color value: " + hex + " Error: " + e, LogLevel.ERROR);
328+
}
329+
}
330+
300331
public static Map<String, String> toMapString(JSONObject jsonobj) {
301332
Map<String, String> map = new HashMap<>();
302333
try {

example/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm App.js
1111
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
1212
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js
1313

14-
14+
1515

1616
cd ./ios
1717
pod install

ios/src/CountlyReactNative.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ @interface CountlyFeedbackWidget ()
2424
+ (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary;
2525
@end
2626

27-
NSString *const kCountlyReactNativeSDKVersion = @"23.2.3";
27+
NSString *const kCountlyReactNativeSDKVersion = @"23.2.4";
2828
NSString *const kCountlyReactNativeSDKName = @"js-rnb-ios";
2929

3030
CLYPushTestMode const CLYPushTestModeProduction = @"CLYPushTestModeProduction";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "countly-sdk-react-native-bridge",
3-
"version": "23.2.3",
3+
"version": "23.2.4",
44
"author": "Countly <[email protected]> (https://count.ly/)",
55
"bugs": {
66
"url": "https://github.com/Countly/countly-sdk-react-native-bridge/issues"

0 commit comments

Comments
 (0)