11
11
12
12
import com .facebook .react .bridge .ActivityEventListener ;
13
13
import com .facebook .react .bridge .LifecycleEventListener ;
14
- import com .facebook .react .modules .core .DeviceEventManagerModule ;
15
14
import com .google .android .gms .common .ConnectionResult ;
16
15
import com .google .android .gms .common .GoogleApiAvailability ;
17
16
@@ -65,27 +64,27 @@ public boolean getIsForeground() {
65
64
@ ReactMethod
66
65
public void register (ReadableMap config , Promise promise ) {
67
66
ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil .getInstance ();
68
- String connectionString = config .getString ("connectionString" );
67
+ String connectionString = config .getString (KEY_REGISTRATION_CONNECTIONSTRING );
69
68
if (connectionString == null ) {
70
69
promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_CONNECTION_STRING );
71
70
return ;
72
71
}
73
72
74
- String hubName = config .getString ("hubName" );
73
+ String hubName = config .getString (KEY_REGISTRATION_HUBNAME );
75
74
if (hubName == null ) {
76
75
promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_HUBNAME );
77
76
return ;
78
77
}
79
78
80
- String senderID = config .getString ("senderID" );
79
+ String senderID = config .getString (KEY_REGISTRATION_SENDERID );
81
80
if (senderID == null ) {
82
81
promise .reject (ERROR_INVALID_ARGUMENTS , ERROR_INVALID_SENDER_ID );
83
82
return ;
84
83
}
85
84
86
85
String [] tags = null ;
87
- if (config .hasKey ("tags" ) && !config .isNull ("tags" )) {
88
- ReadableArray tagsJson = config .getArray ("tags" );
86
+ if (config .hasKey (KEY_REGISTRATION_TAGS ) && !config .isNull (KEY_REGISTRATION_TAGS )) {
87
+ ReadableArray tagsJson = config .getArray (KEY_REGISTRATION_TAGS );
89
88
tags = new String [tagsJson .size ()];
90
89
for (int i = 0 ; i < tagsJson .size (); ++i ) {
91
90
tags [i ] = tagsJson .getString (i );
@@ -98,23 +97,28 @@ public void register(ReadableMap config, Promise promise) {
98
97
notificationHubUtil .setSenderID (reactContext , senderID );
99
98
notificationHubUtil .setTags (reactContext , tags );
100
99
101
- if (config .hasKey ("channelImportance" )) {
102
- int channelImportance = config .getInt ("channelImportance" );
100
+ if (config .hasKey (KEY_REGISTRATION_CHANNELNAME )) {
101
+ String channelName = config .getString (KEY_REGISTRATION_CHANNELNAME );
102
+ notificationHubUtil .setChannelName (reactContext , channelName );
103
+ }
104
+
105
+ if (config .hasKey (KEY_REGISTRATION_CHANNELIMPORTANCE )) {
106
+ int channelImportance = config .getInt (KEY_REGISTRATION_CHANNELIMPORTANCE );
103
107
notificationHubUtil .setChannelImportance (reactContext , channelImportance );
104
108
}
105
109
106
- if (config .hasKey ("channelShowBadge" )) {
107
- boolean channelShowBadge = config .getBoolean ("channelShowBadge" );
110
+ if (config .hasKey (KEY_REGISTRATION_CHANNELSHOWBADGE )) {
111
+ boolean channelShowBadge = config .getBoolean (KEY_REGISTRATION_CHANNELSHOWBADGE );
108
112
notificationHubUtil .setChannelShowBadge (reactContext , channelShowBadge );
109
113
}
110
114
111
- if (config .hasKey ("channelEnableLights" )) {
112
- boolean channelEnableLights = config .getBoolean ("channelEnableLights" );
115
+ if (config .hasKey (KEY_REGISTRATION_CHANNELENABLELIGHTS )) {
116
+ boolean channelEnableLights = config .getBoolean (KEY_REGISTRATION_CHANNELENABLELIGHTS );
113
117
notificationHubUtil .setChannelEnableLights (reactContext , channelEnableLights );
114
118
}
115
119
116
- if (config .hasKey ("channelEnableVibration" )) {
117
- boolean channelEnableVibration = config .getBoolean ("channelEnableVibration" );
120
+ if (config .hasKey (KEY_REGISTRATION_CHANNELENABLEVIBRATION )) {
121
+ boolean channelEnableVibration = config .getBoolean (KEY_REGISTRATION_CHANNELENABLEVIBRATION );
118
122
notificationHubUtil .setChannelEnableVibration (reactContext , channelEnableVibration );
119
123
}
120
124
@@ -170,9 +174,9 @@ public void onHostResume() {
170
174
if (activity != null ) {
171
175
Intent intent = activity .getIntent ();
172
176
if (intent != null ) {
173
- Bundle bundle = intent . getBundleExtra ( KEY_INTENT_NOTIFICATION );
177
+ Bundle bundle = ReactNativeUtil . getBundleFromIntent ( intent );
174
178
if (bundle != null ) {
175
- intent . removeExtra ( KEY_INTENT_NOTIFICATION );
179
+ ReactNativeUtil . removeNotificationFromIntent ( intent );
176
180
bundle .putBoolean (KEY_REMOTE_NOTIFICATION_FOREGROUND , false );
177
181
bundle .putBoolean (KEY_REMOTE_NOTIFICATION_USER_INTERACTION , true );
178
182
bundle .putBoolean (KEY_REMOTE_NOTIFICATION_COLDSTART , true );
@@ -194,7 +198,7 @@ public void onHostDestroy() {
194
198
195
199
@ Override
196
200
public void onNewIntent (Intent intent ) {
197
- Bundle bundle = intent . getBundleExtra ( KEY_INTENT_NOTIFICATION );
201
+ Bundle bundle = ReactNativeUtil . getBundleFromIntent ( intent );
198
202
if (bundle != null ) {
199
203
bundle .putBoolean (KEY_REMOTE_NOTIFICATION_FOREGROUND , false );
200
204
bundle .putBoolean (KEY_REMOTE_NOTIFICATION_USER_INTERACTION , true );
@@ -211,10 +215,7 @@ public class LocalBroadcastReceiver extends BroadcastReceiver {
211
215
@ Override
212
216
public void onReceive (Context context , Intent intent ) {
213
217
if (getIsForeground ()) {
214
- String event = intent .getStringExtra ("event" );
215
- String data = intent .getStringExtra ("data" );
216
- mReactContext .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
217
- .emit (event , data );
218
+ ReactNativeUtil .emitIntent (mReactContext , intent );
218
219
}
219
220
}
220
221
}
0 commit comments