Note: Store when last modified

Also sort the notes based on when last modified. Now that we're moving
towards being a more note-taking app, it makes sense that a recently
modified note goes on top.

Of course, the sorting should be controllable by the user, but the
default probably should be by when modified.
This commit is contained in:
Vishesh Handa
2019-12-09 00:02:40 +01:00
parent e3688cb0d9
commit 76f70f0d18
2 changed files with 25 additions and 3 deletions

View File

@ -18,6 +18,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
String filePath = "";
DateTime _created;
DateTime _modified;
NoteData _data = NoteData();
DateTime _fileLastModified;
@ -44,6 +45,25 @@ class Note with ChangeNotifier implements Comparable<Note> {
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<Note> {
@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<Note> {
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);
}
}

View File

@ -154,6 +154,7 @@ class StateContainerState extends State<StateContainer> {
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<StateContainer> {
void updateNote(Note note) {
Fimber.d("State Container updateNote");
note.updateModified();
_gitRepo.updateNote(note).then((NoteRepoResult _) {
syncNotes();
});