1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-24 20:19:10 +02:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Laurent Cozic
c6722a7a49 Merge branch 'android-sharing' of https://github.com/CalebJohn/joplin into CalebJohn-android-sharing 2018-09-04 10:09:13 +01:00
Caleb John
3caf398021 refresh notes list on AppState Changes
- remove mistaken console.log calls in root.js
2018-07-20 15:59:55 +02:00
Caleb John
8840631266 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 now
2018-07-20 11:04:25 +02:00
13 changed files with 141 additions and 8 deletions

View File

@@ -137,7 +137,7 @@ android {
}
dependencies {
compile project(':react-native-file-viewer')
compile project(':react-native-file-viewer')
compile project(':react-native-securerandom')
compile project(':react-native-push-notification')
compile project(':react-native-fs')
@@ -151,6 +151,8 @@ dependencies {
compile project(':react-native-fetch-blob')
compile project(':react-native-document-picker')
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

View File

@@ -63,5 +63,19 @@
</intent-filter>
</activity>
<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>
</manifest>

View File

@@ -7,6 +7,7 @@ import com.vinzscam.reactnativefileviewer.RNFileViewerPackage;
import net.rhogan.rnsecurerandom.RNSecureRandomPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.imagepicker.ImagePickerPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
@@ -18,6 +19,8 @@ import com.rnfs.RNFSPackage;
import fr.bamlab.rnimageresizer.ImageResizerPackage;
import org.pgsqlite.SQLitePluginPackage;
import com.alinz.parkerdan.shareextension.SharePackage;
import java.util.Arrays;
import java.util.List;
@@ -42,7 +45,8 @@ public class MainApplication extends Application implements ReactApplication {
new RNFetchBlobPackage(),
new RNFSPackage(),
new SQLitePluginPackage(),
new VectorIconsPackage()
new VectorIconsPackage(),
new SharePackage()
);
}
};

View File

@@ -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";
}
}

View File

@@ -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;
}
}

View File

@@ -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')
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')

View File

@@ -34,6 +34,7 @@ const shared = require('lib/components/shared/note-screen-shared.js');
const ImagePicker = require('react-native-image-picker');
const AlarmService = require('lib/services/AlarmService.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';
@@ -57,6 +58,7 @@ class NoteScreenComponent extends BaseScreenComponent {
alarmDialogShown: false,
heightBumpView:0,
noteTagDialogShown: false,
fromShare: false,
};
// iOS doesn't support multiline text fields properly so disable it
@@ -215,6 +217,10 @@ class NoteScreenComponent extends BaseScreenComponent {
componentWillUnmount() {
BackButtonService.removeHandler(this.backHandler);
NavService.removeHandler(this.navHandler);
if (this.state.fromShare) {
ShareExtension.close();
}
}
title_changeText(text) {
@@ -675,9 +681,10 @@ const NoteScreen = connect(
itemType: state.selectedItemType,
folders: state.folders,
theme: state.settings.theme,
sharedData: state.sharedData,
showAdvancedOptions: state.settings.showAdvancedOptions,
};
}
)(NoteScreenComponent)
module.exports = { NoteScreen };
module.exports = { NoteScreen };

View File

@@ -1,5 +1,5 @@
const React = require('react'); const Component = React.Component;
const { View, Button, Text } = require('react-native');
const { AppState, View, Button, Text } = require('react-native');
const { stateUtils } = require('lib/reducer.js');
const { connect } = require('react-redux');
const { reg } = require('lib/registry.js');
@@ -26,6 +26,13 @@ class NotesScreenComponent extends BaseScreenComponent {
constructor() {
super();
this.onAppStateChange_ = async () => {
// Force an update to the notes list when app state changes
let newProps = Object.assign({}, this.props);
newProps.notesSource = '';
await this.refreshNotes(newProps);
}
this.sortButton_press = async () => {
const buttons = [];
const sortNoteOptions = Setting.enumOptions('notes.sortOrder.field');
@@ -67,6 +74,11 @@ class NotesScreenComponent extends BaseScreenComponent {
async componentDidMount() {
await this.refreshNotes();
AppState.addEventListener('change', this.onAppStateChange_);
}
async componentWillUnmount() {
AppState.removeEventListener('change', this.onAppStateChange_);
}
async UNSAFE_componentWillReceiveProps(newProps) {
@@ -233,4 +245,4 @@ const NotesScreen = connect(
}
)(NotesScreenComponent)
module.exports = { NotesScreen };
module.exports = { NotesScreen };

View File

@@ -174,8 +174,13 @@ shared.initState = async function(comp) {
mode: mode,
folder: folder,
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;
}
@@ -190,4 +195,4 @@ shared.toggleIsTodo_onPress = function(comp) {
comp.setState(newState);
}
module.exports = shared;
module.exports = shared;

View File

@@ -23,6 +23,7 @@ const defaultState = {
syncReport: {},
searchQuery: '',
settings: {},
sharedData: null,
appState: 'starting',
hasDisabledSyncItems: false,
newNote: null,
@@ -570,4 +571,4 @@ const reducer = (state = defaultState, action) => {
return newState;
}
module.exports = { reducer, defaultState, stateUtils };
module.exports = { reducer, defaultState, stateUtils };

View File

@@ -6593,6 +6593,11 @@
"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": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/react-native-side-menu/-/react-native-side-menu-1.1.3.tgz",

View File

@@ -40,6 +40,7 @@
"react-native-popup-menu": "^0.10.0",
"react-native-push-notification": "^3.0.1",
"react-native-securerandom": "^0.1.1",
"react-native-share-extension": "^1.2.1",
"react-native-side-menu": "^1.1.3",
"react-native-sqlite-storage": "3.3.*",
"react-native-vector-icons": "^4.4.2",

View File

@@ -50,6 +50,7 @@ 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 SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
const SyncTargetOneDrive = require('lib/SyncTargetOneDrive.js');
@@ -235,6 +236,12 @@ const appReducer = (state = appDefaultState, action) => {
newState.selectedItemType = action.itemType;
}
if ('sharedData' in action) {
newState.sharedData = action.sharedData;
} else {
newState.sharedData = null;
}
newState.route = action;
newState.historyCanGoBack = !!navHistory.length;
break;
@@ -517,6 +524,25 @@ class AppComponent extends React.Component {
});
}
try {
const { type, value } = await ShareExtension.data();
if (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_);
AlarmService.setInAppNotificationHandler(async (alarmId) => {