From 8b85afe4e1377ef9479b47a53cac4185737f5707 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:35:17 +0530 Subject: [PATCH 1/4] Handle limited or no permission --- lib/generated/intl/messages_en.dart | 5 +++ lib/generated/l10n.dart | 30 +++++++++++++ lib/l10n/intl_en.arb | 3 ++ lib/services/local_sync_service.dart | 10 +++++ lib/ui/home/preserve_footer_widget.dart | 45 +++++++++++++++++-- .../backup/backup_folder_selection_page.dart | 4 +- 6 files changed, 91 insertions(+), 6 deletions(-) diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 5fe04c9a4..6106d010f 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -687,6 +687,8 @@ class MessageLookup extends MessageLookupByLibrary { "Generating encryption keys..."), "goToSettings": MessageLookupByLibrary.simpleMessage("Go to settings"), "googlePlayId": MessageLookupByLibrary.simpleMessage("Google Play ID"), + "grantFullAccessPrompt": MessageLookupByLibrary.simpleMessage( + "Please allow access to all photos in the Settings app"), "grantPermission": MessageLookupByLibrary.simpleMessage("Grant permission"), "groupNearbyPhotos": @@ -877,6 +879,7 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Oops, could not save edits"), "oopsSomethingWentWrong": MessageLookupByLibrary.simpleMessage("Oops, something went wrong"), + "openSettings": MessageLookupByLibrary.simpleMessage("Open Settings"), "openTheItem": MessageLookupByLibrary.simpleMessage("• Open the item"), "openstreetmapContributors": MessageLookupByLibrary.simpleMessage("OpenStreetMap contributors"), @@ -1078,6 +1081,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Select items to add"), "selectLanguage": MessageLookupByLibrary.simpleMessage("Select Language"), + "selectMorePhotos": + MessageLookupByLibrary.simpleMessage("Select more photos"), "selectReason": MessageLookupByLibrary.simpleMessage("Select reason"), "selectYourPlan": MessageLookupByLibrary.simpleMessage("Select your plan"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 3a077add0..fe865c4ec 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -4455,6 +4455,36 @@ class S { ); } + /// `Please allow access to all photos in the Settings app` + String get grantFullAccessPrompt { + return Intl.message( + 'Please allow access to all photos in the Settings app', + name: 'grantFullAccessPrompt', + desc: '', + args: [], + ); + } + + /// `Open Settings` + String get openSettings { + return Intl.message( + 'Open Settings', + name: 'openSettings', + desc: '', + args: [], + ); + } + + /// `Select more photos` + String get selectMorePhotos { + return Intl.message( + 'Select more photos', + name: 'selectMorePhotos', + desc: '', + args: [], + ); + } + /// `Existing user` String get existingUser { return Intl.message( diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 4d79745c1..31d3ae77d 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -644,6 +644,9 @@ "startBackup": "Start backup", "noPhotosAreBeingBackedUpRightNow": "No photos are being backed up right now", "preserveMore": "Preserve more", + "grantFullAccessPrompt": "Please allow access to all photos in the Settings app", + "openSettings": "Open Settings", + "selectMorePhotos": "Select more photos", "existingUser": "Existing user", "privateBackups": "Private backups", "forYourMemories": "for your memories", diff --git a/lib/services/local_sync_service.dart b/lib/services/local_sync_service.dart index 972d66347..2f5a58eaf 100644 --- a/lib/services/local_sync_service.dart +++ b/lib/services/local_sync_service.dart @@ -241,6 +241,16 @@ class LocalSyncService { PermissionState.limited.toString(); } + bool hasGrantedFullPermission() { + return (_prefs.getString(kPermissionStateKey) ?? '') == + PermissionState.authorized.toString(); + } + + Future onUpdatePermission(PermissionState state) async { + await _prefs.setBool(kHasGrantedPermissionsKey, true); + await _prefs.setString(kPermissionStateKey, state.toString()); + } + Future onPermissionGranted(PermissionState state) async { await _prefs.setBool(kHasGrantedPermissionsKey, true); await _prefs.setString(kPermissionStateKey, state.toString()); diff --git a/lib/ui/home/preserve_footer_widget.dart b/lib/ui/home/preserve_footer_widget.dart index 0405094ac..c2367a2d2 100644 --- a/lib/ui/home/preserve_footer_widget.dart +++ b/lib/ui/home/preserve_footer_widget.dart @@ -1,11 +1,16 @@ import 'dart:async'; +import "dart:io"; import 'package:flutter/material.dart'; +import "package:flutter/services.dart"; +import "package:logging/logging.dart"; import 'package:photo_manager/photo_manager.dart'; +import "package:photos/core/configuration.dart"; import "package:photos/generated/l10n.dart"; import 'package:photos/services/local_sync_service.dart'; import 'package:photos/ui/common/gradient_button.dart'; import 'package:photos/ui/settings/backup/backup_folder_selection_page.dart'; +import "package:photos/utils/dialog_util.dart"; import 'package:photos/utils/navigation_util.dart'; class PreserveFooterWidget extends StatelessWidget { @@ -17,14 +22,46 @@ class PreserveFooterWidget extends StatelessWidget { padding: const EdgeInsets.fromLTRB(20, 24, 20, 100), child: GradientButton( onTap: () async { - if (LocalSyncService.instance.hasGrantedLimitedPermissions()) { - await PhotoManager.presentLimited(); + try { + final PermissionState state = + await PhotoManager.requestPermissionExtend(); + await LocalSyncService.instance.onUpdatePermission(state); + } on Exception catch (e) { + Logger("PreserveFooterWidget").severe( + "Failed to request permission: ${e.toString()}", + e, + ); + } + if (!LocalSyncService.instance.hasGrantedFullPermission()) { + if (Platform.isAndroid) { + await PhotoManager.openSetting(); + } else { + final bool hasGrantedLimit = + LocalSyncService.instance.hasGrantedLimitedPermissions(); + showChoiceActionSheet( + context, + title: S.of(context).preserveMore, + body: S.of(context).grantFullAccessPrompt, + firstButtonLabel: S.of(context).openSettings, + firstButtonOnTap: () async { + await PhotoManager.openSetting(); + }, + secondButtonLabel: hasGrantedLimit + ? S.of(context).selectMorePhotos + : S.of(context).cancel, + secondButtonOnTap: () async { + if (hasGrantedLimit) { + await PhotoManager.presentLimited(); + } + }, + ); + } } else { unawaited( routeToPage( context, - const BackupFolderSelectionPage( - buttonText: "Preserve", + BackupFolderSelectionPage( + buttonText: S.of(context).backup, ), ), ); diff --git a/lib/ui/settings/backup/backup_folder_selection_page.dart b/lib/ui/settings/backup/backup_folder_selection_page.dart index 457975937..8e4353753 100644 --- a/lib/ui/settings/backup/backup_folder_selection_page.dart +++ b/lib/ui/settings/backup/backup_folder_selection_page.dart @@ -78,14 +78,14 @@ class _BackupFolderSelectionPageState extends State { title: const Text(""), ), body: Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, children: [ const SizedBox( height: 0, ), SafeArea( child: Container( - padding: const EdgeInsets.fromLTRB(24, 32, 24, 8), + padding: const EdgeInsets.fromLTRB(24, 8, 24, 8), child: Text( S.of(context).selectFoldersForBackup, textAlign: TextAlign.left, From 55284af40144c466b8454efc80f483294898616b Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:45:42 +0530 Subject: [PATCH 2/4] bump version: 0.7.86+486 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0509823be..f28235336 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ description: ente photos application # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.7.84+484 +version: 0.7.86+486 environment: sdk: ">=3.0.0 <4.0.0" From 81e70a5aa7592eaec79aae656d68989a4373c9cb Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:01:54 +0530 Subject: [PATCH 3/4] Hide archive for unuploaded files --- lib/ui/viewer/file/file_app_bar.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/viewer/file/file_app_bar.dart b/lib/ui/viewer/file/file_app_bar.dart index d9fba515e..4476122a4 100644 --- a/lib/ui/viewer/file/file_app_bar.dart +++ b/lib/ui/viewer/file/file_app_bar.dart @@ -142,7 +142,7 @@ class FileAppBarState extends State { ); } // options for files owned by the user - if (isOwnedByUser && !isFileHidden) { + if (isOwnedByUser && !isFileHidden && isFileUploaded) { final bool isArchived = widget.file.magicMetadata.visibility == archiveVisibility; items.add( From 3379b4c237cbd1cfd587568cfc6d365d0bfa65b7 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:10:28 +0530 Subject: [PATCH 4/4] bump version: 0.7.87+487 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index f28235336..30b5ed13f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ description: ente photos application # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.7.86+486 +version: 0.7.87+487 environment: sdk: ">=3.0.0 <4.0.0"