-
Notifications
You must be signed in to change notification settings - Fork 60
feat!: support HealthPulse integration #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
b6f8479
0aa83cb
d847b82
5dff808
8c04a7c
8a29e86
9b6c8a6
e7a67d2
fcaa722
0dcefaa
a98064a
8d201a0
1d295f8
be92e11
e82da3a
2108807
caf7839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,11 @@ private void setIntentExtras(Intent intent, String key, JSONObject data) { | |
| return; | ||
| } | ||
|
|
||
| // ODK does not have boolean data type | ||
| if (value instanceof String strValue && ("true".equals(strValue) || "false".equals(strValue))) { | ||
| value = Boolean.parseBoolean(strValue); | ||
| } | ||
|
|
||
| intent.putExtra(key, (Serializable) value); | ||
|
|
||
| } catch (Exception exception) { | ||
|
|
@@ -234,7 +239,7 @@ public Optional<JSONObject> getData() { | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| JSONObject json = parseBundleToJson(intent.getExtras()); | ||
| JSONObject json = parseBundleToJson(null, intent.getExtras()); | ||
| if (json == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
@@ -244,13 +249,13 @@ public Optional<JSONObject> getData() { | |
|
|
||
| //> PRIVATE | ||
|
|
||
| private JSONObject parseBundleToJson(Bundle bundle) { | ||
| private JSONObject parseBundleToJson(String parentKey, Bundle bundle) { | ||
| try { | ||
| JSONObject json = new JSONObject(); | ||
| bundle | ||
| .keySet() | ||
| .iterator() | ||
| .forEachRemaining(key -> setValueInJson(key, json, bundle)); | ||
| .forEachRemaining(key -> setValueInJson(parentKey, key, json, bundle)); | ||
| return json; | ||
|
|
||
| } catch (Exception exception) { | ||
|
|
@@ -260,33 +265,36 @@ private JSONObject parseBundleToJson(Bundle bundle) { | |
| return null; | ||
| } | ||
|
|
||
| private void setValueInJson(String key, JSONObject json, Bundle bundle) { | ||
| private void setValueInJson(String parentKey, String childKey, JSONObject json, Bundle bundle) { | ||
| String key = ("detectedRdt".equals(parentKey) && "concerns".equals(childKey)) | ||
| ? "detectionConcerns" | ||
| : childKey; | ||
| try { | ||
| Object value = bundle.get(key); | ||
| Object value = bundle.get(childKey); | ||
|
|
||
| if (value instanceof Bitmap) { | ||
| json.put(key, parseBitmapImageToBase64((Bitmap) value)); | ||
| json.put(key, parseBitmapImageToBase64((Bitmap) value, false)); | ||
| return; | ||
| } | ||
|
|
||
| if (value instanceof Bundle) { | ||
| json.put(key, parseBundleToJson((Bundle) value)); | ||
| json.put(key, parseBundleToJson(key, (Bundle) value)); | ||
| return; | ||
| } | ||
|
|
||
| if (isBundleList(value)) { | ||
| JSONArray jsonArray = ((List<Bundle>) value) | ||
| .stream() | ||
| .map(this::parseBundleToJson) | ||
| .map(val -> this.parseBundleToJson(key, val)) | ||
| .collect(Collector.of(JSONArray::new, JSONArray::put, JSONArray::put)); | ||
|
|
||
| json.put(key, jsonArray); | ||
| return; | ||
| } | ||
|
|
||
| Optional<Uri> imagePath = getImageUri(value); | ||
| if (imagePath.isPresent()) { | ||
| json.put(key, getImageFromStoragePath(imagePath.get())); | ||
| boolean keepFullResolution = bundle.getBoolean("sampleImage", false); | ||
| json.put(key, getImageFromStoragePath(imagePath.get(), keepFullResolution)); | ||
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -321,7 +329,7 @@ private Optional<Uri> getImageUri(Object value) { | |
| return getUriFromFilePath(path); | ||
| } | ||
|
|
||
| private String getImageFromStoragePath(Uri filePath) { | ||
| private String getImageFromStoragePath(Uri filePath, boolean keepFullResolution) { | ||
| trace(this, "ChtExternalApp :: Retrieving image from storage path."); | ||
|
|
||
| try ( | ||
|
|
@@ -331,7 +339,7 @@ private String getImageFromStoragePath(Uri filePath) { | |
| InputStream file = new FileInputStream(parcelFileDescriptor.getFileDescriptor()); | ||
| ){ | ||
| Bitmap imgBitmap = BitmapFactory.decodeStream(file); | ||
| return parseBitmapImageToBase64(imgBitmap); | ||
| return parseBitmapImageToBase64(imgBitmap, keepFullResolution); | ||
|
|
||
| } catch (Exception exception) { | ||
| error(exception, "ChtExternalApp :: Failed to process image file from path: %s", filePath); | ||
|
|
@@ -340,10 +348,11 @@ private String getImageFromStoragePath(Uri filePath) { | |
| return null; | ||
| } | ||
|
|
||
| private String parseBitmapImageToBase64(Bitmap imgBitmap) throws IOException { | ||
| private String parseBitmapImageToBase64(Bitmap imgBitmap, boolean keepFullResolution) throws IOException { | ||
| try (ByteArrayOutputStream outputFile = new ByteArrayOutputStream()) { | ||
| trace(this, "ChtExternalApp :: Compressing image file."); | ||
| imgBitmap.compress(Bitmap.CompressFormat.JPEG, 75, outputFile); | ||
| int quality = keepFullResolution ? 100 : 75; | ||
| imgBitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputFile); | ||
|
|
||
| trace(this, "ChtExternalApp :: Encoding image file to Base64."); | ||
| byte[] imageBytes = outputFile.toByteArray(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.