Skip to content

Commit

Permalink
Merge pull request #33 from apptentive/develop
Browse files Browse the repository at this point in the history
Release 5.1.4
  • Loading branch information
weeeBox authored Aug 15, 2018
2 parents 4f494cb + 3c21354 commit af91304
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This document lets you know what has changed in the React Native module. For cha
- [Android Changelog](https://github.com/apptentive/apptentive-android/blob/master/CHANGELOG.md)
- [iOS Changelog](https://github.com/apptentive/apptentive-ios/blob/master/CHANGELOG.md)

# 2018-08-15 - v5.1.4

- Fixed Android build issues
- Improved configuration handling

# 2018-07-26 - v5.1.3

- Fix check for registered status on iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import android.support.annotation.Nullable;

import com.apptentive.android.sdk.Apptentive;
import com.apptentive.android.sdk.ApptentiveConfiguration;
import com.apptentive.android.sdk.ApptentiveInternal;
import com.apptentive.android.sdk.ApptentiveLog;
import com.apptentive.android.sdk.conversation.Conversation;
import com.apptentive.android.sdk.conversation.ConversationDispatchTask;
import com.apptentive.android.sdk.lifecycle.ApptentiveActivityLifecycleCallbacks;
import com.apptentive.android.sdk.module.messagecenter.UnreadMessagesListener;
import com.apptentive.android.sdk.util.ObjectUtils;
import com.apptentive.android.sdk.util.StringUtils;
Expand Down Expand Up @@ -45,7 +48,7 @@ public String getName() {
//region JavaScript bindings

@ReactMethod
public void register(ReadableMap configuration, Promise promise) {
public void register(ReadableMap configurationMap, Promise promise) {
try {
Application application = reactContextWrapper.getApplication();

Expand All @@ -55,7 +58,7 @@ public void register(ReadableMap configuration, Promise promise) {
return;
}

Map<String, Object> config = toHashMap(configuration);
Map<String, Object> config = toHashMap(configurationMap);
String apptentiveKey = ObjectUtils.as(config.get("apptentiveKey"), String.class);
if (StringUtils.isNullOrEmpty(apptentiveKey)) {
promise.reject(CODE_APPTENTIVE, "Apptentive key is null or empty");
Expand All @@ -68,7 +71,18 @@ public void register(ReadableMap configuration, Promise promise) {
return;
}

Apptentive.register(application, apptentiveKey, apptentiveSignature);
ApptentiveConfiguration configuration = new ApptentiveConfiguration(apptentiveKey, apptentiveSignature);
ApptentiveLog.Level logLevel = parseLogLevel(ObjectUtils.as(config.get("logLevel"), String.class));
if (logLevel != null) {
configuration.setLogLevel(logLevel);
}

Boolean shouldSanitizeLogMessages = ObjectUtils.as(config.get("shouldSanitizeLogMessages"), Boolean.class);
if (shouldSanitizeLogMessages != null) {
configuration.setShouldSanitizeLogMessages(shouldSanitizeLogMessages);
}

Apptentive.register(application, configuration);

ApptentiveInternal instance = ObjectUtils.as(ApptentiveInternal.getInstance(), ApptentiveInternal.class);
if (instance == null) {
Expand All @@ -82,9 +96,11 @@ public void register(ReadableMap configuration, Promise promise) {
return;
}

instance.getRegisteredLifecycleCallbacks().onActivityCreated(currentActivity, null);
instance.getRegisteredLifecycleCallbacks().onActivityStarted(currentActivity);
instance.getRegisteredLifecycleCallbacks().onActivityResumed(currentActivity);
ApptentiveActivityLifecycleCallbacks lifecycleCallbacks = ApptentiveActivityLifecycleCallbacks.getInstance();
lifecycleCallbacks.onActivityCreated(currentActivity, null);
lifecycleCallbacks.onActivityStarted(currentActivity);
lifecycleCallbacks.onActivityResumed(currentActivity);

Apptentive.addUnreadMessagesListener(this);
Apptentive.setAuthenticationFailedListener(this);
promise.resolve(Boolean.TRUE);
Expand All @@ -93,6 +109,26 @@ public void register(ReadableMap configuration, Promise promise) {
}
}

private ApptentiveLog.Level parseLogLevel(String logLevel) {
if (!StringUtils.isNullOrEmpty(logLevel)) {
switch (logLevel.toLowerCase()) {
case "verbose":
return ApptentiveLog.Level.VERBOSE;
case "debug":
return ApptentiveLog.Level.DEBUG;
case "info":
return ApptentiveLog.Level.INFO;
case "warn":
case "warning":
return ApptentiveLog.Level.WARN;
case "error":
return ApptentiveLog.Level.ERROR;
}
}

return null;
}

@ReactMethod
public void presentMessageCenter(ReadableMap customData, Promise promise) {
try {
Expand Down Expand Up @@ -449,4 +485,4 @@ public void onFinish(boolean result) {
}

//endregion
}
}
2 changes: 1 addition & 1 deletion android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="apptentive_distribution">React Native</string>
<string name="apptentive_distribution_version">5.1.3</string>
<string name="apptentive_distribution_version">5.1.4</string>
</resources>
2 changes: 1 addition & 1 deletion apptentive-react-native.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "apptentive-react-native"
s.version = "5.1.3"
s.version = "5.1.4"
s.summary = "Apptentive SDK module for React Native"

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion ios/RNApptentiveModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (dispatch_queue_t)methodQueue
if (configuration) {
configuration.appID = configurationDictionary[@"appleID"];
configuration.distributionName = @"React Native";
configuration.distributionVersion = @"5.1.3";
configuration.distributionVersion = @"5.1.4";
[Apptentive registerWithConfiguration:configuration];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(messageCenterUnreadCountChangedNotification:) name:ApptentiveMessageCenterUnreadCountChangedNotification object:nil];
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": "apptentive-react-native",
"version": "5.1.3",
"version": "5.1.4",
"description": "React Native Module for Apptentive SDK",
"main": "js/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions sample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class App extends Component {

// Override log level (optional)
configuration.logLevel = 'verbose';
configuration.shouldSanitizeLogMessages = false;

// Register Apptentive
Apptentive.register(configuration)
Expand Down

0 comments on commit af91304

Please sign in to comment.