@woosmap/react-native-plugin-geofencing 0.11.0 → 0.11.1-beta.2

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.11.1
2
+ - Patch:
3
+ 1. Exposed config options `androidNotificationText` and `androidNotificationTitle` to set notification title and text on Android.
4
+ 2. Exposed `androidNotificationIconName` to set the notification icon name from Android `drawable` or `mipmap` folder.
5
+ 3. Exposed `androidNotificationIconUrl` to set the notification icon from the RN and expose `assets` folder.
6
+
1
7
  ## 0.11.0
2
8
  - Enhancement: Removed warning from iOS plugin code
3
9
 
@@ -21,12 +21,20 @@ import com.facebook.react.bridge.ReadableMap;
21
21
  import com.facebook.react.module.annotations.ReactModule;
22
22
  import com.facebook.react.modules.core.PermissionAwareActivity;
23
23
  import com.facebook.react.modules.core.PermissionListener;
24
+ import com.webgeoservices.woosmapgeofencing.NotificationIconProvider;
24
25
  import com.webgeoservices.woosmapgeofencing.Woosmap;
25
26
  import com.webgeoservices.woosmapgeofencing.WoosmapSettings;
26
27
  import com.webgeoservices.woosmapgeofencingcore.database.Region;
27
28
 
28
29
  import java.util.HashMap;
29
30
  import java.util.Iterator;
31
+ import java.util.concurrent.ExecutorService;
32
+ import java.util.concurrent.Executors;
33
+ import java.io.File;
34
+ import java.io.FileOutputStream;
35
+ import java.io.InputStream;
36
+ import java.net.HttpURLConnection;
37
+ import java.net.URL;
30
38
 
31
39
  @ReactModule(name = PluginGeofencingModule.NAME)
32
40
  public class PluginGeofencingModule extends ReactContextBaseJavaModule implements PermissionListener, LifecycleEventListener {
@@ -42,6 +50,7 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
42
50
  private WoosLocationReadyListener locationReadyListener;
43
51
  private WoosRegionReadyListener regionReadyListener;
44
52
  private Promise mNotificationPermissionsRequestPromise;
53
+ private final ExecutorService ioPool = Executors.newSingleThreadExecutor();
45
54
 
46
55
 
47
56
  public PluginGeofencingModule(ReactApplicationContext reactContext) {
@@ -100,6 +109,22 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
100
109
  WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
101
110
  }
102
111
 
112
+ if (map.hasKey(WoosmapMessageAndKey.androidNotificationText)) {
113
+ WoosmapSettings.updateServiceNotificationText = map.getString(WoosmapMessageAndKey.androidNotificationText);
114
+ }
115
+
116
+ if (map.hasKey(WoosmapMessageAndKey.androidNotificationTitle)) {
117
+ WoosmapSettings.updateServiceNotificationTitle = map.getString(WoosmapMessageAndKey.androidNotificationTitle);
118
+ }
119
+ if (map.hasKey(WoosmapMessageAndKey.androidNotificationIconName)) {
120
+ NotificationIconProvider.clearRuntimeOverrides(getReactApplicationContext());
121
+ setNotificationSmallIconByName(map.getString(WoosmapMessageAndKey.androidNotificationIconName), promise);
122
+ }
123
+ if (map.hasKey(WoosmapMessageAndKey.androidNotificationIconUrl)) {
124
+ NotificationIconProvider.clearRuntimeOverrides(getReactApplicationContext());
125
+ setNotificationSmallIconByUrl(map.getString(WoosmapMessageAndKey.androidNotificationIconUrl), promise);
126
+ }
127
+
103
128
  if (map.hasKey(WoosmapMessageAndKey.enableAirshipConnectorKey)){
104
129
  WoosmapUtil.setEnableAishipConnector(map.getBoolean(WoosmapMessageAndKey.enableAirshipConnectorKey), getReactApplicationContext());
105
130
  }
@@ -140,6 +165,85 @@ public class PluginGeofencingModule extends ReactContextBaseJavaModule implement
140
165
  return true;
141
166
  }
142
167
 
168
+ private void setNotificationSmallIconByName(String name, Promise promise) {
169
+ try {
170
+ NotificationIconProvider.setRuntimeSmallIconByName(getReactApplicationContext(), name);
171
+ } catch (Throwable ex) {
172
+ promise.reject("EICON", ex);
173
+ }
174
+ }
175
+
176
+ private void setNotificationSmallIconByUrl(String url, Promise promise) {
177
+ try {
178
+ //NotificationIconProvider.setRuntimeSmallIconFromUri(getReactApplicationContext(), url);
179
+ ioPool.execute(() -> {
180
+ try {
181
+ Log.d(NAME, "Saving icon file to local file path");
182
+ String filePath = materializeToCache(url);
183
+ if (filePath == null) {
184
+ Log.e(NAME, "Failed to download/ copy icon");
185
+ promise.reject(WoosmapMessageAndKey.errorCode, "Failed to copy/download icon: " + url);
186
+ return;
187
+ }
188
+ Log.d(NAME, "Saved file path is: " + filePath);
189
+ NotificationIconProvider.setRuntimeSmallIconFromFile(getReactApplicationContext(), filePath);
190
+ promise.resolve(WoosmapMessageAndKey.successMessage);
191
+ } catch (Throwable t) {
192
+ promise.reject(WoosmapMessageAndKey.errorCode, t.toString());
193
+ }
194
+ });
195
+ } catch (Throwable ex) {
196
+ Log.e(NAME, ex.toString());
197
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.toString());
198
+ }
199
+ }
200
+
201
+ private String materializeToCache(String uriString) throws Exception {
202
+ if (uriString == null || uriString.trim().isEmpty()) return null;
203
+
204
+ // destination file
205
+ File dest = new File(getReactApplicationContext().getCacheDir(), "woosmap_notif_icon.png");
206
+
207
+ if (uriString.startsWith("http://") || uriString.startsWith("https://")) {
208
+ // Download Metro/remote URL
209
+ URL url = new URL(uriString);
210
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
211
+ conn.setConnectTimeout(4000);
212
+ conn.setReadTimeout(4000);
213
+ conn.connect();
214
+ try (InputStream is = conn.getInputStream();
215
+ FileOutputStream os = new FileOutputStream(dest)) {
216
+ byte[] buf = new byte[8192];
217
+ int n;
218
+ while ((n = is.read(buf)) > 0) os.write(buf, 0, n);
219
+ } finally {
220
+ conn.disconnect();
221
+ }
222
+ return dest.getAbsolutePath();
223
+ }
224
+
225
+ if (uriString.startsWith("file://")) {
226
+ // Copy from local file to our cache (optional: could use as-is)
227
+ java.nio.file.Files.copy(
228
+ new File(uriString.substring("file://".length())).toPath(),
229
+ dest.toPath(),
230
+ java.nio.file.StandardCopyOption.REPLACE_EXISTING
231
+ );
232
+ return dest.getAbsolutePath();
233
+ }
234
+
235
+ // content:// and other schemes
236
+ android.net.Uri uri = android.net.Uri.parse(uriString);
237
+ try (InputStream is = getReactApplicationContext().getContentResolver().openInputStream(uri);
238
+ FileOutputStream os = new FileOutputStream(dest)) {
239
+ if (is == null) return null;
240
+ byte[] buf = new byte[8192];
241
+ int n;
242
+ while ((n = is.read(buf)) > 0) os.write(buf, 0, n);
243
+ return dest.getAbsolutePath();
244
+ }
245
+ }
246
+
143
247
  /***
144
248
  * Requests permissions. If the background permission is required then ACCESS_BACKGROUND_LOCATION is requested for devices above Android 9.
145
249
  * @param data Readable Array containing a boolean parameter to check if the background permission is required.
@@ -1,11 +1,18 @@
1
1
  package com.reactnativeplugingeofencing;
2
2
 
3
3
 
4
+ import com.webgeoservices.woosmapgeofencing.WoosmapSettings;
5
+ import com.webgeoservices.woosmapgeofencingcore.WoosmapSettingsCore;
6
+
4
7
  public class WoosmapMessageAndKey {
5
8
  protected static String errorCode = "1001";
6
9
  protected static String successMessage="OK";
7
10
  protected static String profileTrackingKey="trackingProfile";
8
11
  protected static String woosmapPrivateKeyString="privateKeyWoosmapAPI";
12
+ protected static String androidNotificationText="androidNotificationText";
13
+ protected static String androidNotificationTitle="androidNotificationTitle";
14
+ protected static String androidNotificationIconName="androidNotificationIconName";
15
+ protected static String androidNotificationIconUrl="androidNotificationIconUrl";
9
16
  protected static String invalidProfileTrackingError="Invalid tracking profile. Only possible values are liveTracking, passiveTracking, optimalPassiveTracking, visitsTracking, beaconTracking";
10
17
  protected static String permissionNotGrantedMessage="Required permissions not granted";
11
18
  protected static String permissionValueNotProvided="Permission value not provided";
@@ -22,5 +22,9 @@ export interface WoosmapGeofencingOptions {
22
22
  trackingProfile?: trackingProfile;
23
23
  enableAirshipConnector?: Boolean;
24
24
  protectedRegionSlot?: number;
25
+ androidNotificationTitle?: string;
26
+ androidNotificationText?: string;
27
+ androidNotificationIconName?: string;
28
+ androidNotificationIconUrl?: string;
25
29
  }
26
30
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/internal/types.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,UAAU,CAAC;AACjD,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,wBAAwB,GACxB,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/internal/types.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,UAAU,CAAC;AACjD,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,wBAAwB,GACxB,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/react-native-plugin-geofencing",
3
- "version": "0.11.0",
3
+ "version": "0.11.1-beta.2",
4
4
  "description": "This react-native plugin extends the functionality offered by the Woosmap Geofencing Mobile SDKs. Find more about the Woosmap Geofencing SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",