From bea5ce1f710889714af160a4ee5c0d51819d1e62 Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Mon, 25 May 2020 14:08:25 +0530 Subject: [PATCH] android: Receive and handle shares from other apps. Enables handling and receiving shares from other apps, for any type of content (text, images, and other files). Creates a native RN module `SharingModule` to handle the Android part of this feature. 'ReceiveShareActivity.kt' parses the received shared data and handles activating the JS part of the codebase - either by sending an event to an already-running app, or launching `MainActivity` with some initial shared data via the native module. Registers a new root component, `SharingRoot`. It is a dummy component that does nothing, and `ReceiveShareActivity.kt`. It exists because 'Sharing' is linked with launching an activity in the Android ecosystem. But we don't always want to launch `MainActivity` when receiving a share because it may cause two instances of it to be opened simultaneously. We can't check whether the app is running before an activity launches. So, we launch this dummy component, then process the events, identify whether the app is running or not, and handle that as mentioned in the paragraph above, and then quickly kill this dummy Activity. All of this happens fast enough that the component does not even get time to render, so it's seamless. Closes #M117. --- android/app/src/main/AndroidManifest.xml | 23 + .../java/com/zulipmobile/MainApplication.java | 2 + .../sharing/ReceiveShareActivity.kt | 110 ++++ .../com/zulipmobile/sharing/SharingModule.kt | 24 + .../com/zulipmobile/sharing/SharingPackage.kt | 26 + index.js | 2 + src/boot/AppEventHandlers.js | 6 +- src/nav/AppNavigator.js | 2 + src/nav/navActions.js | 4 + src/nav/navReducer.js | 5 + src/sharing/ChooseRecipientsScreen.js | 44 ++ src/sharing/SharingRoot.js | 18 + src/sharing/SharingScreen.js | 472 ++++++++++++++++++ src/sharing/index.js | 57 +++ src/types.js | 17 + static/translations/messages_en.json | 10 +- 16 files changed, 820 insertions(+), 2 deletions(-) create mode 100644 android/app/src/main/java/com/zulipmobile/sharing/ReceiveShareActivity.kt create mode 100644 android/app/src/main/java/com/zulipmobile/sharing/SharingModule.kt create mode 100644 android/app/src/main/java/com/zulipmobile/sharing/SharingPackage.kt create mode 100644 src/sharing/ChooseRecipientsScreen.js create mode 100644 src/sharing/SharingRoot.js create mode 100644 src/sharing/SharingScreen.js create mode 100644 src/sharing/index.js diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 97e7b184ca5..a7ea6d25039 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -53,6 +53,29 @@ + + + + + + + + + + + + + + + + + +