diff --git a/lib/core/note.dart b/lib/core/note.dart index 4ff9ed8b..228e27b9 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -3,10 +3,11 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:path/path.dart' as p; +import 'note_data.dart'; +import 'note_data_serializers.dart'; import 'note_fileName.dart'; import 'note_serializer.dart'; import 'notes_folder.dart'; -import 'serializers.dart'; enum NoteLoadState { None, diff --git a/lib/core/note_data.dart b/lib/core/note_data.dart new file mode 100644 index 00000000..22dbf99e --- /dev/null +++ b/lib/core/note_data.dart @@ -0,0 +1,34 @@ +import 'dart:collection'; + +class NoteData { + String body = ""; + LinkedHashMap props = LinkedHashMap(); + + NoteData([this.body, this.props]) { + body = body ?? ""; + // ignore: prefer_collection_literals + props = props ?? LinkedHashMap(); + } + + @override + int get hashCode => body.hashCode ^ props.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is NoteData && + runtimeType == other.runtimeType && + body == other.body && + _equalMaps(props, other.props); + + static bool _equalMaps(Map a, Map b) { + if (a.length != b.length) return false; + return a.keys + .every((dynamic key) => b.containsKey(key) && a[key] == b[key]); + } + + @override + String toString() { + return 'NoteData{body: $body, props: $props}'; + } +} diff --git a/lib/core/serializers.dart b/lib/core/note_data_serializers.dart similarity index 75% rename from lib/core/serializers.dart rename to lib/core/note_data_serializers.dart index fda99c13..16ab247e 100644 --- a/lib/core/serializers.dart +++ b/lib/core/note_data_serializers.dart @@ -4,38 +4,7 @@ import 'package:fimber/fimber.dart'; import 'package:yaml/yaml.dart'; import 'package:yaml_serializer/yaml_serializer.dart'; -class NoteData { - String body = ""; - LinkedHashMap props = LinkedHashMap(); - - NoteData([this.body, this.props]) { - body = body ?? ""; - // ignore: prefer_collection_literals - props = props ?? LinkedHashMap(); - } - - @override - int get hashCode => body.hashCode ^ props.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is NoteData && - runtimeType == other.runtimeType && - body == other.body && - _equalMaps(props, other.props); - - static bool _equalMaps(Map a, Map b) { - if (a.length != b.length) return false; - return a.keys - .every((dynamic key) => b.containsKey(key) && a[key] == b[key]); - } - - @override - String toString() { - return 'NoteData{body: $body, props: $props}'; - } -} +import 'note_data.dart'; abstract class NoteDataSerializer { String encode(NoteData note); diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index 6b180345..dbb6f299 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -1,7 +1,7 @@ import 'package:gitjournal/utils/datetime.dart'; import 'note.dart'; -import 'serializers.dart'; +import 'note_data.dart'; abstract class NoteSerializerInterface { void encode(Note note, NoteData data); diff --git a/lib/screens/journal_editor.dart b/lib/screens/journal_editor.dart index 59adb016..951c24fa 100644 --- a/lib/screens/journal_editor.dart +++ b/lib/screens/journal_editor.dart @@ -4,7 +4,8 @@ import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder.dart'; import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/widgets/journal_editor_header.dart'; -import 'package:gitjournal/core/serializers.dart'; +import 'package:gitjournal/core/note_data.dart'; +import 'package:gitjournal/core/note_data_serializers.dart'; enum NoteEditorDropDownChoices { Discard, SwitchEditor } diff --git a/test/serializers_test.dart b/test/note_data_serializers_test.dart similarity index 97% rename from test/serializers_test.dart rename to test/note_data_serializers_test.dart index b8bddd90..da6f82d7 100644 --- a/test/serializers_test.dart +++ b/test/note_data_serializers_test.dart @@ -1,6 +1,7 @@ import 'dart:collection'; -import 'package:gitjournal/core/serializers.dart'; +import 'package:gitjournal/core/note_data.dart'; +import 'package:gitjournal/core/note_data_serializers.dart'; import 'package:gitjournal/utils/datetime.dart'; import 'package:test/test.dart'; diff --git a/test/note_storage_test.dart b/test/note_storage_test.dart index 27dcea2a..ebcd3ddc 100644 --- a/test/note_storage_test.dart +++ b/test/note_storage_test.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:gitjournal/utils/datetime.dart'; import 'package:gitjournal/core/note.dart'; -import 'package:gitjournal/core/serializers.dart'; +import 'package:gitjournal/core/note_data.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart';