diff options
Diffstat (limited to 'lib/model/metadata')
| -rw-r--r-- | lib/model/metadata/address.dart | 56 | ||||
| -rw-r--r-- | lib/model/metadata/catalog.dart | 126 | ||||
| -rw-r--r-- | lib/model/metadata/date_modifier.dart | 51 | ||||
| -rw-r--r-- | lib/model/metadata/overlay.dart | 32 | ||||
| -rw-r--r-- | lib/model/metadata/trash.dart | 42 |
5 files changed, 307 insertions, 0 deletions
diff --git a/lib/model/metadata/address.dart b/lib/model/metadata/address.dart new file mode 100644 index 0000000..2680799 --- /dev/null +++ b/lib/model/metadata/address.dart @@ -0,0 +1,56 @@ +import 'package:aves/geo/states.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter/foundation.dart'; + +@immutable +class AddressDetails extends Equatable { + final int id; + final String? countryCode, countryName, adminArea, locality; + + @override + List<Object?> get props => [id, countryCode, countryName, adminArea, locality]; + + String? get place => locality != null && locality!.isNotEmpty ? locality : adminArea; + + String? get stateCode => GeoStates.stateCodeByName[stateName]; + + String? get stateName => GeoStates.stateCountryCodes.contains(countryCode) ? adminArea : null; + + const AddressDetails({ + required this.id, + this.countryCode, + this.countryName, + this.adminArea, + this.locality, + }); + + AddressDetails copyWith({ + int? id, + }) { + return AddressDetails( + id: id ?? this.id, + countryCode: countryCode, + countryName: countryName, + adminArea: adminArea, + locality: locality, + ); + } + + factory AddressDetails.fromMap(Map map) { + return AddressDetails( + id: map['id'] as int, + countryCode: map['countryCode'] as String?, + countryName: map['countryName'] as String?, + adminArea: map['adminArea'] as String?, + locality: map['locality'] as String?, + ); + } + + Map<String, dynamic> toMap() => { + 'id': id, + 'countryCode': countryCode, + 'countryName': countryName, + 'adminArea': adminArea, + 'locality': locality, + }; +} diff --git a/lib/model/metadata/catalog.dart b/lib/model/metadata/catalog.dart new file mode 100644 index 0000000..2c668d3 --- /dev/null +++ b/lib/model/metadata/catalog.dart @@ -0,0 +1,126 @@ +import 'package:aves/services/geocoding_service.dart'; +import 'package:flutter/foundation.dart'; + +class CatalogMetadata { + final int id; + final int? dateMillis; + final bool isAnimated, isGeotiff, is360, isMultiPage, isMotionPhoto, isHdr; + bool isFlipped; + int? rotationDegrees; + final String? mimeType, xmpSubjects, xmpTitle; + double? latitude, longitude; + Address? address; + int rating; + + // less lenient than Flutter's `precisionErrorTolerance` (1e-10) + static const double _precisionErrorTolerance = 1e-9; + + static const _isAnimatedMask = 1 << 0; + static const _isFlippedMask = 1 << 1; + static const _isGeotiffMask = 1 << 2; + static const _is360Mask = 1 << 3; + static const _isMultiPageMask = 1 << 4; + static const _isMotionPhotoMask = 1 << 5; + static const _isHdr = 1 << 6; // for images: embedded HDR gainmap, for videos: HDR color transfer + + CatalogMetadata({ + required this.id, + this.mimeType, + this.dateMillis, + this.isAnimated = false, + this.isFlipped = false, + this.isGeotiff = false, + this.is360 = false, + this.isMultiPage = false, + this.isMotionPhoto = false, + this.isHdr = false, + this.rotationDegrees, + this.xmpSubjects, + this.xmpTitle, + double? latitude, + double? longitude, + this.rating = 0, + }) { + // Geocoder throws an `IllegalArgumentException` when a coordinate has a funky value like `1.7056881853375E7` + // We also exclude zero coordinates, taking into account precision errors (e.g. {5.952380952380953e-11,-2.7777777777777777e-10}), + // but Flutter's `precisionErrorTolerance` (1e-10) is slightly too lenient for this case. + if (latitude != null && longitude != null && (latitude.abs() > _precisionErrorTolerance || longitude.abs() > _precisionErrorTolerance)) { + // funny case: some files have latitude and longitude reverse + // (e.g. a Japanese location at lat~=133 and long~=34, which is a valid longitude but an invalid latitude) + // so we should check and assign both coordinates at once + if (latitude >= -90.0 && latitude <= 90.0 && longitude >= -180.0 && longitude <= 180.0) { + this.latitude = latitude; + this.longitude = longitude; + } + } + } + + CatalogMetadata copyWith({ + int? id, + String? mimeType, + int? dateMillis, + bool? isAnimated, + bool? isMultiPage, + int? rotationDegrees, + double? latitude, + double? longitude, + }) { + return CatalogMetadata( + id: id ?? this.id, + mimeType: mimeType ?? this.mimeType, + dateMillis: dateMillis ?? this.dateMillis, + isAnimated: isAnimated ?? this.isAnimated, + isFlipped: isFlipped, + isGeotiff: isGeotiff, + is360: is360, + isMultiPage: isMultiPage ?? this.isMultiPage, + isMotionPhoto: isMotionPhoto, + isHdr: isHdr, + rotationDegrees: rotationDegrees ?? this.rotationDegrees, + xmpSubjects: xmpSubjects, + xmpTitle: xmpTitle, + latitude: latitude ?? this.latitude, + longitude: longitude ?? this.longitude, + rating: rating, + ); + } + + factory CatalogMetadata.fromMap(Map map) { + final flags = map['flags'] ?? 0; + return CatalogMetadata( + id: map['id'], + mimeType: map['mimeType'], + dateMillis: map['dateMillis'] ?? 0, + isAnimated: flags & _isAnimatedMask != 0, + isFlipped: flags & _isFlippedMask != 0, + isGeotiff: flags & _isGeotiffMask != 0, + is360: flags & _is360Mask != 0, + isMultiPage: flags & _isMultiPageMask != 0, + isMotionPhoto: flags & _isMotionPhotoMask != 0, + isHdr: flags & _isHdr != 0, + // `rotationDegrees` should default to `sourceRotationDegrees`, not 0 + rotationDegrees: map['rotationDegrees'], + xmpSubjects: map['xmpSubjects'] ?? '', + xmpTitle: map['xmpTitle'] ?? '', + latitude: map['latitude'], + longitude: map['longitude'], + rating: map['rating'] ?? 0, + ); + } + + Map<String, dynamic> toMap() => { + 'id': id, + 'mimeType': mimeType, + 'dateMillis': dateMillis, + 'flags': (isAnimated ? _isAnimatedMask : 0) | (isFlipped ? _isFlippedMask : 0) | (isGeotiff ? _isGeotiffMask : 0) | (is360 ? _is360Mask : 0) | (isMultiPage ? _isMultiPageMask : 0) | (isMotionPhoto ? _isMotionPhotoMask : 0) | (isHdr ? _isHdr : 0), + 'rotationDegrees': rotationDegrees, + 'xmpSubjects': xmpSubjects, + 'xmpTitle': xmpTitle, + 'latitude': latitude, + 'longitude': longitude, + 'rating': rating, + }; + + @override + String toString() => '$runtimeType#${shortHash(this)}{id=$id, mimeType=$mimeType, dateMillis=$dateMillis, isAnimated=$isAnimated, isFlipped=$isFlipped, isGeotiff=$isGeotiff, is360=$is360, isMultiPage=$isMultiPage, isMotionPhoto=$isMotionPhoto, rotationDegrees=$rotationDegrees, xmpSubjects=$xmpSubjects, xmpTitle=$xmpTitle, latitude=$latitude, longitude=$longitude, rating=$rating}'; +} diff --git a/lib/model/metadata/date_modifier.dart b/lib/model/metadata/date_modifier.dart new file mode 100644 index 0000000..b34a86e --- /dev/null +++ b/lib/model/metadata/date_modifier.dart @@ -0,0 +1,51 @@ +import 'package:aves_model/aves_model.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter/foundation.dart'; + +@immutable +class DateModifier extends Equatable { + static const writableFields = [ + MetadataField.exifDate, + MetadataField.exifDateOriginal, + MetadataField.exifDateDigitized, + MetadataField.exifGpsDatestamp, + MetadataField.xmpXmpCreateDate, + ]; + + final DateEditAction action; + final Set<MetadataField> fields; + final DateTime? setDateTime; + final DateFieldSource? copyFieldSource; + final int? shiftSeconds; + + @override + List<Object?> get props => [action, fields, setDateTime, copyFieldSource, shiftSeconds]; + + const DateModifier._private( + this.action, { + this.fields = const {}, + this.setDateTime, + this.copyFieldSource, + this.shiftSeconds, + }); + + factory DateModifier.setCustom(Set<MetadataField> fields, DateTime dateTime) { + return DateModifier._private(DateEditAction.setCustom, fields: fields, setDateTime: dateTime); + } + + factory DateModifier.copyField(DateFieldSource copyFieldSource) { + return DateModifier._private(DateEditAction.copyField, copyFieldSource: copyFieldSource); + } + + factory DateModifier.extractFromTitle() { + return const DateModifier._private(DateEditAction.extractFromTitle); + } + + factory DateModifier.shift(Set<MetadataField> fields, int shiftSeconds) { + return DateModifier._private(DateEditAction.shift, fields: fields, shiftSeconds: shiftSeconds); + } + + factory DateModifier.remove(Set<MetadataField> fields) { + return DateModifier._private(DateEditAction.remove, fields: fields); + } +} diff --git a/lib/model/metadata/overlay.dart b/lib/model/metadata/overlay.dart new file mode 100644 index 0000000..55e145f --- /dev/null +++ b/lib/model/metadata/overlay.dart @@ -0,0 +1,32 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter/foundation.dart'; + +@immutable +class OverlayMetadata extends Equatable { + final double? aperture, focalLength; + final String? description, exposureTime; + final int? iso; + + @override + List<Object?> get props => [aperture, description, exposureTime, focalLength, iso]; + + bool get hasShootingDetails => aperture != null || exposureTime != null || focalLength != null || iso != null; + + const OverlayMetadata({ + this.aperture, + this.description, + this.exposureTime, + this.focalLength, + this.iso, + }); + + factory OverlayMetadata.fromMap(Map map) { + return OverlayMetadata( + aperture: map['aperture'] as double?, + description: map['description'] as String?, + exposureTime: map['exposureTime'] as String?, + focalLength: map['focalLength'] as double?, + iso: map['iso'] as int?, + ); + } +} diff --git a/lib/model/metadata/trash.dart b/lib/model/metadata/trash.dart new file mode 100644 index 0000000..260661d --- /dev/null +++ b/lib/model/metadata/trash.dart @@ -0,0 +1,42 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter/foundation.dart'; + +@immutable +class TrashDetails extends Equatable { + final int id; + final String path; + final int dateMillis; + + @override + List<Object?> get props => [id, path, dateMillis]; + + const TrashDetails({ + required this.id, + required this.path, + required this.dateMillis, + }); + + TrashDetails copyWith({ + int? id, + }) { + return TrashDetails( + id: id ?? this.id, + path: path, + dateMillis: dateMillis, + ); + } + + factory TrashDetails.fromMap(Map map) { + return TrashDetails( + id: map['id'] as int, + path: map['path'] as String, + dateMillis: map['dateMillis'] as int, + ); + } + + Map<String, dynamic> toMap() => { + 'id': id, + 'path': path, + 'dateMillis': dateMillis, + }; +} |
