@sentiance-react-native/user-context 6.6.0-rc1 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,17 @@ if (findProject(':core')) {
15
15
  throw new GradleException('Could not find the @sentiance-react-native/core package, have you installed it?')
16
16
  }
17
17
 
18
+ def eventTimelineProj
19
+ if (findProject(':event-timeline')) {
20
+ eventTimelineProj = project(':event-timeline')
21
+ } else if (findProject(':sentiance-react-native_event-timeline')) {
22
+ eventTimelineProj = project(':sentiance-react-native_event-timeline')
23
+ } else if (findProject(':@sentiance-react-native_event-timeline')) {
24
+ eventTimelineProj = project(':@sentiance-react-native_event-timeline')
25
+ } else {
26
+ throw new GradleException('Could not find the @sentiance-react-native/event-timeline package, have you installed it?')
27
+ }
28
+
18
29
  android {
19
30
  compileOptions {
20
31
  sourceCompatibility JavaVersion.VERSION_1_8
@@ -30,10 +41,10 @@ applyAndroidVersionsFrom(corePackageJson)
30
41
  def sentianceSdkVersion = getSentianceSdkVersion()
31
42
 
32
43
  dependencies {
33
- api coreProj
34
-
35
44
  implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
36
45
  api("com.sentiance:sdk-user-context") { transitive = true }
46
+ implementation coreProj
47
+ implementation eventTimelineProj
37
48
  }
38
49
 
39
50
  applyReactNativeDependency()
@@ -3,14 +3,10 @@ package com.sentiance.react.bridge.usercontext;
3
3
  import com.facebook.react.bridge.Arguments;
4
4
  import com.facebook.react.bridge.WritableArray;
5
5
  import com.facebook.react.bridge.WritableMap;
6
+ import com.sentiance.react.bridge.eventtimeline.converters.OnDeviceTypesConverter;
6
7
  import com.sentiance.sdk.ondevice.api.Attribute;
7
- import com.sentiance.sdk.ondevice.api.GeoLocation;
8
- import com.sentiance.sdk.ondevice.api.Waypoint;
9
8
  import com.sentiance.sdk.ondevice.api.event.Event;
10
- import com.sentiance.sdk.ondevice.api.event.StationaryEvent;
11
- import com.sentiance.sdk.ondevice.api.event.TransportEvent;
12
9
  import com.sentiance.sdk.ondevice.api.segment.Segment;
13
- import com.sentiance.sdk.ondevice.api.venue.Venue;
14
10
  import com.sentiance.sdk.usercontext.api.RequestUserContextError;
15
11
  import com.sentiance.sdk.usercontext.api.RequestUserContextFailureReason;
16
12
  import com.sentiance.sdk.usercontext.api.UserContext;
@@ -20,18 +16,13 @@ import com.sentiance.sdk.util.DateTime;
20
16
  import java.util.List;
21
17
 
22
18
  public class SentianceUserContextConverter {
19
+ private final OnDeviceTypesConverter onDeviceTypesConverter;
23
20
 
24
- public static WritableMap convertGeoLocation(GeoLocation location) {
25
- WritableMap locationMap = Arguments.createMap();
26
-
27
- locationMap.putDouble("latitude", location.getLatitude());
28
- locationMap.putDouble("longitude", location.getLongitude());
29
- locationMap.putInt("accuracy", location.getAccuracyInMeters());
30
-
31
- return locationMap;
21
+ public SentianceUserContextConverter() {
22
+ onDeviceTypesConverter = new OnDeviceTypesConverter();
32
23
  }
33
24
 
34
- private static WritableMap convertSegment(Segment segment) {
25
+ private WritableMap convertSegment(Segment segment) {
35
26
  WritableMap map = Arguments.createMap();
36
27
 
37
28
  map.putString("category", segment.getCategory().name());
@@ -59,34 +50,7 @@ public class SentianceUserContextConverter {
59
50
  return map;
60
51
  }
61
52
 
62
- private static WritableMap convertEvent(Event event) {
63
- WritableMap map = Arguments.createMap();
64
-
65
- map.putString("id", event.getId());
66
- map.putString("startTime", event.getStartTime().toString());
67
- map.putDouble("startTimeEpoch", event.getStartTime().getEpochTime());
68
- if (event.getEndTime() != null) {
69
- map.putString("endTime", event.getEndTime().toString());
70
- map.putDouble("endTimeEpoch", event.getEndTime().getEpochTime());
71
-
72
- Long durationInSeconds = event.getDurationInSeconds();
73
- if (durationInSeconds != null) {
74
- map.putDouble("durationInSeconds", durationInSeconds);
75
- }
76
- }
77
-
78
- map.putString("type", event.getEventType().toString());
79
-
80
- if (event instanceof StationaryEvent) {
81
- addStationaryEventInfo(map, (StationaryEvent) event);
82
- } else if (event instanceof TransportEvent) {
83
- addTransportEventInfo(map, (TransportEvent) event);
84
- }
85
-
86
- return map;
87
- }
88
-
89
- public static WritableArray convertCriteriaList(List<UserContextUpdateCriteria> criteria) {
53
+ public WritableArray convertCriteriaList(List<UserContextUpdateCriteria> criteria) {
90
54
  WritableArray array = Arguments.createArray();
91
55
  for (UserContextUpdateCriteria criterion : criteria) {
92
56
  array.pushString(criterion.toString());
@@ -94,13 +58,13 @@ public class SentianceUserContextConverter {
94
58
  return array;
95
59
  }
96
60
 
97
- public static WritableMap convertUserContext(UserContext userContext) {
61
+ public WritableMap convertUserContext(UserContext userContext) {
98
62
  WritableMap userContextMap = Arguments.createMap();
99
63
 
100
64
  // Events
101
65
  WritableArray eventArray = Arguments.createArray();
102
66
  for (Event event : userContext.getEvents()) {
103
- eventArray.pushMap(convertEvent(event));
67
+ eventArray.pushMap(onDeviceTypesConverter.convertEvent(event));
104
68
  }
105
69
  userContextMap.putArray("events", eventArray);
106
70
 
@@ -113,17 +77,17 @@ public class SentianceUserContextConverter {
113
77
 
114
78
  // Last know location
115
79
  if (userContext.getLastKnownLocation() != null) {
116
- userContextMap.putMap("lastKnownLocation", convertGeoLocation(userContext.getLastKnownLocation()));
80
+ userContextMap.putMap("lastKnownLocation", onDeviceTypesConverter.convertGeoLocation(userContext.getLastKnownLocation()));
117
81
  }
118
82
 
119
83
  // Home
120
84
  if (userContext.getHome() != null) {
121
- userContextMap.putMap("home", convertVenue(userContext.getHome()));
85
+ userContextMap.putMap("home", onDeviceTypesConverter.convertVenue(userContext.getHome()));
122
86
  }
123
87
 
124
88
  // Work
125
89
  if (userContext.getWork() != null) {
126
- userContextMap.putMap("work", convertVenue(userContext.getWork()));
90
+ userContextMap.putMap("work", onDeviceTypesConverter.convertVenue(userContext.getWork()));
127
91
  }
128
92
 
129
93
  // Semantic time
@@ -132,7 +96,7 @@ public class SentianceUserContextConverter {
132
96
  return userContextMap;
133
97
  }
134
98
 
135
- public static String stringifyGetUserContextError(RequestUserContextError error) {
99
+ public String stringifyGetUserContextError(RequestUserContextError error) {
136
100
  RequestUserContextFailureReason reason = error.getReason();
137
101
  String details = "";
138
102
  switch (reason) {
@@ -148,52 +112,4 @@ public class SentianceUserContextConverter {
148
112
  }
149
113
  return String.format("Reason: %s - %s", reason.name(), details);
150
114
  }
151
-
152
- private static void addStationaryEventInfo(WritableMap map, StationaryEvent event) {
153
- if (event.getLocation() != null) {
154
- map.putMap("location", convertGeoLocation(event.getLocation()));
155
- }
156
- map.putMap("venue", convertVenue(event.getVenue()));
157
- }
158
-
159
- private static WritableMap convertVenue(Venue venue) {
160
- WritableMap venueMap = Arguments.createMap();
161
-
162
- if (venue.getLocation() != null) {
163
- venueMap.putMap("location", convertGeoLocation(venue.getLocation()));
164
- }
165
- venueMap.putString("significance", venue.getSignificance().name());
166
- venueMap.putString("type", venue.getType().name());
167
-
168
- return venueMap;
169
- }
170
-
171
- private static void addTransportEventInfo(WritableMap map, TransportEvent event) {
172
- map.putString("transportMode", event.getTransportMode().toString());
173
- map.putArray("waypoints", convertWaypointList(event.getWaypoints()));
174
-
175
- if (event.getDistanceInMeters() != null) {
176
- map.putInt("distance", event.getDistanceInMeters());
177
- }
178
- }
179
-
180
- public static WritableMap convertWaypoint(Waypoint waypoint) {
181
- WritableMap waypointMap = Arguments.createMap();
182
-
183
- waypointMap.putDouble("latitude", waypoint.getLatitude());
184
- waypointMap.putDouble("longitude", waypoint.getLongitude());
185
- waypointMap.putInt("accuracy", waypoint.getAccuracyInMeters());
186
- waypointMap.putDouble("timestamp", waypoint.getTimestamp());
187
-
188
- return waypointMap;
189
- }
190
-
191
- private static WritableArray convertWaypointList(List<Waypoint> waypointList) {
192
- WritableArray array = Arguments.createArray();
193
- for (Waypoint waypoint : waypointList) {
194
- array.pushMap(convertWaypoint(waypoint));
195
- }
196
- return array;
197
- }
198
-
199
115
  }
@@ -1,13 +1,10 @@
1
1
  package com.sentiance.react.bridge.usercontext;
2
2
 
3
- import static com.sentiance.react.bridge.usercontext.SentianceUserContextConverter.convertCriteriaList;
4
- import static com.sentiance.react.bridge.usercontext.SentianceUserContextConverter.convertUserContext;
5
-
6
3
  import android.content.Context;
7
4
 
8
5
  import com.facebook.react.bridge.Arguments;
9
6
  import com.facebook.react.bridge.WritableMap;
10
- import com.sentiance.react.bridge.core.base.AbstractSentianceEmitter;
7
+ import com.sentiance.react.bridge.core.common.base.AbstractSentianceEmitter;
11
8
  import com.sentiance.sdk.usercontext.api.UserContext;
12
9
  import com.sentiance.sdk.usercontext.api.UserContextUpdateCriteria;
13
10
 
@@ -16,15 +13,17 @@ import java.util.List;
16
13
  class SentianceUserContextEmitter extends AbstractSentianceEmitter {
17
14
 
18
15
  private static final String USER_CONTEXT_EVENT = "SENTIANCE_USER_CONTEXT_UPDATE_EVENT";
16
+ private final SentianceUserContextConverter converter;
19
17
 
20
18
  public SentianceUserContextEmitter(Context context) {
21
19
  super(context);
20
+ converter = new SentianceUserContextConverter();
22
21
  }
23
22
 
24
23
  void sendUserContext(List<UserContextUpdateCriteria> criteria, UserContext userContext) {
25
24
  WritableMap map = Arguments.createMap();
26
- map.putMap("userContext", convertUserContext(userContext));
27
- map.putArray("criteria", convertCriteriaList(criteria));
25
+ map.putMap("userContext", converter.convertUserContext(userContext));
26
+ map.putArray("criteria", converter.convertCriteriaList(criteria));
28
27
 
29
28
  sendEvent(USER_CONTEXT_EVENT, map);
30
29
  }
@@ -6,8 +6,8 @@ import androidx.annotation.Nullable;
6
6
  import com.facebook.react.bridge.Promise;
7
7
  import com.facebook.react.bridge.ReactApplicationContext;
8
8
  import com.facebook.react.bridge.ReactMethod;
9
- import com.sentiance.react.bridge.core.base.AbstractSentianceModule;
10
9
  import com.sentiance.react.bridge.core.common.SentianceSubscriptionsManager;
10
+ import com.sentiance.react.bridge.core.common.base.AbstractSentianceModule;
11
11
  import com.sentiance.react.bridge.usercontext.utils.ErrorCodes;
12
12
  import com.sentiance.sdk.Sentiance;
13
13
  import com.sentiance.sdk.usercontext.api.RequestUserContextError;
@@ -20,12 +20,14 @@ public class SentianceUserContextModule extends AbstractSentianceModule {
20
20
  private static final String NATIVE_MODULE_NAME = "SentianceUserContext";
21
21
 
22
22
  private final SentianceUserContextEmitter emitter;
23
+ private final SentianceUserContextConverter converter;
23
24
  private @Nullable
24
25
  UserContextUpdateListener mUserContextUpdateListener;
25
26
 
26
27
  public SentianceUserContextModule(ReactApplicationContext reactContext) {
27
28
  super(reactContext, Sentiance.getInstance(reactContext), new SentianceSubscriptionsManager());
28
29
  emitter = new SentianceUserContextEmitter(reactContext);
30
+ converter = new SentianceUserContextConverter();
29
31
  }
30
32
 
31
33
  @NonNull
@@ -46,11 +48,11 @@ public class SentianceUserContextModule extends AbstractSentianceModule {
46
48
  .addOnCompleteListener(pendingOperation -> {
47
49
  if (pendingOperation.isSuccessful()) {
48
50
  UserContext userContext = pendingOperation.getResult();
49
- promise.resolve(SentianceUserContextConverter.convertUserContext(userContext));
51
+ promise.resolve(converter.convertUserContext(userContext));
50
52
  } else {
51
53
  RequestUserContextError error = pendingOperation.getError();
52
54
  promise.reject(ErrorCodes.E_SDK_REQUEST_USER_CONTEXT_ERROR,
53
- SentianceUserContextConverter.stringifyGetUserContextError(error));
55
+ converter.stringifyGetUserContextError(error));
54
56
  }
55
57
  });
56
58
  }
package/lib/index.d.ts CHANGED
@@ -199,6 +199,10 @@ declare module "@sentiance-react-native/user-context" {
199
199
  longitude: number;
200
200
  accuracy: number; // in meters
201
201
  timestamp: number; // UTC epoch time in milliseconds
202
+ speedInMps?: number; // in meters per second
203
+ speedLimitInMps?: number; // in meters per second
204
+ hasUnlimitedSpeedLimit: boolean;
205
+ isSpeedLimitInfoSet: boolean;
202
206
  }
203
207
 
204
208
  export interface Venue {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentiance-react-native/user-context",
3
- "version": "6.6.0-rc1",
4
- "description": "React Native Sentiance - This module provides an easy API to add user context awareness into your apps.",
3
+ "version": "6.6.0",
4
+ "description": "The Sentiance User Context library",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "scripts": {
@@ -14,11 +14,11 @@
14
14
  "sentiance"
15
15
  ],
16
16
  "peerDependencies": {
17
- "@sentiance-react-native/core": "6.6.0-rc1"
17
+ "@sentiance-react-native/core": "6.6.0"
18
18
  },
19
19
  "author": "",
20
20
  "license": "",
21
- "homepage": "https://github.com/sentiance/react-native-sentiance/user-context#readme",
21
+ "homepage": "https://github.com/sentiance/react-native-sentiance/tree/main/packages/user-context",
22
22
  "repository": "github:sentiance/react-native-sentiance",
23
23
  "publishConfig": {
24
24
  "access": "public"