diff --git a/lib/model/filters/album.dart b/lib/model/filters/album.dart index f729f2329..77e0e5c11 100644 --- a/lib/model/filters/album.dart +++ b/lib/model/filters/album.dart @@ -18,14 +18,14 @@ class AlbumFilter extends CollectionFilter { const AlbumFilter(this.album, this.uniqueName); - AlbumFilter.fromJson(Map json) + AlbumFilter.fromMap(Map json) : this( json['album'], json['uniqueName'], ); @override - Map toJson() => { + Map toMap() => { 'type': type, 'album': album, 'uniqueName': uniqueName, diff --git a/lib/model/filters/favourite.dart b/lib/model/filters/favourite.dart index fbf1194de..a5ba2998c 100644 --- a/lib/model/filters/favourite.dart +++ b/lib/model/filters/favourite.dart @@ -8,7 +8,7 @@ class FavouriteFilter extends CollectionFilter { static const type = 'favourite'; @override - Map toJson() => { + Map toMap() => { 'type': type, }; diff --git a/lib/model/filters/filters.dart b/lib/model/filters/filters.dart index ab519743c..d1f8efe86 100644 --- a/lib/model/filters/filters.dart +++ b/lib/model/filters/filters.dart @@ -27,17 +27,17 @@ abstract class CollectionFilter implements Comparable { final type = jsonMap['type']; switch (type) { case AlbumFilter.type: - return AlbumFilter.fromJson(jsonMap); + return AlbumFilter.fromMap(jsonMap); case FavouriteFilter.type: return FavouriteFilter(); case LocationFilter.type: - return LocationFilter.fromJson(jsonMap); + return LocationFilter.fromMap(jsonMap); case MimeFilter.type: - return MimeFilter.fromJson(jsonMap); + return MimeFilter.fromMap(jsonMap); case QueryFilter.type: - return QueryFilter.fromJson(jsonMap); + return QueryFilter.fromMap(jsonMap); case TagFilter.type: - return TagFilter.fromJson(jsonMap); + return TagFilter.fromMap(jsonMap); } debugPrint('failed to parse filter from json=$jsonString'); return null; @@ -45,7 +45,9 @@ abstract class CollectionFilter implements Comparable { const CollectionFilter(); - Map toJson(); + Map toMap(); + + String toJson() => jsonEncode(toMap()); bool filter(ImageEntry entry); diff --git a/lib/model/filters/location.dart b/lib/model/filters/location.dart index 9f31a8e2f..02c5f7b81 100644 --- a/lib/model/filters/location.dart +++ b/lib/model/filters/location.dart @@ -17,14 +17,14 @@ class LocationFilter extends CollectionFilter { if (split.length > 1) _countryCode = split[1]; } - LocationFilter.fromJson(Map json) + LocationFilter.fromMap(Map json) : this( LocationLevel.values.firstWhere((v) => v.toString() == json['level'], orElse: () => null), json['location'], ); @override - Map toJson() => { + Map toMap() => { 'type': type, 'level': level.toString(), 'location': _countryCode != null ? '$_location$locationSeparator$_countryCode' : _location, diff --git a/lib/model/filters/mime.dart b/lib/model/filters/mime.dart index 54b6beb0a..fdc948cca 100644 --- a/lib/model/filters/mime.dart +++ b/lib/model/filters/mime.dart @@ -38,13 +38,13 @@ class MimeFilter extends CollectionFilter { _icon ??= AIcons.vector; } - MimeFilter.fromJson(Map json) + MimeFilter.fromMap(Map json) : this( json['mime'], ); @override - Map toJson() => { + Map toMap() => { 'type': type, 'mime': mime, }; diff --git a/lib/model/filters/query.dart b/lib/model/filters/query.dart index 9714adc2b..5d89a5ca7 100644 --- a/lib/model/filters/query.dart +++ b/lib/model/filters/query.dart @@ -32,13 +32,13 @@ class QueryFilter extends CollectionFilter { _filter = not ? (entry) => !entry.search(upQuery) : (entry) => entry.search(upQuery); } - QueryFilter.fromJson(Map json) + QueryFilter.fromMap(Map json) : this( json['query'], ); @override - Map toJson() => { + Map toMap() => { 'type': type, 'query': query, }; diff --git a/lib/model/filters/tag.dart b/lib/model/filters/tag.dart index 83c0d5ef1..4f7cd3e23 100644 --- a/lib/model/filters/tag.dart +++ b/lib/model/filters/tag.dart @@ -10,13 +10,13 @@ class TagFilter extends CollectionFilter { const TagFilter(this.tag); - TagFilter.fromJson(Map json) + TagFilter.fromMap(Map json) : this( json['tag'], ); @override - Map toJson() => { + Map toMap() => { 'type': type, 'tag': tag, }; diff --git a/lib/services/app_shortcut_service.dart b/lib/services/app_shortcut_service.dart index 9008776f3..5d4c244b7 100644 --- a/lib/services/app_shortcut_service.dart +++ b/lib/services/app_shortcut_service.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:aves/model/filters/filters.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -28,7 +26,7 @@ class AppShortcutService { try { await platform.invokeMethod('pin', { 'label': label, - 'filters': filters.map((filter) => jsonEncode(filter.toJson())).toList(), + 'filters': filters.map((filter) => filter.toJson()).toList(), }); } on PlatformException catch (e) { debugPrint('pin failed with code=${e.code}, exception=${e.message}, details=${e.details}'); diff --git a/test/model/filters_test.dart b/test/model/filters_test.dart index 7ebf5fe35..28bf84b9f 100644 --- a/test/model/filters_test.dart +++ b/test/model/filters_test.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:aves/model/filters/album.dart'; import 'package:aves/model/filters/favourite.dart'; import 'package:aves/model/filters/filters.dart'; @@ -12,7 +10,7 @@ import 'package:test/test.dart'; void main() { test('Filter serialization', () { - CollectionFilter jsonRoundTrip(filter) => CollectionFilter.fromJson(jsonEncode(filter.toJson())); + CollectionFilter jsonRoundTrip(filter) => CollectionFilter.fromJson(filter.toJson()); final album = AlbumFilter('path/to/album', 'album'); expect(album, jsonRoundTrip(album));