mirror of https://github.com/laurent22/joplin.git
Handle lat/long
parent
a71210658f
commit
5e187e4f1a
|
@ -5,6 +5,7 @@
|
|||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="16"
|
||||
|
|
|
@ -17,7 +17,13 @@ class NoteScreenComponent extends React.Component {
|
|||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.setState({ note: this.props.note });
|
||||
if (!this.props.noteId) {
|
||||
this.setState({ note: Note.new(this.props.folderId) });
|
||||
} else {
|
||||
Note.load(this.props.noteId).then((note) => {
|
||||
this.setState({ note: note });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
noteComponent_change = (propName, propValue) => {
|
||||
|
@ -37,14 +43,7 @@ class NoteScreenComponent extends React.Component {
|
|||
}
|
||||
|
||||
saveNoteButton_press = () => {
|
||||
Note.save(this.state.note).then((note) => {
|
||||
this.props.dispatch({
|
||||
type: 'NOTES_UPDATE_ONE',
|
||||
note: note,
|
||||
});
|
||||
}).catch((error) => {
|
||||
Log.warn('Cannot save note', error);
|
||||
});
|
||||
Note.save(this.state.note);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -63,7 +62,8 @@ class NoteScreenComponent extends React.Component {
|
|||
const NoteScreen = connect(
|
||||
(state) => {
|
||||
return {
|
||||
note: state.selectedNoteId ? Note.byId(state.notes, state.selectedNoteId) : Note.new(state.selectedFolderId),
|
||||
noteId: state.selectedNoteId,
|
||||
folderId: state.selectedFolderId,
|
||||
};
|
||||
}
|
||||
)(NoteScreenComponent)
|
||||
|
|
|
@ -330,8 +330,6 @@ class Database {
|
|||
default: Database.formatValue(row.field_type, row.field_default),
|
||||
});
|
||||
}
|
||||
|
||||
Log.info(this.tableFields_);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
class Geolocation {
|
||||
|
||||
static currentPosition_testResponse() {
|
||||
return {
|
||||
mocked: false,
|
||||
timestamp: (new Date()).getTime(),
|
||||
coords: {
|
||||
speed: 0,
|
||||
heading: 0,
|
||||
accuracy: 20,
|
||||
longitude: -3.4596633911132812,
|
||||
altitude: 0,
|
||||
latitude: 48.73219093634444
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static currentPosition(options = null) {
|
||||
if (!options) options = {};
|
||||
if (!('enableHighAccuracy' in options)) options.enableHighAccuracy = true;
|
||||
if (!('timeout' in options)) options.timeout = 10000;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
navigator.geolocation.getCurrentPosition((data) => {
|
||||
resolve(data);
|
||||
}, (error) => {
|
||||
rejec(error);
|
||||
}, options);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Geolocation };
|
|
@ -1,5 +1,6 @@
|
|||
import { BaseModel } from 'src/base-model.js';
|
||||
import { Log } from 'src/log.js';
|
||||
import { Geolocation } from 'src/geolocation.js';
|
||||
|
||||
class Note extends BaseModel {
|
||||
|
||||
|
@ -39,6 +40,38 @@ class Note extends BaseModel {
|
|||
|
||||
}
|
||||
|
||||
static save(o, options = null) {
|
||||
if (!options) options = {};
|
||||
if (!('updateLatLong' in options)) options.updateLatLong = true;
|
||||
|
||||
return super.save(o, options).then((note) => {
|
||||
this.dispatch({
|
||||
type: 'NOTES_UPDATE_ONE',
|
||||
note: note,
|
||||
});
|
||||
|
||||
if (options.updateLatLong && !note.latitude && !note.longitude) {
|
||||
Log.info('Updating lat/long of note...');
|
||||
let geoData = null;
|
||||
Geolocation.currentPosition().then((data) => {
|
||||
Log.info('Got lat/long');
|
||||
geoData = data;
|
||||
return Note.load(note.id);
|
||||
}).then((note) => {
|
||||
if (!note) return; // Has been deleted in the meantime
|
||||
note.longitude = geoData.coords.longitude;
|
||||
note.latitude = geoData.coords.latitude;
|
||||
note.altitude = geoData.coords.altitude;
|
||||
Note.save(note, { updateLatLong: false });
|
||||
}).catch((error) => {
|
||||
Log.info('Cannot get location:', error);
|
||||
});
|
||||
}
|
||||
|
||||
return note;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Note };
|
|
@ -164,7 +164,7 @@ class AppComponent extends React.Component {
|
|||
componentDidMount() {
|
||||
let db = new Database();
|
||||
//db.setDebugEnabled(Registry.debugMode());
|
||||
db.setDebugEnabled(true);
|
||||
db.setDebugEnabled(false);
|
||||
|
||||
BaseModel.dispatch = this.props.dispatch;
|
||||
BaseModel.db_ = db;
|
||||
|
|
Loading…
Reference in New Issue