Skip to content

Commit

Permalink
Mobile: resolves laurent22#8639: implement callback url on android
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusteng committed Jan 30, 2024
1 parent 07ee20a commit 218913f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/app-mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
<data android:mimeType="*/*" />
</intent-filter>
<!-- /SHARE EXTENSION -->

<!-- EXTERNAL LINK -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="joplin" />
</intent-filter>
<!-- /EXTERNAL LINK -->
</activity>

</application>
Expand Down
12 changes: 12 additions & 0 deletions packages/app-mobile/components/screens/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { join } from 'path';
import { Dispatch } from 'redux';
import { RefObject } from 'react';
import { SelectionRange } from '../NoteEditor/types';
import { getNoteCallbackUrl } from '@joplin/lib/callbackUrlUtils';
const urlUtils = require('@joplin/lib/urlUtils');

const emptyArray: any[] = [];
Expand Down Expand Up @@ -1098,6 +1099,11 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
Clipboard.setString(Note.markdownTag(note));
}

private copyExternalLink_onPress() {
const note = this.state.note;
Clipboard.setString(getNoteCallbackUrl(note.id));
}

public sideMenuOptions() {
const note = this.state.note;
if (!note) return [];
Expand Down Expand Up @@ -1305,6 +1311,12 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
this.copyMarkdownLink_onPress();
},
});
output.push({
title: _('Copy external link'),
onPress: () => {
this.copyExternalLink_onPress();
},
});
}
output.push({
title: _('Properties'),
Expand Down
29 changes: 27 additions & 2 deletions packages/app-mobile/components/screens/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Tag from '@joplin/lib/models/Tag';
import Note from '@joplin/lib/models/Note';
import Setting from '@joplin/lib/models/Setting';
const { themeStyle } = require('../global-style.js');
import { ScreenHeader } from '../ScreenHeader';
import { ScreenHeader, MenuOptionType } from '../ScreenHeader';
import { _ } from '@joplin/lib/locale';
import ActionButton from '../ActionButton';
const { dialogs } = require('../../utils/dialogs.js');
Expand All @@ -18,6 +18,8 @@ const { BackButtonService } = require('../../services/back-button.js');
import { AppState } from '../../utils/types';
import { NoteEntity } from '@joplin/lib/services/database/types';
const { ALL_NOTES_FILTER_ID } = require('@joplin/lib/reserved-ids.js');
const Clipboard = require('@react-native-community/clipboard').default;
import { getFolderCallbackUrl, getTagCallbackUrl } from '@joplin/lib/callbackUrlUtils';

class NotesScreenComponent extends BaseScreenComponent<any> {

Expand Down Expand Up @@ -197,6 +199,29 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
return this.folderPickerOptions_;
}

public menuOptions() {
const output: MenuOptionType[] = [];

if (this.props.notesParentType === 'Tag') {
output.push({
title: _('Copy external link'),
onPress: () => {
Clipboard.setString(getTagCallbackUrl(this.props.selectedTagId));
},
});
}
if (this.props.notesParentType === 'Folder') {
output.push({
title: _('Copy external link'),
onPress: () => {
Clipboard.setString(getFolderCallbackUrl(this.props.selectedFolderId));
},
});
}

return output;
}

public render() {
const parent = this.parentItem();
const theme = themeStyle(this.props.themeId);
Expand Down Expand Up @@ -285,7 +310,7 @@ class NotesScreenComponent extends BaseScreenComponent<any> {
accessibilityElementsHidden={accessibilityHidden}
importantForAccessibility={accessibilityHidden ? 'no-hide-descendants' : undefined}
>
<ScreenHeader title={iconString + title} showBackButton={false} parentComponent={thisComp} sortButton_press={this.sortButton_press} folderPickerOptions={this.folderPickerOptions()} showSearchButton={true} showSideMenuButton={true} />
<ScreenHeader title={iconString + title} showBackButton={false} parentComponent={thisComp} sortButton_press={this.sortButton_press} folderPickerOptions={this.folderPickerOptions()} showSearchButton={true} showSideMenuButton={true} menuOptions={this.menuOptions()} />
<NoteList />
{actionButtonComp}
<DialogBox
Expand Down
33 changes: 33 additions & 0 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const SyncTargetDropbox = require('@joplin/lib/SyncTargetDropbox.js');
const SyncTargetAmazonS3 = require('@joplin/lib/SyncTargetAmazonS3.js');
import BiometricPopup from './components/biometrics/BiometricPopup';
import initLib from '@joplin/lib/initLib';
import { isCallbackUrl, parseCallbackUrl, CallbackUrlCommand } from '@joplin/lib/callbackUrlUtils';

SyncTargetRegistry.addClass(SyncTargetNone);
SyncTargetRegistry.addClass(SyncTargetOneDrive);
Expand Down Expand Up @@ -794,6 +795,38 @@ class AppComponent extends React.Component {
logger.info('Sharing: handleOpenURL_: Processing share data');
void this.handleShareData();
}

if (isCallbackUrl(event.url)) {
const { command, params } = parseCallbackUrl(event.url);

switch (command) {

case CallbackUrlCommand.OpenNote:
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Note',
noteId: params.id,
});
break;

case CallbackUrlCommand.OpenTag:
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Notes',
tagId: params.id,
});
break;

case CallbackUrlCommand.OpenFolder:
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Notes',
folderId: params.id,
});
break;

}
}
};

this.handleNewShare_ = () => {
Expand Down

0 comments on commit 218913f

Please sign in to comment.