From fcec2d16b31ccfa4247dc45a323be8ff2c8d8492 Mon Sep 17 00:00:00 2001
From: Mostafa Mansour <mostafa@outlook.kr>
Date: Fri, 13 Sep 2019 16:42:08 +0400
Subject: [PATCH] =?UTF-8?q?feat(preview-any-file):=20add=20new=20plugin=20?=
 =?UTF-8?q?to=20preview=20the=20=E2=80=A6=20(#3156)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* feat(cordova-plugin-preview-any-file): add new plugin to preview the files in both ios and android

* fix lint error

* add missing descriptions

* add the reop link
---
 .../plugins/preview-any-file/index.ts         | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 src/@ionic-native/plugins/preview-any-file/index.ts

diff --git a/src/@ionic-native/plugins/preview-any-file/index.ts b/src/@ionic-native/plugins/preview-any-file/index.ts
new file mode 100644
index 000000000..c6e4f642a
--- /dev/null
+++ b/src/@ionic-native/plugins/preview-any-file/index.ts
@@ -0,0 +1,46 @@
+import { Injectable } from '@angular/core';
+import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
+/**
+ * @name PreviewAnyFile
+ * @description
+ * Whatever the file is PDF document, Word document, Excel, office document,zip archive file, image, text, html or anything else, you can perform a preview by this cordova Plugin to preview any file in native mode by providing the local or external URL.
+ *
+ *  Requires Cordova plugin: `cordova-plugin-preview-any-file`. For more info, please see the [previewAnyFile plugin docs](https://github.com/mostafa-mansour1/previewAnyFile).
+ *
+ * @usage
+ * ```typescript
+ * import { PreviewAnyFile } from '@ionic-native/preview-any-file';
+ *
+ *
+ * constructor(private previewAnyFile: PreviewAnyFile) { }
+ *
+ * ...
+ *
+ *
+ * this.previewAnyFile.preview('file://filepath.ext')
+ *   .then((res: any) => console.log(res))
+ *   .catch((error: any) => console.error(error));
+ *
+ * ```
+ */
+@Plugin({
+  pluginName: 'PreviewAnyFile',
+  plugin: 'cordova-plugin-preview-any-file', // npm package name, example: cordova-plugin-camera
+  pluginRef: 'PreviewAnyFile', // the variable reference to call the plugin, example: navigator.geolocation
+  repo: 'https://github.com/mostafa-mansour1/previewAnyFile', // the github repository URL for the plugin
+  install: '', // OPTIONAL install command, in case the plugin requires variables
+  installVariables: [], // OPTIONAL the plugin requires variables
+  platforms: ['Android', 'iOS'] // Array of platforms supported, example: ['Android', 'iOS']
+})
+@Injectable()
+export class PreviewAnyFile extends IonicNativePlugin {
+  /**
+   * this function return SUCCESS in success callback if the file successfully opened, if the content is base64 you have to write it into file by cordova-plugin-file
+   * @param url {string} full absolute URL for the file, if the path is content:// you need to resolve the native url, if the path is https:// it may not work in android
+   * @return {Promise<any>} Returns a promise that resolves if the file opened reject if not;
+   */
+  @Cordova()
+  preview(url: string): Promise<string> {
+    return;
+  }
+}