|
1 | 1 | package ly.count.android.sdk.react; |
2 | 2 |
|
3 | 3 | import android.app.Activity; |
| 4 | +import android.graphics.Color; |
4 | 5 | import android.media.AudioAttributes; |
5 | 6 | import android.net.Uri; |
6 | 7 | import android.util.Log; |
@@ -83,7 +84,7 @@ public String toString() { |
83 | 84 | public class CountlyReactNative extends ReactContextBaseJavaModule implements LifecycleEventListener { |
84 | 85 |
|
85 | 86 | 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"; |
87 | 88 | private String COUNTLY_RN_SDK_NAME = "js-rnb-android"; |
88 | 89 |
|
89 | 90 | private static final CountlyConfig config = new CountlyConfig(); |
@@ -228,6 +229,9 @@ private void populateConfig(JSONObject _config) { |
228 | 229 | int messagingMode = Integer.parseInt(pushObject.getString("tokenType")); |
229 | 230 | channelName = pushObject.getString("channelName"); |
230 | 231 | channelDescription = pushObject.getString("channelDescription"); |
| 232 | + if (pushObject.has("accentColor")) { |
| 233 | + setHexNotificationAccentColor(pushObject.getString("accentColor")); |
| 234 | + } |
231 | 235 |
|
232 | 236 | if (messagingMode == 0) { |
233 | 237 | CountlyReactNative.messagingMode = Countly.CountlyMessagingMode.PRODUCTION; |
@@ -297,6 +301,33 @@ private void populateConfig(JSONObject _config) { |
297 | 301 | } |
298 | 302 | } |
299 | 303 |
|
| 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 | + |
300 | 331 | public static Map<String, String> toMapString(JSONObject jsonobj) { |
301 | 332 | Map<String, String> map = new HashMap<>(); |
302 | 333 | try { |
|
0 commit comments