1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Android: Resolves #2896: Enable sharing to Joplin on Android (#2870)

This commit is contained in:
Roman Musin
2020-06-04 18:40:44 +01:00
committed by GitHub
parent 949c92f6d6
commit 33ad0dce15
13 changed files with 324 additions and 99 deletions

View File

@ -2,7 +2,7 @@ import setUpQuickActions from './setUpQuickActions';
import PluginAssetsLoader from './PluginAssetsLoader';
const React = require('react');
const { AppState, Keyboard, NativeModules, BackHandler, Platform, Animated, View, StatusBar } = require('react-native');
const { AppState, Keyboard, NativeModules, BackHandler, Animated, View, StatusBar } = require('react-native');
const SafeAreaView = require('lib/components/SafeAreaView');
const { connect, Provider } = require('react-redux');
const { BackButtonService } = require('lib/services/back-button.js');
@ -57,7 +57,8 @@ const { PoorManIntervals } = require('lib/poor-man-intervals.js');
const { reducer, defaultState } = require('lib/reducer.js');
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
const DropdownAlert = require('react-native-dropdownalert').default;
// const ShareExtension = require('react-native-share-extension').default;
const ShareExtension = require('lib/ShareExtension.js').default;
const handleShared = require('lib/shareHandler').default;
const ResourceFetcher = require('lib/services/ResourceFetcher');
const SearchEngine = require('lib/services/SearchEngine');
const WelcomeUtils = require('lib/WelcomeUtils');
@ -614,43 +615,6 @@ class AppComponent extends React.Component {
});
}
if (Platform.OS !== 'ios') {
// try {
// const { type, value } = await ShareExtension.data();
// // reg.logger().info('Got share data:', type, value);
// if (type != '' && this.props.selectedFolderId) {
// const newNote = await Note.save({
// title: Note.defaultTitleFromBody(value),
// body: value,
// parent_id: this.props.selectedFolderId,
// });
// // This is a bit hacky, but the surest way to go to
// // the needed note. We go back one screen in case there's
// // already a note open - if we don't do this, the dispatch
// // below will do nothing (because routeName wouldn't change)
// // Then we wait a bit for the state to be set correctly, and
// // finally we go to the new note.
// this.props.dispatch({
// type: 'NAV_BACK',
// });
// setTimeout(() => {
// this.props.dispatch({
// type: 'NAV_GO',
// routeName: 'Note',
// noteId: newNote.id,
// });
// }, 5);
// }
// } catch (e) {
// reg.logger().error('Error in ShareExtension.data', e);
// }
}
BackButtonService.initialize(this.backButtonHandler_);
AlarmService.setInAppNotificationHandler(async (alarmId) => {
@ -660,6 +624,16 @@ class AppComponent extends React.Component {
});
AppState.addEventListener('change', this.onAppStateChange_);
const sharedData = await ShareExtension.data();
if (sharedData) {
reg.logger().info('Received shared data');
if (this.props.selectedFolderId) {
handleShared(sharedData, this.props.selectedFolderId, this.props.dispatch);
} else {
reg.logger.info('Cannot handle share - default folder id is not set');
}
}
}
componentWillUnmount() {