diff --git a/lib/note.dart b/lib/note.dart index 94e6429b..def5bfc6 100644 --- a/lib/note.dart +++ b/lib/note.dart @@ -1,13 +1,13 @@ import 'package:journal/datetime_utils.dart'; class Note implements Comparable { - String fileName; + String filePath; DateTime created; String body; Map extraProperties = Map(); - Note({this.created, this.body, this.fileName, this.extraProperties}) { + Note({this.created, this.body, this.filePath, this.extraProperties}) { if (created == null) { created = DateTime(0, 0, 0, 0, 0, 0, 0, 0); } @@ -17,10 +17,10 @@ class Note implements Comparable { } factory Note.fromJson(Map json) { - String fileName = ""; - if (json.containsKey("fileName")) { - fileName = json["fileName"].toString(); - json.remove("fileName"); + String filePath = ""; + if (json.containsKey("filePath")) { + filePath = json["filePath"].toString(); + json.remove("filePath"); } DateTime created; @@ -56,7 +56,7 @@ class Note implements Comparable { } return Note( - fileName: fileName, + filePath: filePath, created: created, body: body, extraProperties: json, @@ -70,14 +70,14 @@ class Note implements Comparable { json['created'] = createdStr; } json['body'] = body; - json['fileName'] = fileName; + json['filePath'] = filePath; return json; } @override int get hashCode => - fileName.hashCode ^ + filePath.hashCode ^ created.hashCode ^ body.hashCode ^ extraProperties.hashCode; @@ -87,7 +87,7 @@ class Note implements Comparable { identical(this, other) || other is Note && runtimeType == other.runtimeType && - fileName == other.fileName && + filePath == other.filePath && body == other.body && created == other.created && _equalMaps(extraProperties, other.extraProperties); @@ -100,7 +100,7 @@ class Note implements Comparable { @override String toString() { - return 'Note{fileName: $fileName, body: $body, created: $created, extraProperties: $extraProperties}'; + return 'Note{filePath: $filePath, body: $body, created: $created, extraProperties: $extraProperties}'; } @override @@ -108,7 +108,7 @@ class Note implements Comparable { if (other == null) { return -1; } - if (created == other.created) return fileName.compareTo(other.fileName); + if (created == other.created) return filePath.compareTo(other.filePath); return created.compareTo(other.created); } } diff --git a/lib/state_container.dart b/lib/state_container.dart index 510f2c1c..eae5f988 100644 --- a/lib/state_container.dart +++ b/lib/state_container.dart @@ -169,8 +169,8 @@ class StateContainerState extends State { void insertNote(int index, Note note) { print("State Container insertNote"); setState(() { - if (note.fileName == null || note.fileName.isEmpty) { - note.fileName = toIso8601WithTimezone(note.created) + '.md'; + if (note.filePath == null || note.filePath.isEmpty) { + note.filePath = toIso8601WithTimezone(note.created) + '.md'; } appState.notes.insert(index, note); noteRepo.addNote(note).then((NoteRepoResult _) { diff --git a/lib/storage/file_storage.dart b/lib/storage/file_storage.dart index a1c08c24..441c0f12 100644 --- a/lib/storage/file_storage.dart +++ b/lib/storage/file_storage.dart @@ -35,7 +35,7 @@ class FileStorage implements NoteRepository { if (note == null) { continue; } - if (!note.fileName.toLowerCase().endsWith('.md')) { + if (!note.filePath.toLowerCase().endsWith('.md')) { continue; } notes.add(note); @@ -54,13 +54,13 @@ class FileStorage implements NoteRepository { final string = await file.readAsString(); var note = noteSerializer.decode(string); - note.fileName = p.basename(entity.path); + note.filePath = p.basename(entity.path); return note; } @override Future addNote(Note note) async { - var filePath = p.join(baseDirectory, note.fileName); + var filePath = p.join(baseDirectory, note.filePath); print("FileStorage: Adding note in " + filePath); var file = File(filePath); @@ -75,7 +75,7 @@ class FileStorage implements NoteRepository { @override Future removeNote(Note note) async { - var filePath = p.join(baseDirectory, note.fileName); + var filePath = p.join(baseDirectory, note.filePath); var file = File(filePath); await file.delete(); @@ -97,7 +97,7 @@ class FileStorage implements NoteRepository { final dir = Directory(baseDirectory); for (var note in notes) { - var filePath = p.join(dir.path, note.fileName); + var filePath = p.join(dir.path, note.filePath); var file = File(filePath); var contents = noteSerializer.encode(note); diff --git a/lib/widgets/journal_list.dart b/lib/widgets/journal_list.dart index 7b46f805..09fa02ce 100644 --- a/lib/widgets/journal_list.dart +++ b/lib/widgets/journal_list.dart @@ -27,7 +27,7 @@ class JournalList extends StatelessWidget { var note = notes[i]; return Dismissible( - key: Key(note.fileName), + key: Key(note.filePath), child: _buildRow(context, note, i), background: Container(color: Theme.of(context).accentColor), onDismissed: (direction) { diff --git a/test/file_storage_test.dart b/test/file_storage_test.dart index 8628b107..29973886 100644 --- a/test/file_storage_test.dart +++ b/test/file_storage_test.dart @@ -14,8 +14,8 @@ DateTime nowWithoutMicro() { void main() { group('FileStorage', () { var notes = [ - Note(fileName: "1.md", body: "test", created: nowWithoutMicro()), - Note(fileName: "2.md", body: "test2", created: nowWithoutMicro()), + Note(filePath: "1.md", body: "test", created: nowWithoutMicro()), + Note(filePath: "2.md", body: "test2", created: nowWithoutMicro()), ]; Directory tempDir; diff --git a/test/serializers_test.dart b/test/serializers_test.dart index 42d158d0..7f008166 100644 --- a/test/serializers_test.dart +++ b/test/serializers_test.dart @@ -10,7 +10,7 @@ DateTime nowWithoutMicro() { void main() { group('Serializers', () { var note = Note( - fileName: "2", body: "This is the body", created: nowWithoutMicro()); + filePath: "2", body: "This is the body", created: nowWithoutMicro()); test('JSON Serializer', () { var serializer = JsonNoteSerializer(); @@ -26,7 +26,7 @@ void main() { var note2 = serializer.decode(str); // The YAML seriazlier loses the fileName by design - note2.fileName = note.fileName; + note2.filePath = note.filePath; expect(note2, note); });