From 6f4feabd039ec1270d3ecf9e5fe6d418a703a115 Mon Sep 17 00:00:00 2001 From: Leon Dudlik Date: Wed, 5 May 2021 13:45:22 +0200 Subject: [PATCH] Add version 2.0.0 --- .gitignore | 7 +++ CHANGELOG.md | 11 +++++ README.md | 2 +- hooks/dependencies-gradle-hook.js | 4 +- package.json | 51 +++++++++++---------- plugin.xml | 13 ++++-- src/android/PESDKPlugin.kt | 41 +++++++++-------- src/android/build.gradle | 4 +- types/configuration.ts | 1 + types/index.d.ts | 76 +++++++++++++++++-------------- www/photoeditorsdk.js | 46 +++++++++++++------ 11 files changed, 155 insertions(+), 101 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b568ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# OSX +# +.DS_Store + +# node.js +# +/node_modules/** \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a9feb1b..a0b0d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [2.0.0] + +### Changed + +* Improved API documentation. +* Deprecated `PESDK.loadResource` - use `PESDK.resolveStaticResource` instead. +* Updated minimum `cordova` version to 9.0.0. +* [Android] Updated native SDK to version 8. +* [Android] Updated minimum `cordova-android` version to 9.0.0. +* [iOS] Updated minimum `cordova-ios` version to 5.0.1. + ## [1.1.0] ### Changed diff --git a/README.md b/README.md index 0dcca46..08f4b31 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Open the editor with an image: PESDK.openEditor( successCallback, failureCallback, - PESDK.loadResource('www/assets/image.jpg') + PESDK.resolveStaticResource('www/assets/image.jpg') ); ``` diff --git a/hooks/dependencies-gradle-hook.js b/hooks/dependencies-gradle-hook.js index 1ddcd6f..12320ae 100644 --- a/hooks/dependencies-gradle-hook.js +++ b/hooks/dependencies-gradle-hook.js @@ -12,8 +12,8 @@ module.exports = (context) => { "\n" + BLOCK_START + ` - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" - classpath "ly.img.android.sdk:plugin:7.6.6"` + + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10" + classpath "ly.img.android.sdk:plugin:8.1.3"` + "\n" + BLOCK_END + "\n"; diff --git a/package.json b/package.json index 431bf36..a25d0d1 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,12 @@ { "name": "cordova-plugin-photoeditorsdk", - "title": "Cordova plugin for PhotoEditor SDK", - "version": "1.1.0", - "types": "./types/index.d.ts", - "cordova_name": "cordova-plugin-photoeditorsdk", "description": "A Cordova plugin for PhotoEditor SDK. Integrate the photo editor into your own HTML5, iOS or Android app - in minutes!", + "version": "2.0.0", + "types": "./types/index.d.ts", "main": "www/photoeditorsdk.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "repository": { - "type": "git", - "url": "https://github.com/imgly/pesdk-cordova.git" - }, - "homepage": "https://www.photoeditorsdk.com", - "author": { - "name": "img.ly GmbH", - "email": "contact@img.ly" - }, - "license": "BSD-3-Clause", - "licenseFilename": "LICENSE.md", - "readmeFilename": "README.md", "cordova": { "id": "cordova-plugin-photoeditorsdk", "platforms": [ @@ -28,30 +14,45 @@ "ios" ] }, - "engines": { - "cordovaDependencies": { - "1.0.0": { - "cordova-ios": ">4.3.0" - } - } - }, "keywords": [ + "cordova", + "photoeditorsdk", "ecosystem:cordova", "cordova-android", "cordova-ios", - "cordova", "image", "image editor", "imageeditor", "photo", "photo editor", "photoeditor", - "photoeditorsdk", "PhotoEditor SDK", "SDK", "ios", "android" ], + "repository": { + "type": "git", + "url": "https://github.com/imgly/pesdk-cordova.git" + }, + "homepage": "https://www.photoeditorsdk.com", + "author": { + "name": "img.ly GmbH", + "email": "contact@img.ly" + }, + "license": "BSD-3-Clause", + "engines": { + "cordovaDependencies": { + "1.0.0": { + "cordova-ios": ">4.3.0" + }, + "2.0.0": { + "cordova": ">=9.0.0", + "cordova-ios": ">5.0.0", + "cordova-android": ">=9.0.0" + } + } + }, "dependencies": { "async": "^3.2.0" } diff --git a/plugin.xml b/plugin.xml index 3cccf6e..44d6b79 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,13 +1,16 @@ - + PhotoEditorSDK A Cordova plugin for PhotoEditor SDK. Integrate the photo editor into your own HTML5, iOS or Android app - in minutes! - MIT - ecosystem:cordova,cordova-android,cordova-ios,cordova,image,image editor,imageeditor,photo,photo editor,photoeditor,photoeditorsdk,PhotoEditor SDK,SDK,ios,android + BSD-3-Clause + cordova,cordova-android,cordova-ios,image,image editor,imageeditor,photo,photo editor,photoeditor,photoeditorsdk,PhotoEditor SDK,SDK,ios,android https://github.com/imgly/pesdk-cordova.git - img.ly GmbH,contact@img.ly + img.ly GmbH, contact@img.ly + - + + + diff --git a/src/android/PESDKPlugin.kt b/src/android/PESDKPlugin.kt index f097d7f..e156ca7 100644 --- a/src/android/PESDKPlugin.kt +++ b/src/android/PESDKPlugin.kt @@ -13,8 +13,9 @@ import ly.img.android.PESDK import ly.img.android.pesdk.PhotoEditorSettingsList import ly.img.android.pesdk.backend.model.EditorSDKResult import ly.img.android.pesdk.backend.model.state.LoadSettings -import ly.img.android.pesdk.backend.model.state.SaveSettings import ly.img.android.pesdk.backend.model.state.manager.SettingsList +import ly.img.android.pesdk.backend.model.constant.OutputMode +import ly.img.android.pesdk.backend.encoder.Encoder import ly.img.android.pesdk.kotlin_extension.continueWithExceptions import ly.img.android.pesdk.ui.activity.EditorBuilder import ly.img.android.pesdk.ui.activity.ImgLyIntent @@ -22,8 +23,8 @@ import ly.img.android.pesdk.utils.MainThreadRunnable import ly.img.android.pesdk.utils.SequenceRunnable import ly.img.android.pesdk.utils.UriHelper import ly.img.android.sdk.config.* -import ly.img.android.serializer._3._0._0.PESDKFileReader -import ly.img.android.serializer._3._0._0.PESDKFileWriter +import ly.img.android.serializer._3.IMGLYFileReader +import ly.img.android.serializer._3.IMGLYFileWriter import org.apache.cordova.CallbackContext import org.apache.cordova.CordovaPlugin import org.json.JSONArray @@ -95,20 +96,20 @@ class PESDKPlugin : CordovaPlugin() { settingsList.configure { loadSettings -> filepath?.also { if (it.startsWith("data:")) { - loadSettings.setSource(UriHelper.createFromBase64String(it.substringAfter("base64,")), deleteProtectedSource = false) + loadSettings.source = UriHelper.createFromBase64String(it.substringAfter("base64,")) } else { val potentialFile = continueWithExceptions { File(it) } if (potentialFile?.exists() == true) { - loadSettings.setSource(Uri.fromFile(potentialFile), deleteProtectedSource = true) + loadSettings.source = Uri.fromFile(potentialFile) } else { - loadSettings.setSource(ConfigLoader.parseUri(it), deleteProtectedSource = true) + loadSettings.source = ConfigLoader.parseUri(it) } } } - }.configure { - it.savePolicy = SaveSettings.SavePolicy.KEEP_SOURCE_AND_CREATE_ALWAYS_OUTPUT } + val currentActivity = mainActivity ?: throw RuntimeException("Can't start the Editor because there is no current activity") + readSerialisation(settingsList, serialization, filepath == null) val self = this @@ -116,9 +117,9 @@ class PESDKPlugin : CordovaPlugin() { cordova.setActivityResultCallback(self) MainThreadRunnable { - EditorBuilder(mainActivity) + EditorBuilder(currentActivity) .setSettingsList(settingsList) - .startActivityForResult(mainActivity, EDITOR_RESULT_ID) + .startActivityForResult(currentActivity, EDITOR_RESULT_ID) }() } @@ -139,9 +140,10 @@ class PESDKPlugin : CordovaPlugin() { } } - private fun success(intent: Intent) { + private fun success(intent: Intent?) { + + intent ?: return // If resultData is null the result is not from us. val data = EditorSDKResult(intent) - data.notifyGallery(EditorSDKResult.UPDATE_RESULT and EditorSDKResult.UPDATE_SOURCE) SequenceRunnable("Export Done") { val sourcePath = data.sourceUri @@ -158,13 +160,16 @@ class PESDKPlugin : CordovaPlugin() { } when (serializationConfig.exportType) { SerializationExportType.FILE_URL -> { - val file = serializationConfig.filename?.let { Export.convertPathToFile(it) } - ?: File.createTempFile("serialization", ".json") - PESDKFileWriter(settingsList).writeJson(file) - file.absolutePath + val uri = serializationConfig.filename?.let { + Uri.parse(it) + } ?: Uri.fromFile(File.createTempFile("serialization", ".json")) + Encoder.createOutputStream(uri).use { outputStream -> + IMGLYFileWriter(settingsList).writeJson(outputStream); + } + uri.toString() } SerializationExportType.OBJECT -> { - PESDKFileWriter(settingsList).writeJsonAsString() + IMGLYFileWriter(settingsList).writeJsonAsString() } } } @@ -184,7 +189,7 @@ class PESDKPlugin : CordovaPlugin() { private fun readSerialisation(settingsList: SettingsList, serialization: String?, readImage: Boolean) { if (serialization != null) { skipIfNotExists { - PESDKFileReader(settingsList).also { + IMGLYFileReader(settingsList).also { it.readJson(serialization, readImage) } } diff --git a/src/android/build.gradle b/src/android/build.gradle index d0c8a1c..ac6d843 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -22,7 +22,7 @@ imglyConfig { } } -def MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION = "7.6.6" +def MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION = "8.1.3" task checkVersion { if (imglyConfig.convertToVersionNumber(imglyConfig.getVersion()) < imglyConfig.convertToVersionNumber(MIN_LY_IMG_ANDROID_SDK_PLUGIN_VERSION)) { @@ -62,7 +62,7 @@ repositories { } dependencies { - api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61' + api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10' compileOnly "ly.img.android.sdk:serializer:$imglyConfig.version" implementation 'com.google.code.gson:gson:2.8.5' } \ No newline at end of file diff --git a/types/configuration.ts b/types/configuration.ts index be0763a..846e3f5 100644 --- a/types/configuration.ts +++ b/types/configuration.ts @@ -908,6 +908,7 @@ export interface Configuration { filename?: string | null; /** * Whether the serialization data should include the original input image data. + * @note This is only supported on iOS. * @example // Defaults to: * false */ diff --git a/types/index.d.ts b/types/index.d.ts index d52b692..6f716b0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,61 +8,71 @@ interface PhotoEditorResult { image: string; /** An indicator whether the input image was modified at all. */ hasChanges: boolean; - /** - * All modifications applied to the input image if - * `export.serialization.enabled` of the `Configuration` was set to `true`. - */ + /** All modifications applied to the input image if `export.serialization.enabled` of the `Configuration` was set to `true`. */ serialization?: string | object; } declare class PESDK { /** - * Present a photo editor. - * @note EXIF meta data is only preserved in the edited image if and only if - * the source image is loaded from a local `file://` resource. + * Modally present a photo editor. * - * @param {function} success - The callback returns a {PhotoEditorResult} or - * `null` if the editor is dismissed without exporting the edited image. - * @param {function} failure - The callback function that will be called when - * an error occurs. + * @param {function} success - The callback returns a `PhotoEditorResult` or `null` if the editor + * is dismissed without exporting the edited image. + * @param {function} failure - The callback function that will be called when an error occurs. * @param {string} image The source of the image to be edited. - * @param {Configuration} configuration The configuration used to initialize the - * editor. - * @param {object} serialization The serialization used to initialize the - * editor. This - * restores a previous state of the editor by re-applying all modifications to - * the loaded image. + * Can be a local or remote URI. Local URIs are recommended as the handling of remote URIs is not optimized. + * Remote resources should be downloaded in advance and then passed to the editor as local resources. + * Static local resources which reside, e.g., in the `www` folder of your app, should be resolved by + * `PESDK.resolveStaticResource("www/path/to/your/image")` before they can be passed to the editor. + * If this parameter is `null`, the `serialization` parameter must not be `null` and it must contain + * an embedded source image. + * @param {object} configuration The configuration used to initialize the editor. + * @param {object} serialization The serialization used to initialize the editor. This + * restores a previous state of the editor by re-applying all modifications to the loaded + * image. */ static openEditor( success: (args: PhotoEditorResult) => void, failure: (error: any) => void, - image: { uri: string }, + image?: string, configuration?: Configuration, serialization?: object): void /** - * Unlock PhotoEditor SDK with a license. - * - * The license should have an extension like this: - * for iOS: "xxx.ios", example: pesdk_license.ios - * for Android: "xxx.android", example: pesdk_license.android - * then pass just the name without the extension to the `unlockWithLicense` function. - * @example `PESDK.unlockWithLicense('www/assets/pesdk_license')` + * Unlock PhotoEditor SDK with a license. + * + * @param {string} license The path of the license used to unlock the SDK. + * The license files should be located within the `www` folder and must have + * the extension `.ios` for iOS and `.android` for Android. In this way the + * licenses get automatically resolved for each platform so that no file- + * extension is needed in the path. + * + * @example + * // Both licenses `pesdk_license.ios` and `pesdk_license.android` + * // located in `www/assets/` will be automatically resolved by: + * PESDK.unlockWithLicense('www/assets/pesdk_license') + */ + static unlockWithLicense(license: string): void + + /** + * Resolves the path of a static local resource. * - * @param {string} license The path of license used to unlock the SDK. + * @param {string} path The path of the static local resource. + * @returns {string} The platform-specific path for a static local resource that can be accessed by the native PhotoEditor SDK plugin. */ - static unlockWithLicense(license: string): void + static resolveStaticResource( + path: string): string /** - * Get the correct path to each platform - * It can be used to load local resources + * @deprecated Use `PESDK.resolveStaticResource` instead. + * Resolves the path of a static local resource. * - * @param {string} path The path of the local resource. - * @returns {string} assets path to deal with it inside PhotoEditor SDK + * @param {string} path The path of the static local resource. + * @returns {string} The platform-specific path for a static local resource that can be accessed by the native PhotoEditor SDK plugin. */ static loadResource( - image: string): { uri: string } + path: string): string } export { PESDK, PhotoEditorResult } -export * from './configuration'; \ No newline at end of file +export * from './configuration'; diff --git a/www/photoeditorsdk.js b/www/photoeditorsdk.js index f5aad37..dbdfaa3 100644 --- a/www/photoeditorsdk.js +++ b/www/photoeditorsdk.js @@ -1,13 +1,17 @@ var PESDK = { /** - * Present a photo editor. - * @note EXIF meta data is only preserved in the edited image if and only if the source - * image is loaded from a local `file://` resource. + * Modally present a photo editor. * * @param {function} success - The callback returns a `PhotoEditorResult` or `null` if the editor * is dismissed without exporting the edited image. * @param {function} failure - The callback function that will be called when an error occurs. * @param {string} image The source of the image to be edited. + * Can be a local or remote URI. Local URIs are recommended as the handling of remote URIs is not optimized. + * Remote resources should be downloaded in advance and then passed to the editor as local resources. + * Static local resources which reside, e.g., in the `www` folder of your app, should be resolved by + * `PESDK.resolveStaticResource("www/path/to/your/image")` before they can be passed to the editor. + * If this parameter is `null`, the `serialization` parameter must not be `null` and it must contain + * an embedded source image. * @param {object} configuration The configuration used to initialize the editor. * @param {object} serialization The serialization used to initialize the editor. This * restores a previous state of the editor by re-applying all modifications to the loaded @@ -28,13 +32,16 @@ var PESDK = { /** * Unlock PhotoEditor SDK with a license. * - * The license should have an extension like this: - * for iOS: "xxx.ios", example: pesdk_license.ios - * for Android: "xxx.android", example: pesdk_license.android - * then pass just the name without the extension to the `unlockWithLicense` function. - * @example `PESDK.unlockWithLicense('www/assets/pesdk_license')` - * - * @param {string} license The path of license used to unlock the SDK. + * @param {string} license The path of the license used to unlock the SDK. + * The license files should be located within the `www` folder and must have + * the extension `.ios` for iOS and `.android` for Android. In this way the + * licenses get automatically resolved for each platform so that no file- + * extension is needed in the path. + * + * @example + * // Both licenses `pesdk_license.ios` and `pesdk_license.android` + * // located in `www/assets/` will be automatically resolved by: + * PESDK.unlockWithLicense('www/assets/pesdk_license') */ unlockWithLicense: function (license) { var platform = window.cordova.platformId; @@ -46,13 +53,12 @@ var PESDK = { cordova.exec(null, null, "PESDK", "unlockWithLicense", [license]); }, /** - * Get the correct path to each platform - * It can be used to load local resources + * Resolves the path of a static local resource. * - * @param {string} path The path of the local resource. - * @returns {string} assets path to deal with it inside PhotoEditor SDK + * @param {string} path The path of the static local resource. + * @returns {string} The platform-specific path for a static local resource that can be accessed by the native PhotoEditor SDK plugin. */ - loadResource: function (path) { + resolveStaticResource: function (path) { var platform = window.cordova.platformId; if (platform == "android") return "asset:///" + path; else if (platform == "ios") { @@ -63,5 +69,15 @@ var PESDK = { getDevice: function () { return window.cordova.platformId; }, + /** + * @deprecated Use `PESDK.resolveStaticResource` instead. + * Resolves the path of a static local resource. + * + * @param {string} path The path of the static local resource. + * @returns {string} The platform-specific path for a static local resource that can be accessed by the native PhotoEditor SDK plugin. + */ + loadResource: function (path) { + return this.resolveStaticResource(path); + }, }; module.exports = PESDK;