6
6
import android .support .annotation .Nullable ;
7
7
8
8
import com .apptentive .android .sdk .Apptentive ;
9
+ import com .apptentive .android .sdk .ApptentiveConfiguration ;
9
10
import com .apptentive .android .sdk .ApptentiveInternal ;
11
+ import com .apptentive .android .sdk .ApptentiveLog ;
10
12
import com .apptentive .android .sdk .conversation .Conversation ;
11
13
import com .apptentive .android .sdk .conversation .ConversationDispatchTask ;
14
+ import com .apptentive .android .sdk .lifecycle .ApptentiveActivityLifecycleCallbacks ;
12
15
import com .apptentive .android .sdk .module .messagecenter .UnreadMessagesListener ;
13
16
import com .apptentive .android .sdk .util .ObjectUtils ;
14
17
import com .apptentive .android .sdk .util .StringUtils ;
@@ -45,7 +48,7 @@ public String getName() {
45
48
//region JavaScript bindings
46
49
47
50
@ ReactMethod
48
- public void register (ReadableMap configuration , Promise promise ) {
51
+ public void register (ReadableMap configurationMap , Promise promise ) {
49
52
try {
50
53
Application application = reactContextWrapper .getApplication ();
51
54
@@ -55,7 +58,7 @@ public void register(ReadableMap configuration, Promise promise) {
55
58
return ;
56
59
}
57
60
58
- Map <String , Object > config = toHashMap (configuration );
61
+ Map <String , Object > config = toHashMap (configurationMap );
59
62
String apptentiveKey = ObjectUtils .as (config .get ("apptentiveKey" ), String .class );
60
63
if (StringUtils .isNullOrEmpty (apptentiveKey )) {
61
64
promise .reject (CODE_APPTENTIVE , "Apptentive key is null or empty" );
@@ -68,7 +71,18 @@ public void register(ReadableMap configuration, Promise promise) {
68
71
return ;
69
72
}
70
73
71
- Apptentive .register (application , apptentiveKey , apptentiveSignature );
74
+ ApptentiveConfiguration configuration = new ApptentiveConfiguration (apptentiveKey , apptentiveSignature );
75
+ ApptentiveLog .Level logLevel = parseLogLevel (ObjectUtils .as (config .get ("logLevel" ), String .class ));
76
+ if (logLevel != null ) {
77
+ configuration .setLogLevel (logLevel );
78
+ }
79
+
80
+ Boolean shouldSanitizeLogMessages = ObjectUtils .as (config .get ("shouldSanitizeLogMessages" ), Boolean .class );
81
+ if (shouldSanitizeLogMessages != null ) {
82
+ configuration .setShouldSanitizeLogMessages (shouldSanitizeLogMessages );
83
+ }
84
+
85
+ Apptentive .register (application , configuration );
72
86
73
87
ApptentiveInternal instance = ObjectUtils .as (ApptentiveInternal .getInstance (), ApptentiveInternal .class );
74
88
if (instance == null ) {
@@ -82,9 +96,11 @@ public void register(ReadableMap configuration, Promise promise) {
82
96
return ;
83
97
}
84
98
85
- instance .getRegisteredLifecycleCallbacks ().onActivityCreated (currentActivity , null );
86
- instance .getRegisteredLifecycleCallbacks ().onActivityStarted (currentActivity );
87
- instance .getRegisteredLifecycleCallbacks ().onActivityResumed (currentActivity );
99
+ ApptentiveActivityLifecycleCallbacks lifecycleCallbacks = ApptentiveActivityLifecycleCallbacks .getInstance ();
100
+ lifecycleCallbacks .onActivityCreated (currentActivity , null );
101
+ lifecycleCallbacks .onActivityStarted (currentActivity );
102
+ lifecycleCallbacks .onActivityResumed (currentActivity );
103
+
88
104
Apptentive .addUnreadMessagesListener (this );
89
105
Apptentive .setAuthenticationFailedListener (this );
90
106
promise .resolve (Boolean .TRUE );
@@ -93,6 +109,26 @@ public void register(ReadableMap configuration, Promise promise) {
93
109
}
94
110
}
95
111
112
+ private ApptentiveLog .Level parseLogLevel (String logLevel ) {
113
+ if (!StringUtils .isNullOrEmpty (logLevel )) {
114
+ switch (logLevel .toLowerCase ()) {
115
+ case "verbose" :
116
+ return ApptentiveLog .Level .VERBOSE ;
117
+ case "debug" :
118
+ return ApptentiveLog .Level .DEBUG ;
119
+ case "info" :
120
+ return ApptentiveLog .Level .INFO ;
121
+ case "warn" :
122
+ case "warning" :
123
+ return ApptentiveLog .Level .WARN ;
124
+ case "error" :
125
+ return ApptentiveLog .Level .ERROR ;
126
+ }
127
+ }
128
+
129
+ return null ;
130
+ }
131
+
96
132
@ ReactMethod
97
133
public void presentMessageCenter (ReadableMap customData , Promise promise ) {
98
134
try {
@@ -449,4 +485,4 @@ public void onFinish(boolean result) {
449
485
}
450
486
451
487
//endregion
452
- }
488
+ }
0 commit comments