Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Stop seperating files with og location and ones with not and let user choose which ones to edit/revert on. Updated dialogs shown when user edits/reverts location data

ashilkn5019ca808eba
diff --git a/lib/services/files_service.dart b/lib/services/files_service.dart
index c21d5e0f72..eb4eda36da 100644
--- a/lib/services/files_service.dart
+++ b/lib/services/files_service.dart
@@ -18,7 +18,6 @@ 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';
-import "package:photos/utils/exif_util.dart";
class FilesService {
late Dio _enteDio;
@@ -109,122 +108,108 @@ class FilesService {
final List<EnteFile> remoteFilesToUpdate = [];
final Map<int, Map<String, dynamic>> fileIDToUpdateMetadata = {};
if (location == null) {
- await _processFilesForBulkRemoveLocation(
- remoteFilesToUpdate,
- uploadedFiles,
- fileIDToUpdateMetadata,
- context,
- );
- } else {
- 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;
- }
+ final buttonResult = (await showActionSheet(
+ context: context,
+ body: "Revert to original location for all items?",
+ buttons: [
+ ButtonWidget(
+ labelText: "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,
+ ),
+ ],
+ ))!;
- remoteFilesToUpdate.add(remoteFile);
- fileIDToUpdateMetadata[remoteFile.uploadedFileID!] = {
- latKey: location.latitude,
- longKey: location.longitude,
- };
+ if (buttonResult.action == ButtonAction.cancel) {
+ return;
}
- }
+ } else {
+ final buttonResult = (await showActionSheet(
+ context: context,
+ body: "Change location of selected items?",
+ bodyHighlight: "You can revert back to the original location anytime",
+ buttons: [
+ ButtonWidget(
+ labelText: "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,
+ ),
+ ],
+ ))!;
- if (remoteFilesToUpdate.isNotEmpty) {
- await FileMagicService.instance.updatePublicMagicMetadata(
- remoteFilesToUpdate,
- null,
- metadataUpdateMap: fileIDToUpdateMetadata,
- );
+ if (buttonResult.action == ButtonAction.cancel) {
+ return;
+ }
}
}
- Future<void> _processFilesForBulkRemoveLocation(
- List<EnteFile> remoteFilesToUpdate,
+ Future<void> _editLocationData(
List<EnteFile> uploadedFiles,
Map<int, Map<String, dynamic>> fileIDToUpdateMetadata,
- BuildContext context,
+ List<EnteFile> remoteFilesToUpdate,
+ LatLng? location,
) async {
- final filesWithOgLocation = <EnteFile>[];
- final filesWithoutOgLocation = <EnteFile>[];
for (EnteFile remoteFile in uploadedFiles) {
- // discard files not owned by user and also dedupe files
+ // discard files not owned by user and also dedupe already processed
+ // files
if (remoteFile.ownerID != _config.getUserID()! ||
- filesWithoutOgLocation.any(
- (file) => file.uploadedFileID == remoteFile.uploadedFileID,
- ) ||
- filesWithOgLocation.any(
- (file) => file.uploadedFileID == remoteFile.uploadedFileID,
- )) {
+ fileIDToUpdateMetadata.containsKey(remoteFile.uploadedFileID!)) {
continue;
}
- final exif = await getExif(remoteFile);
- final locationFromExif = gpsDataFromExif(exif).toLocationObj();
- locationFromExif == null
- ? filesWithoutOgLocation.add(remoteFile)
- : filesWithOgLocation.add(remoteFile);
- }
- if (filesWithOgLocation.isEmpty && filesWithoutOgLocation.isEmpty) {
- return;
- }
- if (filesWithoutOgLocation.isEmpty) {
- remoteFilesToUpdate.addAll(filesWithOgLocation);
- } else {
- final buttons = <ButtonWidget>[
- ButtonWidget(
- labelText: "All items",
- buttonType: ButtonType.neutral,
- buttonSize: ButtonSize.large,
- shouldStickToDarkTheme: true,
- buttonAction: ButtonAction.first,
- shouldSurfaceExecutionStates: true,
- isInAlert: true,
- onTap: () async {
- remoteFilesToUpdate.addAll(
- [...filesWithOgLocation, ...filesWithoutOgLocation],
- );
- },
- ),
- ButtonWidget(
- labelText: "Items with location data",
- buttonType: ButtonType.neutral,
- buttonSize: ButtonSize.large,
- shouldStickToDarkTheme: true,
- buttonAction: ButtonAction.first,
- shouldSurfaceExecutionStates: true,
- isInAlert: true,
- onTap: () async {
- remoteFilesToUpdate.addAll(filesWithOgLocation);
- },
- ),
- ButtonWidget(
- labelText: S.of(context).cancel,
- buttonType: ButtonType.secondary,
- buttonSize: ButtonSize.large,
- shouldStickToDarkTheme: true,
- buttonAction: ButtonAction.fourth,
- isInAlert: true,
- ),
- ];
-
- await showActionSheet(
- context: context,
- buttons: buttons,
- title: "Choose items to reset",
- body: "Some items selected never had location data in the first place",
- bodyHighlight:
- "Resetting location data for such items will delete its custom location data",
- );
+ remoteFilesToUpdate.add(remoteFile);
+ fileIDToUpdateMetadata[remoteFile.uploadedFileID!] = {
+ latKey: location?.latitude,
+ longKey: location?.longitude,
+ };
}
- for (var element in remoteFilesToUpdate) {
- fileIDToUpdateMetadata[element.uploadedFileID!] = {
- latKey: null,
- longKey: null,
- };
+ if (remoteFilesToUpdate.isNotEmpty) {
+ await FileMagicService.instance.updatePublicMagicMetadata(
+ remoteFilesToUpdate,
+ null,
+ metadataUpdateMap: fileIDToUpdateMetadata,
+ );
}
}
diff --git a/lib/ui/viewer/file/file_details_widget.dart b/lib/ui/viewer/file/file_details_widget.dart
index cc27fe3007..b1a43cdbc7 100644
--- a/lib/ui/viewer/file/file_details_widget.dart
+++ b/lib/ui/viewer/file/file_details_widget.dart
@@ -162,7 +162,8 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
const FileDetailsDivider(),
],
)
- : file.fileType != FileType.video
+ : file.fileType != FileType.video &&
+ file.ownerID == _currentUserID
? Column(
children: [
InfoItemWidget(
diff --git a/lib/ui/viewer/file_details/location_tags_widget.dart b/lib/ui/viewer/file_details/location_tags_widget.dart
index 1f22121f1b..bfcb812fb3 100644
--- a/lib/ui/viewer/file_details/location_tags_widget.dart
+++ b/lib/ui/viewer/file_details/location_tags_widget.dart
@@ -2,6 +2,7 @@ import "dart:async";
import "package:flutter/material.dart";
import "package:modal_bottom_sheet/modal_bottom_sheet.dart";
+import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/location_tag_updated_event.dart";
import "package:photos/generated/l10n.dart";
@@ -61,21 +62,24 @@ class _LocationTagsWidgetState extends State<LocationTagsWidget> {
subtitleSection: locationTagChips,
hasChipButtons: hasChipButtons ?? true,
onTap: onTap,
- editOnTap: () {
- showBarModalBottomSheet(
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.vertical(
- top: Radius.circular(5),
- ),
- ),
- backgroundColor: getEnteColorScheme(context).backgroundElevated,
- barrierColor: backdropFaintDark,
- context: context,
- builder: (context) {
- return UpdateLocationDataWidget([widget.file]);
- },
- );
- },
+ editOnTap: widget.file.ownerID == Configuration.instance.getUserID()!
+ ? () {
+ showBarModalBottomSheet(
+ shape: const RoundedRectangleBorder(
+ borderRadius: BorderRadius.vertical(
+ top: Radius.circular(5),
+ ),
+ ),
+ backgroundColor:
+ getEnteColorScheme(context).backgroundElevated,
+ barrierColor: backdropFaintDark,
+ context: context,
+ builder: (context) {
+ return UpdateLocationDataWidget([widget.file]);
+ },
+ );
+ }
+ : null,
),
);
}