2017-11-03 02:09:34 +02:00
|
|
|
const React = require('react'); const Component = React.Component;
|
2018-02-05 20:32:59 +02:00
|
|
|
const { Platform, Keyboard, BackHandler, View, Button, TextInput, WebView, Text, StyleSheet, Linking, Image } = require('react-native');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const { uuid } = require('lib/uuid.js');
|
|
|
|
const { Log } = require('lib/log.js');
|
2017-11-20 00:08:58 +02:00
|
|
|
const RNFS = require('react-native-fs');
|
2017-12-14 20:12:14 +02:00
|
|
|
const Note = require('lib/models/Note.js');
|
|
|
|
const Setting = require('lib/models/Setting.js');
|
|
|
|
const Resource = require('lib/models/Resource.js');
|
|
|
|
const Folder = require('lib/models/Folder.js');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { BackButtonService } = require('lib/services/back-button.js');
|
2018-02-22 00:08:34 +02:00
|
|
|
const NavService = require('lib/services/NavService.js');
|
2017-12-14 20:12:14 +02:00
|
|
|
const BaseModel = require('lib/BaseModel.js');
|
2017-11-03 02:09:34 +02:00
|
|
|
const { ActionButton } = require('lib/components/action-button.js');
|
|
|
|
const Icon = require('react-native-vector-icons/Ionicons').default;
|
2017-12-02 01:15:49 +02:00
|
|
|
const { fileExtension, basename, safeFileExtension } = require('lib/path-utils.js');
|
2017-11-20 00:08:58 +02:00
|
|
|
const mimeUtils = require('lib/mime-utils.js').mime;
|
2017-11-03 02:09:34 +02:00
|
|
|
const { ScreenHeader } = require('lib/components/screen-header.js');
|
|
|
|
const { time } = require('lib/time-utils.js');
|
|
|
|
const { Checkbox } = require('lib/components/checkbox.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { shim } = require('lib/shim.js');
|
|
|
|
const { BaseScreenComponent } = require('lib/components/base-screen.js');
|
|
|
|
const { dialogs } = require('lib/dialogs.js');
|
|
|
|
const { globalStyle, themeStyle } = require('lib/components/global-style.js');
|
|
|
|
const DialogBox = require('react-native-dialogbox').default;
|
|
|
|
const { NoteBodyViewer } = require('lib/components/note-body-viewer.js');
|
|
|
|
const RNFetchBlob = require('react-native-fetch-blob').default;
|
|
|
|
const { DocumentPicker, DocumentPickerUtil } = require('react-native-document-picker');
|
|
|
|
const ImageResizer = require('react-native-image-resizer').default;
|
2017-11-05 02:49:23 +02:00
|
|
|
const shared = require('lib/components/shared/note-screen-shared.js');
|
2017-11-19 17:18:07 +02:00
|
|
|
const ImagePicker = require('react-native-image-picker');
|
2017-11-28 00:50:46 +02:00
|
|
|
const AlarmService = require('lib/services/AlarmService.js');
|
2017-11-24 19:09:24 +02:00
|
|
|
const { SelectDateTimeDialog } = require('lib/components/select-date-time-dialog.js');
|
2017-05-12 22:23:54 +02:00
|
|
|
|
2017-07-14 20:49:14 +02:00
|
|
|
class NoteScreenComponent extends BaseScreenComponent {
|
2017-12-19 22:14:40 +02:00
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
static navigationOptions(options) {
|
2017-05-16 21:57:09 +02:00
|
|
|
return { header: null };
|
|
|
|
}
|
2017-05-12 22:23:54 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2017-07-10 23:34:26 +02:00
|
|
|
this.state = {
|
|
|
|
note: Note.new(),
|
|
|
|
mode: 'view',
|
2017-07-13 20:47:31 +02:00
|
|
|
noteMetadata: '',
|
|
|
|
showNoteMetadata: false,
|
2017-07-13 23:50:21 +02:00
|
|
|
folder: null,
|
2017-07-15 01:12:32 +02:00
|
|
|
lastSavedNote: null,
|
2017-07-24 23:52:30 +02:00
|
|
|
isLoading: true,
|
2017-07-31 19:56:14 +02:00
|
|
|
titleTextInputHeight: 20,
|
2017-09-10 18:56:27 +02:00
|
|
|
alarmDialogShown: false,
|
2017-12-19 11:08:22 +02:00
|
|
|
heightBumpView:0
|
2017-07-16 23:17:22 +02:00
|
|
|
};
|
|
|
|
|
2017-11-19 17:19:36 +02:00
|
|
|
// iOS doesn't support multiline text fields properly so disable it
|
|
|
|
this.enableMultilineTitle_ = Platform.OS !== 'ios';
|
2017-12-19 22:14:40 +02:00
|
|
|
|
2017-07-16 23:17:22 +02:00
|
|
|
this.saveButtonHasBeenShown_ = false;
|
2017-07-15 01:12:32 +02:00
|
|
|
|
2017-08-01 20:53:50 +02:00
|
|
|
this.styles_ = {};
|
|
|
|
|
2018-02-22 00:08:34 +02:00
|
|
|
const saveDialog = async () => {
|
2017-08-24 20:10:03 +02:00
|
|
|
if (this.isModified()) {
|
|
|
|
let buttonId = await dialogs.pop(this, _('This note has been modified:'), [
|
2018-02-22 20:58:15 +02:00
|
|
|
{ text: _('Save changes'), id: 'save' },
|
|
|
|
{ text: _('Discard changes'), id: 'discard' },
|
|
|
|
{ text: _('Cancel'), id: 'cancel' },
|
2017-08-24 20:10:03 +02:00
|
|
|
]);
|
2017-07-31 21:02:21 +02:00
|
|
|
|
2017-08-24 20:10:03 +02:00
|
|
|
if (buttonId == 'cancel') return true;
|
|
|
|
if (buttonId == 'save') await this.saveNoteButton_press();
|
|
|
|
}
|
2017-07-31 21:02:21 +02:00
|
|
|
|
2018-02-22 00:08:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.navHandler = async () => {
|
|
|
|
return await saveDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.backHandler = async () => {
|
|
|
|
const r = await saveDialog();
|
|
|
|
if (r) return r;
|
|
|
|
|
2017-08-24 20:10:03 +02:00
|
|
|
if (!this.state.note.id) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-31 21:02:21 +02:00
|
|
|
|
2017-08-24 20:10:03 +02:00
|
|
|
if (this.state.mode == 'edit') {
|
|
|
|
Keyboard.dismiss()
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
note: Object.assign({}, this.state.lastSavedNote),
|
|
|
|
mode: 'view',
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
2017-07-15 01:12:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 20:53:50 +02:00
|
|
|
styles() {
|
|
|
|
const themeId = this.props.theme;
|
|
|
|
const theme = themeStyle(themeId);
|
|
|
|
|
|
|
|
if (this.styles_[themeId]) return this.styles_[themeId];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
|
|
|
let styles = {
|
|
|
|
bodyTextInput: {
|
|
|
|
flex: 1,
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
textAlignVertical: 'top',
|
|
|
|
color: theme.color,
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
},
|
|
|
|
noteBodyViewer: {
|
|
|
|
flex: 1,
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
paddingTop: theme.marginTop,
|
|
|
|
paddingBottom: theme.marginBottom,
|
|
|
|
},
|
2017-08-02 19:47:25 +02:00
|
|
|
metadata: {
|
|
|
|
paddingLeft: globalStyle.marginLeft,
|
|
|
|
paddingRight: globalStyle.marginRight,
|
|
|
|
color: theme.color,
|
|
|
|
},
|
2017-08-01 20:53:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
styles.titleContainer = {
|
|
|
|
flex: 0,
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
borderBottomColor: theme.dividerColor,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
styles.titleContainerTodo = Object.assign({}, styles.titleContainer);
|
2017-08-21 20:32:43 +02:00
|
|
|
styles.titleContainerTodo.paddingLeft = 0;
|
2017-08-01 20:53:50 +02:00
|
|
|
|
|
|
|
this.styles_[themeId] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[themeId];
|
|
|
|
}
|
|
|
|
|
2017-07-15 01:12:32 +02:00
|
|
|
isModified() {
|
2017-11-05 02:49:23 +02:00
|
|
|
return shared.isModified(this);
|
2017-05-12 22:23:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 16:11:44 +02:00
|
|
|
async componentWillMount() {
|
2017-08-24 20:10:03 +02:00
|
|
|
BackButtonService.addHandler(this.backHandler);
|
2018-02-22 00:08:34 +02:00
|
|
|
NavService.addHandler(this.navHandler);
|
2017-07-15 01:12:32 +02:00
|
|
|
|
2017-11-05 02:49:23 +02:00
|
|
|
await shared.initState(this);
|
2017-07-23 16:11:44 +02:00
|
|
|
|
|
|
|
this.refreshNoteMetadata();
|
2017-07-13 23:50:21 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 20:36:27 +02:00
|
|
|
refreshNoteMetadata(force = null) {
|
|
|
|
return shared.refreshNoteMetadata(this, force);
|
2017-05-12 22:23:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 01:12:32 +02:00
|
|
|
componentWillUnmount() {
|
2017-08-24 20:10:03 +02:00
|
|
|
BackButtonService.removeHandler(this.backHandler);
|
2018-02-22 00:08:34 +02:00
|
|
|
NavService.removeHandler(this.navHandler);
|
2017-07-13 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
title_changeText(text) {
|
2017-11-05 02:49:23 +02:00
|
|
|
shared.noteComponent_change(this, 'title', text);
|
2017-05-12 22:23:54 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
body_changeText(text) {
|
2017-11-05 02:49:23 +02:00
|
|
|
shared.noteComponent_change(this, 'body', text);
|
2017-07-22 20:16:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:29:00 +02:00
|
|
|
async saveNoteButton_press() {
|
2017-11-05 02:49:23 +02:00
|
|
|
await shared.saveNoteButton_press(this);
|
2017-07-17 22:22:05 +02:00
|
|
|
|
2017-09-24 16:48:23 +02:00
|
|
|
Keyboard.dismiss();
|
2017-05-12 22:23:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-22 20:16:16 +02:00
|
|
|
async saveOneProperty(name, value) {
|
2017-11-05 02:49:23 +02:00
|
|
|
await shared.saveOneProperty(this, name, value);
|
2017-07-22 20:16:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 01:12:32 +02:00
|
|
|
async deleteNote_onPress() {
|
|
|
|
let note = this.state.note;
|
|
|
|
if (!note.id) return;
|
|
|
|
|
|
|
|
let ok = await dialogs.confirm(this, _('Delete note?'));
|
|
|
|
if (!ok) return;
|
|
|
|
|
|
|
|
let folderId = note.parent_id;
|
|
|
|
|
|
|
|
await Note.delete(note.id);
|
2017-07-16 23:17:22 +02:00
|
|
|
|
2017-07-25 20:09:01 +02:00
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-25 20:09:01 +02:00
|
|
|
routeName: 'Notes',
|
|
|
|
folderId: folderId,
|
|
|
|
});
|
2017-06-04 17:01:52 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 23:40:14 +02:00
|
|
|
async pickDocument() {
|
|
|
|
return new Promise((resolve, reject) => {
|
2017-11-19 17:19:36 +02:00
|
|
|
DocumentPicker.show({ filetype: [DocumentPickerUtil.allFiles()] }, (error,res) => {
|
2017-08-01 23:40:14 +02:00
|
|
|
if (error) {
|
2017-09-10 18:57:06 +02:00
|
|
|
// Also returns an error if the user doesn't pick a file
|
|
|
|
// so just resolve with null.
|
|
|
|
console.info('pickDocument error:', error);
|
|
|
|
resolve(null);
|
2017-08-01 23:40:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:47:25 +02:00
|
|
|
async imageDimensions(uri) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Image.getSize(uri, (width, height) => {
|
|
|
|
resolve({ width: width, height: height });
|
|
|
|
}, (error) => { reject(error) });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
showImagePicker(options) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
ImagePicker.showImagePicker(options, (response) => {
|
|
|
|
resolve(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-08-01 23:40:14 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
async resizeImage(localFilePath, targetPath, mimeType) {
|
|
|
|
const maxSize = Resource.IMAGE_MAX_DIMENSION;
|
2017-08-02 19:47:25 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
let dimensions = await this.imageDimensions(localFilePath);
|
|
|
|
|
|
|
|
reg.logger().info('Original dimensions ', dimensions);
|
|
|
|
if (dimensions.width > maxSize || dimensions.height > maxSize) {
|
|
|
|
dimensions.width = maxSize;
|
|
|
|
dimensions.height = maxSize;
|
|
|
|
}
|
|
|
|
reg.logger().info('New dimensions ', dimensions);
|
|
|
|
|
|
|
|
const format = mimeType == 'image/png' ? 'PNG' : 'JPEG';
|
|
|
|
reg.logger().info('Resizing image ' + localFilePath);
|
2017-11-20 00:08:58 +02:00
|
|
|
const resizedImage = await ImageResizer.createResizedImage(localFilePath, dimensions.width, dimensions.height, format, 85); //, 0, targetPath);
|
2017-12-19 22:14:40 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
const resizedImagePath = resizedImage.uri;
|
|
|
|
reg.logger().info('Resized image ', resizedImagePath);
|
2017-11-20 00:08:58 +02:00
|
|
|
reg.logger().info('Moving ' + resizedImagePath + ' => ' + targetPath);
|
2017-12-19 22:14:40 +02:00
|
|
|
|
2017-11-20 00:08:58 +02:00
|
|
|
await RNFS.copyFile(resizedImagePath, targetPath);
|
2017-12-19 22:14:40 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
try {
|
2017-11-20 00:08:58 +02:00
|
|
|
await RNFS.unlink(resizedImagePath);
|
2017-11-19 17:18:07 +02:00
|
|
|
} catch (error) {
|
2017-11-20 00:08:58 +02:00
|
|
|
reg.logger().warn('Error when unlinking cached file: ', error);
|
2017-11-19 17:18:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async attachFile(pickerResponse, fileType) {
|
|
|
|
if (!pickerResponse) {
|
|
|
|
reg.logger().warn('Got no response from picker');
|
2017-11-01 19:39:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-01 23:40:14 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
if (pickerResponse.error) {
|
|
|
|
reg.logger().warn('Got error from picker', pickerResponse.error);
|
2017-11-01 19:39:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-02 19:47:25 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
if (pickerResponse.didCancel) {
|
|
|
|
reg.logger().info('User cancelled picker');
|
|
|
|
return;
|
|
|
|
}
|
2017-08-02 19:47:25 +02:00
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
const localFilePath = pickerResponse.uri;
|
2017-11-20 00:08:58 +02:00
|
|
|
let mimeType = pickerResponse.type;
|
|
|
|
|
|
|
|
if (!mimeType) {
|
|
|
|
const ext = fileExtension(localFilePath);
|
|
|
|
mimeType = mimeUtils.fromFileExtension(ext);
|
|
|
|
}
|
2017-08-02 19:47:25 +02:00
|
|
|
|
2017-11-20 21:18:49 +02:00
|
|
|
if (!mimeType && fileType === 'image') {
|
|
|
|
// Assume JPEG if we couldn't determine the file type. It seems to happen with the image picker
|
|
|
|
// when the file path is something like content://media/external/images/media/123456
|
|
|
|
// If the image is not a JPEG, something will throw an error below, but there's a good chance
|
|
|
|
// it will work.
|
|
|
|
reg.logger().info('Missing file type and could not detect it - assuming image/jpg');
|
|
|
|
mimeType = 'image/jpg';
|
|
|
|
}
|
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
reg.logger().info('Got file: ' + localFilePath);
|
2017-11-20 00:08:58 +02:00
|
|
|
reg.logger().info('Got type: ' + mimeType);
|
2017-08-01 23:40:14 +02:00
|
|
|
|
|
|
|
let resource = Resource.new();
|
|
|
|
resource.id = uuid.create();
|
2017-11-20 00:08:58 +02:00
|
|
|
resource.mime = mimeType;
|
2017-11-19 17:18:07 +02:00
|
|
|
resource.title = pickerResponse.fileName ? pickerResponse.fileName : _('Untitled');
|
2017-12-02 01:15:49 +02:00
|
|
|
resource.file_extension = safeFileExtension(fileExtension(pickerResponse.fileName));
|
|
|
|
|
|
|
|
if (!resource.mime) resource.mime = 'application/octet-stream';
|
2017-08-01 23:40:14 +02:00
|
|
|
|
2017-08-02 19:47:25 +02:00
|
|
|
let targetPath = Resource.fullPath(resource);
|
|
|
|
|
2017-11-20 00:08:58 +02:00
|
|
|
try {
|
|
|
|
if (mimeType == 'image/jpeg' || mimeType == 'image/jpg' || mimeType == 'image/png') {
|
|
|
|
await this.resizeImage(localFilePath, targetPath, pickerResponse.mime);
|
2017-11-19 17:18:07 +02:00
|
|
|
} else {
|
2017-11-20 00:08:58 +02:00
|
|
|
if (fileType === 'image') {
|
|
|
|
dialogs.error(this, _('Unsupported image type: %s', mimeType));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
await RNFetchBlob.fs.cp(localFilePath, targetPath);
|
|
|
|
}
|
2017-08-02 19:47:25 +02:00
|
|
|
}
|
2017-11-20 00:08:58 +02:00
|
|
|
} catch (error) {
|
|
|
|
reg.logger().warn('Could not attach file:', error);
|
|
|
|
return;
|
2017-08-02 19:47:25 +02:00
|
|
|
}
|
2017-08-01 23:40:14 +02:00
|
|
|
|
|
|
|
await Resource.save(resource, { isNew: true });
|
|
|
|
|
|
|
|
const resourceTag = Resource.markdownTag(resource);
|
2017-07-13 20:47:31 +02:00
|
|
|
|
2017-08-02 19:47:25 +02:00
|
|
|
const newNote = Object.assign({}, this.state.note);
|
|
|
|
newNote.body += "\n" + resourceTag;
|
|
|
|
this.setState({ note: newNote });
|
2017-07-13 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-19 17:18:07 +02:00
|
|
|
async attachImage_onPress() {
|
|
|
|
const options = {
|
|
|
|
mediaType: 'photo',
|
|
|
|
};
|
|
|
|
const response = await this.showImagePicker(options);
|
|
|
|
await this.attachFile(response, 'image');
|
|
|
|
}
|
|
|
|
|
|
|
|
async attachFile_onPress() {
|
|
|
|
const response = await this.pickDocument();
|
|
|
|
await this.attachFile(response, 'all');
|
|
|
|
}
|
|
|
|
|
2017-07-30 21:51:18 +02:00
|
|
|
toggleIsTodo_onPress() {
|
2017-11-05 02:49:23 +02:00
|
|
|
shared.toggleIsTodo_onPress(this);
|
2017-07-17 22:22:05 +02:00
|
|
|
}
|
|
|
|
|
2017-09-10 18:56:27 +02:00
|
|
|
setAlarm_onPress() {
|
|
|
|
this.setState({ alarmDialogShown: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
async onAlarmDialogAccept(date) {
|
|
|
|
let newNote = Object.assign({}, this.state.note);
|
|
|
|
newNote.todo_due = date ? date.getTime() : 0;
|
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
await this.saveOneProperty('todo_due', date ? date.getTime() : 0);
|
|
|
|
|
|
|
|
this.setState({ alarmDialogShown: false });
|
2017-09-10 18:56:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onAlarmDialogReject() {
|
|
|
|
this.setState({ alarmDialogShown: false });
|
|
|
|
}
|
|
|
|
|
2017-07-13 20:47:31 +02:00
|
|
|
showMetadata_onPress() {
|
2017-11-05 02:49:23 +02:00
|
|
|
shared.showMetadata_onPress(this);
|
2017-06-04 17:01:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-22 20:16:16 +02:00
|
|
|
async showOnMap_onPress() {
|
|
|
|
if (!this.state.note.id) return;
|
|
|
|
|
|
|
|
let note = await Note.load(this.state.note.id);
|
|
|
|
try {
|
|
|
|
const url = Note.geolocationUrl(note);
|
|
|
|
Linking.openURL(url);
|
|
|
|
} catch (error) {
|
|
|
|
await dialogs.error(this, error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
menuOptions() {
|
2017-07-17 22:22:05 +02:00
|
|
|
const note = this.state.note;
|
2017-09-10 18:57:06 +02:00
|
|
|
const isTodo = note && !!note.is_todo;
|
2017-07-17 22:22:05 +02:00
|
|
|
|
2017-09-10 18:57:06 +02:00
|
|
|
let output = [];
|
|
|
|
|
2017-11-20 21:01:19 +02:00
|
|
|
// The file attachement modules only work in Android >= 5 (Version 21)
|
|
|
|
// https://github.com/react-community/react-native-image-picker/issues/606
|
2017-11-20 20:29:39 +02:00
|
|
|
let canAttachPicture = true;
|
|
|
|
if (Platform.OS === 'android' && Platform.Version < 21) canAttachPicture = false;
|
|
|
|
if (canAttachPicture) {
|
2017-11-28 22:31:14 +02:00
|
|
|
output.push({ title: _('Attach photo'), onPress: () => { this.attachImage_onPress(); } });
|
|
|
|
output.push({ title: _('Attach any file'), onPress: () => { this.attachFile_onPress(); } });
|
|
|
|
output.push({ isDivider: true });
|
2017-11-20 21:01:19 +02:00
|
|
|
}
|
2017-07-17 22:22:05 +02:00
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
if (isTodo) {
|
2017-11-28 22:31:14 +02:00
|
|
|
output.push({ title: _('Set alarm'), onPress: () => { this.setState({ alarmDialogShown: true }) }});;
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
2017-09-10 18:57:06 +02:00
|
|
|
|
2017-11-28 22:31:14 +02:00
|
|
|
output.push({ title: isTodo ? _('Convert to note') : _('Convert to todo'), onPress: () => { this.toggleIsTodo_onPress(); } });
|
|
|
|
output.push({ isDivider: true });
|
2017-09-24 16:48:23 +02:00
|
|
|
if (this.props.showAdvancedOptions) output.push({ title: this.state.showNoteMetadata ? _('Hide metadata') : _('Show metadata'), onPress: () => { this.showMetadata_onPress(); } });
|
2017-11-28 22:31:14 +02:00
|
|
|
output.push({ title: _('View on map'), onPress: () => { this.showOnMap_onPress(); } });
|
|
|
|
output.push({ isDivider: true });
|
|
|
|
output.push({ title: _('Delete'), onPress: () => { this.deleteNote_onPress(); } });
|
2017-09-10 18:57:06 +02:00
|
|
|
|
|
|
|
return output;
|
2017-06-04 17:01:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 18:06:05 +02:00
|
|
|
async todoCheckbox_change(checked) {
|
2017-07-16 23:17:22 +02:00
|
|
|
await this.saveOneProperty('todo_completed', checked ? time.unixMs() : 0);
|
2017-07-15 01:12:32 +02:00
|
|
|
}
|
|
|
|
|
2017-07-31 19:56:14 +02:00
|
|
|
titleTextInput_contentSizeChange(event) {
|
2017-11-19 17:19:36 +02:00
|
|
|
if (!this.enableMultilineTitle_) return;
|
|
|
|
|
2017-07-31 19:56:14 +02:00
|
|
|
let height = event.nativeEvent.contentSize.height;
|
|
|
|
this.setState({ titleTextInputHeight: height });
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:23:54 +02:00
|
|
|
render() {
|
2017-07-24 23:52:30 +02:00
|
|
|
if (this.state.isLoading) {
|
|
|
|
return (
|
|
|
|
<View style={this.styles().screen}>
|
2017-07-24 23:58:14 +02:00
|
|
|
<ScreenHeader/>
|
2017-07-24 23:52:30 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-01 20:53:50 +02:00
|
|
|
const theme = themeStyle(this.props.theme);
|
2017-05-24 22:51:50 +02:00
|
|
|
const note = this.state.note;
|
|
|
|
const isTodo = !!Number(note.is_todo);
|
2017-07-13 23:50:21 +02:00
|
|
|
const folder = this.state.folder;
|
2017-07-24 23:52:30 +02:00
|
|
|
const isNew = !note.id;
|
2017-05-24 22:51:50 +02:00
|
|
|
|
2017-07-10 23:34:26 +02:00
|
|
|
let bodyComponent = null;
|
|
|
|
if (this.state.mode == 'view') {
|
2017-07-30 21:51:18 +02:00
|
|
|
const onCheckboxChange = (newBody) => {
|
|
|
|
this.saveOneProperty('body', newBody);
|
|
|
|
};
|
2017-07-17 23:34:08 +02:00
|
|
|
|
2017-08-01 20:53:50 +02:00
|
|
|
bodyComponent = <NoteBodyViewer style={this.styles().noteBodyViewer} webViewStyle={theme} note={note} onCheckboxChange={(newBody) => { onCheckboxChange(newBody) }}/>
|
2017-07-10 23:34:26 +02:00
|
|
|
} else {
|
2017-07-24 23:52:30 +02:00
|
|
|
const focusBody = !isNew && !!note.title;
|
2017-10-30 23:29:36 +02:00
|
|
|
|
|
|
|
// Note: blurOnSubmit is necessary to get multiline to work.
|
|
|
|
// See https://github.com/facebook/react-native/issues/12717#issuecomment-327001997
|
2017-07-15 01:12:32 +02:00
|
|
|
bodyComponent = (
|
|
|
|
<TextInput
|
2017-07-16 18:31:42 +02:00
|
|
|
autoCapitalize="sentences"
|
2017-07-24 23:52:30 +02:00
|
|
|
autoFocus={focusBody}
|
2017-08-01 20:53:50 +02:00
|
|
|
style={this.styles().bodyTextInput}
|
2017-07-15 01:12:32 +02:00
|
|
|
multiline={true}
|
|
|
|
value={note.body}
|
|
|
|
onChangeText={(text) => this.body_changeText(text)}
|
2017-10-30 23:29:36 +02:00
|
|
|
blurOnSubmit={false}
|
2017-07-15 01:12:32 +02:00
|
|
|
/>
|
|
|
|
);
|
2017-07-10 23:34:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-14 01:35:37 +02:00
|
|
|
const renderActionButton = () => {
|
|
|
|
let buttons = [];
|
|
|
|
|
|
|
|
buttons.push({
|
|
|
|
title: _('Edit'),
|
|
|
|
icon: 'md-create',
|
|
|
|
onPress: () => {
|
|
|
|
this.setState({ mode: 'edit' });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
if (this.state.mode == 'edit') return <ActionButton style={{display:'none'}}/>;
|
2017-07-15 01:12:32 +02:00
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
return <ActionButton multiStates={true} buttons={buttons} buttonIndex={0} />
|
2017-07-14 01:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const actionButtonComp = renderActionButton();
|
|
|
|
|
2017-07-16 23:17:22 +02:00
|
|
|
let showSaveButton = this.state.mode == 'edit' || this.isModified() || this.saveButtonHasBeenShown_;
|
2017-07-16 12:17:40 +02:00
|
|
|
let saveButtonDisabled = !this.isModified();
|
|
|
|
|
2017-07-16 23:17:22 +02:00
|
|
|
if (showSaveButton) this.saveButtonHasBeenShown_ = true;
|
|
|
|
|
2017-08-01 20:53:50 +02:00
|
|
|
const titleContainerStyle = isTodo ? this.styles().titleContainerTodo : this.styles().titleContainer;
|
|
|
|
|
|
|
|
let titleTextInputStyle = {
|
|
|
|
flex: 1,
|
|
|
|
paddingLeft: 0,
|
|
|
|
color: theme.color,
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: theme.fontSize,
|
2017-11-19 17:19:36 +02:00
|
|
|
paddingTop: 10, // Added for iOS (Not needed for Android??)
|
|
|
|
paddingBottom: 10, // Added for iOS (Not needed for Android??)
|
2017-08-01 20:53:50 +02:00
|
|
|
};
|
2017-07-21 23:40:02 +02:00
|
|
|
|
2017-11-19 17:19:36 +02:00
|
|
|
if (this.enableMultilineTitle_) titleTextInputStyle.height = this.state.titleTextInputHeight;
|
2017-07-31 19:56:14 +02:00
|
|
|
|
2017-08-21 20:32:43 +02:00
|
|
|
let checkboxStyle = {
|
|
|
|
color: theme.color,
|
|
|
|
paddingRight: 10,
|
|
|
|
paddingLeft: theme.marginLeft,
|
2017-11-19 17:19:36 +02:00
|
|
|
paddingTop: 10, // Added for iOS (Not needed for Android??)
|
|
|
|
paddingBottom: 10, // Added for iOS (Not needed for Android??)
|
2017-08-21 20:32:43 +02:00
|
|
|
}
|
|
|
|
|
2017-09-10 18:56:27 +02:00
|
|
|
const dueDate = isTodo && note.todo_due ? new Date(note.todo_due) : null;
|
|
|
|
|
2017-07-31 19:56:14 +02:00
|
|
|
const titleComp = (
|
|
|
|
<View style={titleContainerStyle}>
|
2017-08-21 20:32:43 +02:00
|
|
|
{ isTodo && <Checkbox style={checkboxStyle} checked={!!Number(note.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(checked) }} /> }
|
2017-07-31 19:56:14 +02:00
|
|
|
<TextInput
|
|
|
|
onContentSizeChange={(event) => this.titleTextInput_contentSizeChange(event)}
|
|
|
|
autoFocus={isNew}
|
2017-11-19 17:19:36 +02:00
|
|
|
multiline={this.enableMultilineTitle_}
|
2017-07-31 19:56:14 +02:00
|
|
|
underlineColorAndroid="#ffffff00"
|
|
|
|
autoCapitalize="sentences"
|
|
|
|
style={titleTextInputStyle}
|
|
|
|
value={note.title}
|
|
|
|
onChangeText={(text) => this.title_changeText(text)}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
2017-05-12 22:23:54 +02:00
|
|
|
return (
|
2018-02-05 20:32:59 +02:00
|
|
|
<View style={this.rootStyle(this.props.theme).root}>
|
2017-07-16 12:17:40 +02:00
|
|
|
<ScreenHeader
|
2017-11-23 20:47:51 +02:00
|
|
|
folderPickerOptions={{
|
|
|
|
enabled: true,
|
|
|
|
selectedFolderId: folder ? folder.id : null,
|
2017-07-16 18:06:05 +02:00
|
|
|
onValueChange: async (itemValue, itemIndex) => {
|
|
|
|
if (note.id) await Note.moveToFolder(note.id, itemValue);
|
|
|
|
note.parent_id = itemValue;
|
|
|
|
|
|
|
|
const folder = await Folder.load(note.parent_id);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
lastSavedNote: Object.assign({}, note),
|
|
|
|
note: note,
|
|
|
|
folder: folder,
|
|
|
|
});
|
2017-11-23 20:47:51 +02:00
|
|
|
},
|
2017-07-16 18:06:05 +02:00
|
|
|
}}
|
2017-07-16 12:17:40 +02:00
|
|
|
menuOptions={this.menuOptions()}
|
|
|
|
showSaveButton={showSaveButton}
|
|
|
|
saveButtonDisabled={saveButtonDisabled}
|
|
|
|
onSaveButtonPress={() => this.saveNoteButton_press()}
|
|
|
|
/>
|
2017-07-31 19:56:14 +02:00
|
|
|
{ titleComp }
|
2017-07-13 20:47:31 +02:00
|
|
|
{ bodyComponent }
|
2017-07-14 01:35:37 +02:00
|
|
|
{ actionButtonComp }
|
2017-08-02 19:47:25 +02:00
|
|
|
{ this.state.showNoteMetadata && <Text style={this.styles().metadata}>{this.state.noteMetadata}</Text> }
|
2017-09-10 18:56:27 +02:00
|
|
|
|
|
|
|
<SelectDateTimeDialog
|
|
|
|
shown={this.state.alarmDialogShown}
|
|
|
|
date={dueDate}
|
|
|
|
onAccept={(date) => this.onAlarmDialogAccept(date) }
|
|
|
|
onReject={() => this.onAlarmDialogReject() }
|
|
|
|
/>
|
|
|
|
|
2017-07-15 01:12:32 +02:00
|
|
|
<DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
2018-02-05 20:32:59 +02:00
|
|
|
</View>
|
2017-05-12 22:23:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const NoteScreen = connect(
|
|
|
|
(state) => {
|
|
|
|
return {
|
2017-11-22 20:35:31 +02:00
|
|
|
noteId: state.selectedNoteIds.length ? state.selectedNoteIds[0] : null,
|
2017-05-22 22:22:50 +02:00
|
|
|
folderId: state.selectedFolderId,
|
2017-05-24 22:51:50 +02:00
|
|
|
itemType: state.selectedItemType,
|
2017-07-16 18:06:05 +02:00
|
|
|
folders: state.folders,
|
2017-08-01 20:53:50 +02:00
|
|
|
theme: state.settings.theme,
|
2017-09-24 16:48:23 +02:00
|
|
|
showAdvancedOptions: state.settings.showAdvancedOptions,
|
2017-05-12 22:23:54 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
)(NoteScreenComponent)
|
|
|
|
|
2017-11-03 02:13:17 +02:00
|
|
|
module.exports = { NoteScreen };
|