Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Add/Edit location data feature (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashilkn authored Dec 18, 2023
2 parents b882cb4 + 37777b6 commit 195f84b
Show file tree
Hide file tree
Showing 26 changed files with 645 additions and 34 deletions.
50 changes: 50 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/l10n/intl_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1158,5 +1158,10 @@
"signOutFromOtherDevices": "Von anderen Geräten abmelden",
"signOutOtherBody": "Falls du denkst, dass jemand dein Passwort kennen könnte, kannst du alle anderen Geräte von deinem Account abmelden.",
"signOutOtherDevices": "Andere Geräte abmelden",
"doNotSignOut": "Melde dich nicht ab"
"doNotSignOut": "Melde dich nicht ab",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
10 changes: 7 additions & 3 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,8 @@
"itLooksLikeSomethingWentWrongPleaseRetryAfterSome": "It looks like something went wrong. Please retry after some time. If the error persists, please contact our support team.",
"error": "Error",
"tempErrorContactSupportIfPersists": "It looks like something went wrong. Please retry after some time. If the error persists, please contact our support team.",
"networkHostLookUpErr" : "Unable to connect to Ente, please check your network settings and contact support if the error persists.",
"networkConnectionRefusedErr" : "Unable to connect to Ente, please retry after sometime. If the error persists, please contact support.",
"networkHostLookUpErr": "Unable to connect to Ente, please check your network settings and contact support if the error persists.",
"networkConnectionRefusedErr": "Unable to connect to Ente, please retry after sometime. If the error persists, please contact support.",
"cachedData": "Cached data",
"clearCaches": "Clear caches",
"remoteImages": "Remote images",
Expand Down Expand Up @@ -1170,10 +1170,14 @@
"contacts": "Contacts",
"noInternetConnection": "No internet connection",
"pleaseCheckYourInternetConnectionAndTryAgain": "Please check your internet connection and try again.",

"signOutFromOtherDevices": "Sign out from other devices",
"signOutOtherBody": "If you think someone might know your password, you can force all other devices using your account to sign out.",
"signOutOtherDevices": "Sign out other devices",
"doNotSignOut": "Do not sign out",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente",
"cleanUncategorized": "Clean Uncategorized"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -968,5 +968,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1149,5 +1149,10 @@
"@addNew": {
"description": "Text to add a new item (location tag, album, caption etc)"
},
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1111,5 +1111,10 @@
"addOnPageSubtitle": "Dettagli dei componenti aggiuntivi",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_ko.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1158,5 +1158,10 @@
"signOutFromOtherDevices": "Log uit op andere apparaten",
"signOutOtherBody": "Als je denkt dat iemand je wachtwoord zou kunnen kennen, kun je alle andere apparaten die je account gebruiken dwingen om uit te loggen.",
"signOutOtherDevices": "Log uit op andere apparaten",
"doNotSignOut": "Niet uitloggen"
"doNotSignOut": "Niet uitloggen",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_no.arb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
7 changes: 6 additions & 1 deletion lib/l10n/intl_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,10 @@
"deleteConfirmDialogBody": "This account is linked to other ente apps, if you use any.\\n\\nYour uploaded data, across all ente apps, will be scheduled for deletion, and your account will be permanently deleted.",
"yourMap": "Your map",
"modifyYourQueryOrTrySearchingFor": "Modify your query, or try searching for",
"contacts": "Contacts"
"contacts": "Contacts",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente"
}
5 changes: 5 additions & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1173,5 +1173,10 @@
"signOutOtherBody": "如果你认为有人可能知道你的密码,你可以强制所有使用你账户的其他设备退出登录。",
"signOutOtherDevices": "登出其他设备",
"doNotSignOut": "不要退登",
"editLocation": "Edit location",
"selectALocation": "Select a location",
"selectALocationFirst": "Select a location first",
"changeLocationOfSelectedItems": "Change location of selected items?",
"editsToLocationWillOnlyBeSeenWithinEnte": "Edits to location will only be seen within Ente",
"cleanUncategorized": "清除未分类的"
}
2 changes: 2 additions & 0 deletions lib/models/file/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:photos/utils/date_time_util.dart';
import 'package:photos/utils/exif_util.dart';
import 'package:photos/utils/file_uploader_util.dart';

//Todo: files with no location data have lat and long set to 0.0. This should ideally be null.
class EnteFile {
int? generatedID;
int? uploadedFileID;
Expand Down Expand Up @@ -271,6 +272,7 @@ class EnteFile {
int get width {
return pubMagicMetadata?.w ?? 0;
}

bool get hasDimensions {
return height != 0 && width != 0;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/models/gallery_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ extension GalleyTypeExtension on GalleryType {
bool showRemoveFromHiddenAlbum() {
return this == GalleryType.hiddenOwnedCollection;
}

bool showEditLocation() {
return this != GalleryType.sharedCollection;
}
}

extension GalleryAppBarExtn on GalleryType {
Expand Down
79 changes: 79 additions & 0 deletions lib/services/files_service.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import 'package:dio/dio.dart';
import "package:flutter/material.dart";
import "package:latlong2/latlong.dart";
import 'package:logging/logging.dart';
import 'package:path/path.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/network/network.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/extensions/list.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file_load_result.dart";
import "package:photos/models/metadata/file_magic.dart";
import 'package:photos/services/file_magic_service.dart';
import "package:photos/services/ignored_files_service.dart";
import "package:photos/ui/components/action_sheet_widget.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import 'package:photos/utils/date_time_util.dart';

class FilesService {
Expand Down Expand Up @@ -85,6 +91,79 @@ class FilesService {
}
}

Future<void> bulkEditLocationData(
List<EnteFile> files,
LatLng location,
BuildContext context,
) async {
final List<EnteFile> uploadedFiles =
files.where((element) => element.uploadedFileID != null).toList();

final List<EnteFile> remoteFilesToUpdate = [];
final Map<int, Map<String, dynamic>> fileIDToUpdateMetadata = {};
await showActionSheet(
context: context,
body: S.of(context).changeLocationOfSelectedItems,
buttons: [
ButtonWidget(
labelText: S.of(context).yes,
buttonType: ButtonType.neutral,
buttonSize: ButtonSize.large,
shouldStickToDarkTheme: true,
buttonAction: ButtonAction.first,
shouldSurfaceExecutionStates: true,
isInAlert: true,
onTap: () async {
await _editLocationData(
uploadedFiles,
fileIDToUpdateMetadata,
remoteFilesToUpdate,
location,
);
},
),
ButtonWidget(
labelText: S.of(context).cancel,
buttonType: ButtonType.secondary,
buttonSize: ButtonSize.large,
shouldStickToDarkTheme: true,
buttonAction: ButtonAction.cancel,
isInAlert: true,
),
],
);
}

Future<void> _editLocationData(
List<EnteFile> uploadedFiles,
Map<int, Map<String, dynamic>> fileIDToUpdateMetadata,
List<EnteFile> remoteFilesToUpdate,
LatLng location,
) async {
for (EnteFile remoteFile in uploadedFiles) {
// discard files not owned by user and also dedupe already processed
// files
if (remoteFile.ownerID != _config.getUserID()! ||
fileIDToUpdateMetadata.containsKey(remoteFile.uploadedFileID!)) {
continue;
}

remoteFilesToUpdate.add(remoteFile);
fileIDToUpdateMetadata[remoteFile.uploadedFileID!] = {
latKey: location.latitude,
longKey: location.longitude,
};
}

if (remoteFilesToUpdate.isNotEmpty) {
await FileMagicService.instance.updatePublicMagicMetadata(
remoteFilesToUpdate,
null,
metadataUpdateMap: fileIDToUpdateMetadata,
);
}
}

// Note: this method is not used anywhere, but it is kept for future
// reference when we add bulk EditTime feature
Future<void> bulkEditTime(
Expand Down
18 changes: 13 additions & 5 deletions lib/services/location_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,25 @@ class LocationService {
return false;
}

String convertLocationToDMS(Location centerPoint) {
/// returns [lat, lng]
List<String>? convertLocationToDMS(Location centerPoint) {
if (centerPoint.latitude == null || centerPoint.longitude == null) {
return null;
}
final lat = centerPoint.latitude!;
final long = centerPoint.longitude!;
final latRef = lat >= 0 ? "N" : "S";
final longRef = long >= 0 ? "E" : "W";
final latDMS = convertCoordinateToDMS(lat.abs());
final longDMS = convertCoordinateToDMS(long.abs());
return "${latDMS[0]}°${latDMS[1]}'${latDMS[2]}\"$latRef, ${longDMS[0]}°${longDMS[1]}'${longDMS[2]}\"$longRef";
final latDMS = _convertCoordinateToDMS(lat.abs());
final longDMS = _convertCoordinateToDMS(long.abs());

return [
"${latDMS[0]}°${latDMS[1]}'${latDMS[2]}\" $latRef",
"${longDMS[0]}°${longDMS[1]}'${longDMS[2]}\" $longRef",
];
}

List<int> convertCoordinateToDMS(double coordinate) {
List<int> _convertCoordinateToDMS(double coordinate) {
final degrees = coordinate.floor();
final minutes = ((coordinate - degrees) * 60).floor();
final seconds = ((coordinate - degrees - minutes / 60) * 3600).floor();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _MapScreenState extends State<MapScreen> {
double maxZoom = 18.0;
double minZoom = 2.8;
int debounceDuration = 500;
LatLng center = LatLng(46.7286, 4.8614);
LatLng center = const LatLng(46.7286, 4.8614);
final Logger _logger = Logger("_MapScreenState");
StreamSubscription? _mapMoveSubscription;
Isolate? isolate;
Expand Down
Loading

0 comments on commit 195f84b

Please sign in to comment.