mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-25 00:14:42 +01:00
Refactor: extract exif function
This commit is contained in:
parent
5e385097a0
commit
610bf688a0
2 changed files with 47 additions and 20 deletions
43
app/lib/entity/exif_extension.dart
Normal file
43
app/lib/entity/exif_extension.dart
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import 'package:exifdart/exifdart.dart';
|
||||||
|
import 'package:nc_photos/entity/exif.dart';
|
||||||
|
|
||||||
|
extension ExifExtension on Exif {
|
||||||
|
double? get gpsLatitudeDeg {
|
||||||
|
if (gpsLatitude == null || gpsLatitudeRef == null) {
|
||||||
|
return null;
|
||||||
|
} else if (gpsLatitudeRef != "N" && gpsLatitudeRef != "S") {
|
||||||
|
// invalid value
|
||||||
|
return null;
|
||||||
|
} else if (gpsLatitude!.any((e) => e.denominator == 0)) {
|
||||||
|
// invalid value
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return _gpsDmsToDouble(gpsLatitude!) * (gpsLatitudeRef == "S" ? -1 : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double? get gpsLongitudeDeg {
|
||||||
|
if (gpsLongitude == null || gpsLongitudeRef == null) {
|
||||||
|
return null;
|
||||||
|
} else if (gpsLongitudeRef != "E" && gpsLongitudeRef != "W") {
|
||||||
|
// invalid value
|
||||||
|
return null;
|
||||||
|
} else if (gpsLongitude!.any((e) => e.denominator == 0)) {
|
||||||
|
// invalid value
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return _gpsDmsToDouble(gpsLongitude!) * (gpsLongitudeRef == "W" ? -1 : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double _gpsDmsToDouble(List<Rational> dms) {
|
||||||
|
double product = dms[0].toDouble();
|
||||||
|
if (dms.length > 1) {
|
||||||
|
product += dms[1].toDouble() / 60;
|
||||||
|
}
|
||||||
|
if (dms.length > 2) {
|
||||||
|
product += dms[2].toDouble() / 3600;
|
||||||
|
}
|
||||||
|
return product;
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:android_intent_plus/android_intent.dart';
|
import 'package:android_intent_plus/android_intent.dart';
|
||||||
import 'package:exifdart/exifdart.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:kiwi/kiwi.dart';
|
import 'package:kiwi/kiwi.dart';
|
||||||
|
@ -15,6 +14,7 @@ import 'package:nc_photos/entity/album.dart';
|
||||||
import 'package:nc_photos/entity/album/cover_provider.dart';
|
import 'package:nc_photos/entity/album/cover_provider.dart';
|
||||||
import 'package:nc_photos/entity/album/item.dart';
|
import 'package:nc_photos/entity/album/item.dart';
|
||||||
import 'package:nc_photos/entity/album/provider.dart';
|
import 'package:nc_photos/entity/album/provider.dart';
|
||||||
|
import 'package:nc_photos/entity/exif_extension.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/notified_action.dart';
|
import 'package:nc_photos/notified_action.dart';
|
||||||
|
@ -334,14 +334,9 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
if (exif.isoSpeedRatings != null) {
|
if (exif.isoSpeedRatings != null) {
|
||||||
_isoSpeedRatings = exif.isoSpeedRatings!;
|
_isoSpeedRatings = exif.isoSpeedRatings!;
|
||||||
}
|
}
|
||||||
if (exif.gpsLatitudeRef != null &&
|
final lat = exif.gpsLatitudeDeg;
|
||||||
exif.gpsLatitude != null &&
|
final lng = exif.gpsLongitudeDeg;
|
||||||
exif.gpsLongitudeRef != null &&
|
if (lat != null && lng != null) {
|
||||||
exif.gpsLongitude != null) {
|
|
||||||
final lat = _gpsDmsToDouble(exif.gpsLatitude!) *
|
|
||||||
(exif.gpsLatitudeRef == "S" ? -1 : 1);
|
|
||||||
final lng = _gpsDmsToDouble(exif.gpsLongitude!) *
|
|
||||||
(exif.gpsLongitudeRef == "W" ? -1 : 1);
|
|
||||||
_log.fine("GPS: ($lat, $lng)");
|
_log.fine("GPS: ($lat, $lng)");
|
||||||
_gps = Tuple2(lat, lng);
|
_gps = Tuple2(lat, lng);
|
||||||
}
|
}
|
||||||
|
@ -494,17 +489,6 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static double _gpsDmsToDouble(List<Rational> dms) {
|
|
||||||
double product = dms[0].toDouble();
|
|
||||||
if (dms.length > 1) {
|
|
||||||
product += dms[1].toDouble() / 60;
|
|
||||||
}
|
|
||||||
if (dms.length > 2) {
|
|
||||||
product += dms[2].toDouble() / 3600;
|
|
||||||
}
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _checkCanRemoveFromAlbum() {
|
bool _checkCanRemoveFromAlbum() {
|
||||||
if (widget.album == null ||
|
if (widget.album == null ||
|
||||||
widget.album!.provider is! AlbumStaticProvider) {
|
widget.album!.provider is! AlbumStaticProvider) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue