safer metadata retrieval
This commit is contained in:
parent
6d8a3afa9d
commit
b014041a58
5 changed files with 30 additions and 23 deletions
|
@ -176,7 +176,7 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
||||||
XMPProperty item = xmpMeta.getArrayItem(XMP_DC_SCHEMA_NS, XMP_SUBJECT_PROP_NAME, i);
|
XMPProperty item = xmpMeta.getArrayItem(XMP_DC_SCHEMA_NS, XMP_SUBJECT_PROP_NAME, i);
|
||||||
sb.append(" ").append(item.getValue());
|
sb.append(" ").append(item.getValue());
|
||||||
}
|
}
|
||||||
metadataMap.put("keywords", sb.toString());
|
metadataMap.put("xmpSubjects", sb.toString());
|
||||||
}
|
}
|
||||||
} catch (XMPException e) {
|
} catch (XMPException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -106,20 +106,20 @@ class ImageEntry {
|
||||||
|
|
||||||
class CatalogMetadata {
|
class CatalogMetadata {
|
||||||
final int contentId, dateMillis;
|
final int contentId, dateMillis;
|
||||||
final String keywords;
|
final String xmpSubjects;
|
||||||
final double latitude, longitude;
|
final double latitude, longitude;
|
||||||
Address address;
|
Address address;
|
||||||
|
|
||||||
CatalogMetadata({this.contentId, this.dateMillis, this.keywords, double latitude, double longitude})
|
CatalogMetadata({this.contentId, this.dateMillis, this.xmpSubjects, double latitude, double longitude})
|
||||||
// Geocoder throws an IllegalArgumentException when a coordinate has a funky values like 1.7056881853375E7
|
// Geocoder throws an IllegalArgumentException when a coordinate has a funky values like 1.7056881853375E7
|
||||||
: this.latitude = latitude < -90.0 || latitude > 90.0 ? null : latitude,
|
: this.latitude = latitude == null || latitude < -90.0 || latitude > 90.0 ? null : latitude,
|
||||||
this.longitude = longitude < -180.0 || longitude > 180.0 ? null : longitude;
|
this.longitude = longitude == null || longitude < -180.0 || longitude > 180.0 ? null : longitude;
|
||||||
|
|
||||||
factory CatalogMetadata.fromMap(Map map) {
|
factory CatalogMetadata.fromMap(Map map) {
|
||||||
return CatalogMetadata(
|
return CatalogMetadata(
|
||||||
contentId: map['contentId'],
|
contentId: map['contentId'],
|
||||||
dateMillis: map['dateMillis'],
|
dateMillis: map['dateMillis'],
|
||||||
keywords: map['keywords'],
|
xmpSubjects: map['xmpSubjects'],
|
||||||
latitude: map['latitude'],
|
latitude: map['latitude'],
|
||||||
longitude: map['longitude'],
|
longitude: map['longitude'],
|
||||||
);
|
);
|
||||||
|
@ -128,13 +128,13 @@ class CatalogMetadata {
|
||||||
Map<String, dynamic> toMap() => {
|
Map<String, dynamic> toMap() => {
|
||||||
'contentId': contentId,
|
'contentId': contentId,
|
||||||
'dateMillis': dateMillis,
|
'dateMillis': dateMillis,
|
||||||
'keywords': keywords,
|
'xmpSubjects': xmpSubjects,
|
||||||
'latitude': latitude,
|
'latitude': latitude,
|
||||||
'longitude': longitude,
|
'longitude': longitude,
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'CatalogMetadata{contentId: $contentId, dateMillis: $dateMillis, latitude: $latitude, longitude: $longitude, keywords=$keywords}';
|
return 'CatalogMetadata{contentId: $contentId, dateMillis: $dateMillis, latitude: $latitude, longitude: $longitude, xmpSubjects=$xmpSubjects}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class MetadataService {
|
||||||
// 'dateMillis': date taken in milliseconds since Epoch (long)
|
// 'dateMillis': date taken in milliseconds since Epoch (long)
|
||||||
// 'latitude': latitude (double)
|
// 'latitude': latitude (double)
|
||||||
// 'longitude': longitude (double)
|
// 'longitude': longitude (double)
|
||||||
// 'keywords': space separated XMP subjects (string)
|
// 'xmpSubjects': space separated XMP subjects (string)
|
||||||
final result = await platform.invokeMethod('getCatalogMetadata', <String, dynamic>{
|
final result = await platform.invokeMethod('getCatalogMetadata', <String, dynamic>{
|
||||||
'path': path,
|
'path': path,
|
||||||
}) as Map;
|
}) as Map;
|
||||||
|
|
|
@ -20,7 +20,7 @@ class MetadataDb {
|
||||||
await path,
|
await path,
|
||||||
onCreate: (db, version) {
|
onCreate: (db, version) {
|
||||||
return db.execute(
|
return db.execute(
|
||||||
'CREATE TABLE $table(contentId INTEGER PRIMARY KEY, dateMillis INTEGER, keywords TEXT, latitude REAL, longitude REAL)',
|
'CREATE TABLE $table(contentId INTEGER PRIMARY KEY, dateMillis INTEGER, xmpSubjects TEXT, latitude REAL, longitude REAL)',
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
version: 1,
|
version: 1,
|
||||||
|
|
|
@ -37,19 +37,26 @@ class InfoPageState extends State<InfoPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
initMetadataLoader() {
|
initMetadataLoader() {
|
||||||
_catalogLoader = MetadataService.getCatalogMetadata(entry.contentId, entry.path).then((metadata) async {
|
_catalogLoader = MetadataService.getCatalogMetadata(entry.contentId, entry.path);//.then(addAddressToMetadata);
|
||||||
final latitude = metadata.latitude;
|
_metadataLoader = MetadataService.getAllMetadata(entry.path);
|
||||||
final longitude = metadata.longitude;
|
}
|
||||||
if (latitude != null && longitude != null) {
|
|
||||||
final coordinates = Coordinates(latitude, longitude);
|
Future<CatalogMetadata> addAddressToMetadata(metadata) async {
|
||||||
|
if (metadata == null) return null;
|
||||||
|
final latitude = metadata.latitude;
|
||||||
|
final longitude = metadata.longitude;
|
||||||
|
if (latitude != null && longitude != null) {
|
||||||
|
final coordinates = Coordinates(latitude, longitude);
|
||||||
|
try {
|
||||||
final addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
|
final addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
|
||||||
if (addresses != null && addresses.length > 0) {
|
if (addresses != null && addresses.length > 0) {
|
||||||
metadata.address = addresses.first;
|
metadata.address = addresses.first;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$runtimeType addAddressToMetadata failed with exception=${e.message}');
|
||||||
}
|
}
|
||||||
return metadata;
|
}
|
||||||
});
|
return metadata;
|
||||||
_metadataLoader = MetadataService.getAllMetadata(entry.path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -104,8 +111,8 @@ class InfoPageState extends State<InfoPage> {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
..._buildLocationSection(metadata.latitude, metadata.longitude, metadata.address),
|
..._buildLocationSection(metadata?.latitude, metadata?.longitude, metadata?.address),
|
||||||
..._buildTagSection(metadata.keywords),
|
..._buildTagSection(metadata?.xmpSubjects),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -180,12 +187,12 @@ class InfoPageState extends State<InfoPage> {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _buildTagSection(String keywords) {
|
List<Widget> _buildTagSection(String xmpSubjects) {
|
||||||
if (keywords == null) return [];
|
if (xmpSubjects == null) return [];
|
||||||
return [
|
return [
|
||||||
SectionRow('XMP Tags'),
|
SectionRow('XMP Tags'),
|
||||||
Wrap(
|
Wrap(
|
||||||
children: keywords
|
children: xmpSubjects
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.where((word) => word.isNotEmpty)
|
.where((word) => word.isNotEmpty)
|
||||||
.map((word) => Padding(
|
.map((word) => Padding(
|
||||||
|
|
Loading…
Reference in a new issue