mirror of https://github.com/laurent22/joplin.git
Add simple sharing facilities for Android
- react code should be cross platform but support needs to be added for ios - only shares plain text notes for nowpull/689/head
parent
f63668350b
commit
8840631266
|
@ -137,7 +137,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':react-native-file-viewer')
|
compile project(':react-native-file-viewer')
|
||||||
compile project(':react-native-securerandom')
|
compile project(':react-native-securerandom')
|
||||||
compile project(':react-native-push-notification')
|
compile project(':react-native-push-notification')
|
||||||
compile project(':react-native-fs')
|
compile project(':react-native-fs')
|
||||||
|
@ -151,6 +151,8 @@ dependencies {
|
||||||
compile project(':react-native-fetch-blob')
|
compile project(':react-native-fetch-blob')
|
||||||
compile project(':react-native-document-picker')
|
compile project(':react-native-document-picker')
|
||||||
compile project(':react-native-image-resizer')
|
compile project(':react-native-image-resizer')
|
||||||
|
compile project(':react-native-share-extension')
|
||||||
|
compile "com.facebook.react:react-native:+"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run this once to be able to run the application with BUCK
|
// Run this once to be able to run the application with BUCK
|
||||||
|
|
|
@ -63,5 +63,19 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
||||||
|
<activity
|
||||||
|
android:noHistory="true"
|
||||||
|
android:name=".share.ShareActivity"
|
||||||
|
android:configChanges="orientation"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
android:theme="@style/AppTheme" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.vinzscam.reactnativefileviewer.RNFileViewerPackage;
|
||||||
import net.rhogan.rnsecurerandom.RNSecureRandomPackage;
|
import net.rhogan.rnsecurerandom.RNSecureRandomPackage;
|
||||||
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
|
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
|
||||||
import com.imagepicker.ImagePickerPackage;
|
import com.imagepicker.ImagePickerPackage;
|
||||||
|
import com.facebook.react.ReactInstanceManager;
|
||||||
import com.facebook.react.ReactNativeHost;
|
import com.facebook.react.ReactNativeHost;
|
||||||
import com.facebook.react.ReactPackage;
|
import com.facebook.react.ReactPackage;
|
||||||
import com.facebook.react.shell.MainReactPackage;
|
import com.facebook.react.shell.MainReactPackage;
|
||||||
|
@ -18,6 +19,8 @@ import com.rnfs.RNFSPackage;
|
||||||
import fr.bamlab.rnimageresizer.ImageResizerPackage;
|
import fr.bamlab.rnimageresizer.ImageResizerPackage;
|
||||||
import org.pgsqlite.SQLitePluginPackage;
|
import org.pgsqlite.SQLitePluginPackage;
|
||||||
|
|
||||||
|
import com.alinz.parkerdan.shareextension.SharePackage;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -42,7 +45,8 @@ public class MainApplication extends Application implements ReactApplication {
|
||||||
new RNFetchBlobPackage(),
|
new RNFetchBlobPackage(),
|
||||||
new RNFSPackage(),
|
new RNFSPackage(),
|
||||||
new SQLitePluginPackage(),
|
new SQLitePluginPackage(),
|
||||||
new VectorIconsPackage()
|
new VectorIconsPackage(),
|
||||||
|
new SharePackage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package net.cozic.joplin.share;
|
||||||
|
|
||||||
|
|
||||||
|
// import ReactActivity
|
||||||
|
import com.facebook.react.ReactActivity;
|
||||||
|
|
||||||
|
|
||||||
|
public class ShareActivity extends ReactActivity {
|
||||||
|
@Override
|
||||||
|
protected String getMainComponentName() {
|
||||||
|
// this is the name AppRegistry will use to launch the Share View
|
||||||
|
return "Joplin";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package net.cozic.joplin.share;
|
||||||
|
// import build config
|
||||||
|
import net.cozic.joplin.BuildConfig;
|
||||||
|
|
||||||
|
import com.alinz.parkerdan.shareextension.SharePackage;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import com.facebook.react.shell.MainReactPackage;
|
||||||
|
import com.facebook.react.ReactNativeHost;
|
||||||
|
import com.facebook.react.ReactApplication;
|
||||||
|
import com.facebook.react.ReactPackage;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class ShareApplication extends Application implements ReactApplication {
|
||||||
|
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
||||||
|
@Override
|
||||||
|
public boolean getUseDeveloperSupport() {
|
||||||
|
return BuildConfig.DEBUG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<ReactPackage> getPackages() {
|
||||||
|
return Arrays.<ReactPackage>asList(
|
||||||
|
new MainReactPackage(),
|
||||||
|
new SharePackage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReactNativeHost getReactNativeHost() {
|
||||||
|
return mReactNativeHost;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,4 +25,7 @@ include ':react-native-fetch-blob'
|
||||||
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
|
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
|
||||||
|
|
||||||
include ':react-native-document-picker'
|
include ':react-native-document-picker'
|
||||||
project(':react-native-document-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-picker/android')
|
project(':react-native-document-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-picker/android')
|
||||||
|
include ':app', ':react-native-share-extension'
|
||||||
|
|
||||||
|
project(':react-native-share-extension').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share-extension/android')
|
||||||
|
|
|
@ -34,6 +34,7 @@ const shared = require('lib/components/shared/note-screen-shared.js');
|
||||||
const ImagePicker = require('react-native-image-picker');
|
const ImagePicker = require('react-native-image-picker');
|
||||||
const AlarmService = require('lib/services/AlarmService.js');
|
const AlarmService = require('lib/services/AlarmService.js');
|
||||||
const { SelectDateTimeDialog } = require('lib/components/select-date-time-dialog.js');
|
const { SelectDateTimeDialog } = require('lib/components/select-date-time-dialog.js');
|
||||||
|
const ShareExtension = require('react-native-share-extension').default;
|
||||||
|
|
||||||
import FileViewer from 'react-native-file-viewer';
|
import FileViewer from 'react-native-file-viewer';
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||||
alarmDialogShown: false,
|
alarmDialogShown: false,
|
||||||
heightBumpView:0,
|
heightBumpView:0,
|
||||||
noteTagDialogShown: false,
|
noteTagDialogShown: false,
|
||||||
|
fromShare: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// iOS doesn't support multiline text fields properly so disable it
|
// iOS doesn't support multiline text fields properly so disable it
|
||||||
|
@ -215,6 +217,10 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
BackButtonService.removeHandler(this.backHandler);
|
BackButtonService.removeHandler(this.backHandler);
|
||||||
NavService.removeHandler(this.navHandler);
|
NavService.removeHandler(this.navHandler);
|
||||||
|
|
||||||
|
if (this.state.fromShare) {
|
||||||
|
ShareExtension.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
title_changeText(text) {
|
title_changeText(text) {
|
||||||
|
@ -675,9 +681,10 @@ const NoteScreen = connect(
|
||||||
itemType: state.selectedItemType,
|
itemType: state.selectedItemType,
|
||||||
folders: state.folders,
|
folders: state.folders,
|
||||||
theme: state.settings.theme,
|
theme: state.settings.theme,
|
||||||
|
sharedData: state.sharedData,
|
||||||
showAdvancedOptions: state.settings.showAdvancedOptions,
|
showAdvancedOptions: state.settings.showAdvancedOptions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)(NoteScreenComponent)
|
)(NoteScreenComponent)
|
||||||
|
|
||||||
module.exports = { NoteScreen };
|
module.exports = { NoteScreen };
|
||||||
|
|
|
@ -174,8 +174,13 @@ shared.initState = async function(comp) {
|
||||||
mode: mode,
|
mode: mode,
|
||||||
folder: folder,
|
folder: folder,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
fromShare: comp.props.sharedData ? true : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (comp.props.sharedData) {
|
||||||
|
this.noteComponent_change(comp, 'body', comp.props.sharedData.value);
|
||||||
|
}
|
||||||
|
|
||||||
comp.lastLoadedNoteId_ = note ? note.id : null;
|
comp.lastLoadedNoteId_ = note ? note.id : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,4 +195,4 @@ shared.toggleIsTodo_onPress = function(comp) {
|
||||||
comp.setState(newState);
|
comp.setState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = shared;
|
module.exports = shared;
|
||||||
|
|
|
@ -23,6 +23,7 @@ const defaultState = {
|
||||||
syncReport: {},
|
syncReport: {},
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
settings: {},
|
settings: {},
|
||||||
|
sharedData: null,
|
||||||
appState: 'starting',
|
appState: 'starting',
|
||||||
hasDisabledSyncItems: false,
|
hasDisabledSyncItems: false,
|
||||||
newNote: null,
|
newNote: null,
|
||||||
|
@ -570,4 +571,4 @@ const reducer = (state = defaultState, action) => {
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { reducer, defaultState, stateUtils };
|
module.exports = { reducer, defaultState, stateUtils };
|
||||||
|
|
|
@ -6593,6 +6593,11 @@
|
||||||
"base64-js": "*"
|
"base64-js": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-native-share-extension": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-native-share-extension/-/react-native-share-extension-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-C+WaUFhM4iMtH38N7/44lX4uW/B+XSbeJnSBZMMgKsZQIJKzJSYQklKVZdxf2/V5YOjjPaXohFwabTYclpJhtA=="
|
||||||
|
},
|
||||||
"react-native-side-menu": {
|
"react-native-side-menu": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/react-native-side-menu/-/react-native-side-menu-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/react-native-side-menu/-/react-native-side-menu-1.1.3.tgz",
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
"react-native-popup-menu": "^0.10.0",
|
"react-native-popup-menu": "^0.10.0",
|
||||||
"react-native-push-notification": "^3.0.1",
|
"react-native-push-notification": "^3.0.1",
|
||||||
"react-native-securerandom": "^0.1.1",
|
"react-native-securerandom": "^0.1.1",
|
||||||
|
"react-native-share-extension": "^1.2.1",
|
||||||
"react-native-side-menu": "^1.1.3",
|
"react-native-side-menu": "^1.1.3",
|
||||||
"react-native-sqlite-storage": "3.3.*",
|
"react-native-sqlite-storage": "3.3.*",
|
||||||
"react-native-vector-icons": "^4.4.2",
|
"react-native-vector-icons": "^4.4.2",
|
||||||
|
|
|
@ -50,6 +50,7 @@ const { PoorManIntervals } = require('lib/poor-man-intervals.js');
|
||||||
const { reducer, defaultState } = require('lib/reducer.js');
|
const { reducer, defaultState } = require('lib/reducer.js');
|
||||||
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
|
||||||
const DropdownAlert = require('react-native-dropdownalert').default;
|
const DropdownAlert = require('react-native-dropdownalert').default;
|
||||||
|
const ShareExtension = require('react-native-share-extension').default;
|
||||||
|
|
||||||
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
|
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
|
||||||
const SyncTargetOneDrive = require('lib/SyncTargetOneDrive.js');
|
const SyncTargetOneDrive = require('lib/SyncTargetOneDrive.js');
|
||||||
|
@ -235,6 +236,12 @@ const appReducer = (state = appDefaultState, action) => {
|
||||||
newState.selectedItemType = action.itemType;
|
newState.selectedItemType = action.itemType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('sharedData' in action) {
|
||||||
|
newState.sharedData = action.sharedData;
|
||||||
|
} else {
|
||||||
|
newState.sharedData = null;
|
||||||
|
}
|
||||||
|
|
||||||
newState.route = action;
|
newState.route = action;
|
||||||
newState.historyCanGoBack = !!navHistory.length;
|
newState.historyCanGoBack = !!navHistory.length;
|
||||||
break;
|
break;
|
||||||
|
@ -517,6 +524,27 @@ class AppComponent extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { type, value } = await ShareExtension.data();
|
||||||
|
|
||||||
|
if (type != "") {
|
||||||
|
console.log(value);
|
||||||
|
console.log(type)
|
||||||
|
|
||||||
|
this.props.dispatch({
|
||||||
|
type: 'NAV_GO',
|
||||||
|
routeName: 'Note',
|
||||||
|
noteId: null,
|
||||||
|
sharedData: {type: type, value: value},
|
||||||
|
folderId: this.props.parentFolderId,
|
||||||
|
itemType: 'note',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.log('Error in ShareExtension.data', e);
|
||||||
|
}
|
||||||
|
|
||||||
BackButtonService.initialize(this.backButtonHandler_);
|
BackButtonService.initialize(this.backButtonHandler_);
|
||||||
|
|
||||||
AlarmService.setInAppNotificationHandler(async (alarmId) => {
|
AlarmService.setInAppNotificationHandler(async (alarmId) => {
|
||||||
|
|
Loading…
Reference in New Issue