diff --git a/lib/core/note.dart b/lib/core/note.dart index 2ee4e26e..b2620f4b 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -18,6 +18,7 @@ class Note with ChangeNotifier implements Comparable { String filePath = ""; DateTime _created; + DateTime _modified; NoteData _data = NoteData(); DateTime _fileLastModified; @@ -44,6 +45,25 @@ class Note with ChangeNotifier implements Comparable { notifyListeners(); } + DateTime get modified { + return _modified; + } + + set modified(DateTime dt) { + _modified = dt; + + if (hasValidDate()) { + _data.props['modified'] = toIso8601WithTimezone(_modified); + } else { + _data.props.remove('modified'); + } + notifyListeners(); + } + + void updateModified() { + modified = DateTime.now(); + } + String get body { return data.body; } @@ -153,7 +173,7 @@ class Note with ChangeNotifier implements Comparable { @override String toString() { - return 'Note{filePath: $filePath, created: $created, data: $data}'; + return 'Note{filePath: $filePath, created: $created, modified: $modified, data: $data}'; } @override @@ -161,7 +181,7 @@ class Note with ChangeNotifier implements Comparable { if (other == null) { return -1; } - if (created == other.created) return filePath.compareTo(other.filePath); - return created.compareTo(other.created); + if (modified == other.modified) return filePath.compareTo(other.filePath); + return modified.compareTo(other.modified); } } diff --git a/lib/state_container.dart b/lib/state_container.dart index 0a0769c1..6273dcf9 100644 --- a/lib/state_container.dart +++ b/lib/state_container.dart @@ -154,6 +154,7 @@ class StateContainerState extends State { note.filePath = p.join(parentPath, getFileName(note)); } note.parent.insert(index, note); + note.updateModified(); _gitRepo.addNote(note).then((NoteRepoResult _) { syncNotes(); }); @@ -161,6 +162,7 @@ class StateContainerState extends State { void updateNote(Note note) { Fimber.d("State Container updateNote"); + note.updateModified(); _gitRepo.updateNote(note).then((NoteRepoResult _) { syncNotes(); });