From 4540f54d59cddc8e6e82f367937dbfc2b01cab86 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Mon, 4 Sep 2023 07:48:58 +0530 Subject: [PATCH] Fix document picker trigger bug (#5275) * Revert "Revert a1b6973 until we find out why it uses OPEN_DOCUMENT by default on fresh install" This reverts commit 7ce3b7ebb1c5ec127cd7de0a83d64af17ff1b200. * Potential fix for get_content picker being used in first run The initial state of the 'openDocumentPhotoPickerPref' seems to be incorrect during a fresh install on some devices. Try to ensure we always use the proper initial state by propagating the default to the preference access code. This hopefully fixes #5274 --- .../contributions/ContributionController.java | 4 +-- .../nrw/commons/filepicker/FilePicker.java | 25 ++++++++++--------- .../commons/settings/SettingsFragment.java | 6 ++--- app/src/main/res/values/strings.xml | 4 +-- app/src/main/res/xml/preferences.xml | 12 +++++---- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java index b44484b8d..755766fd4 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java @@ -171,8 +171,8 @@ public class ContributionController { */ private void initiateGalleryUpload(final Activity activity, final boolean allowMultipleUploads) { setPickerConfiguration(activity, allowMultipleUploads); - boolean isGetContentPickerPreferred = defaultKvStore.getBoolean("getContentPhotoPickerPref"); - FilePicker.openGallery(activity, 0, isGetContentPickerPreferred); + boolean openDocumentIntentPreferred = defaultKvStore.getBoolean("openDocumentPhotoPickerPref", true); + FilePicker.openGallery(activity, 0, openDocumentIntentPreferred); } /** diff --git a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java index f05f6a7e7..31ea06e0d 100644 --- a/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java +++ b/app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java @@ -47,10 +47,10 @@ public class FilePicker implements Constants { } private static Intent createGalleryIntent(@NonNull Context context, int type, - boolean isGetContentPickerPreferred) { + boolean openDocumentIntentPreferred) { // storing picked image type to shared preferences storeType(context, type); - return plainGalleryPickerIntent(isGetContentPickerPreferred) + return plainGalleryPickerIntent(openDocumentIntentPreferred) .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery()); } @@ -106,8 +106,8 @@ public class FilePicker implements Constants { * * @param type Custom type of your choice, which will be returned with the images */ - public static void openGallery(Activity activity, int type, boolean isGetContentPickerPreferred) { - Intent intent = createGalleryIntent(activity, type, isGetContentPickerPreferred); + public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) { + Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred); activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY); } @@ -201,8 +201,8 @@ public class FilePicker implements Constants { return data == null || (data.getData() == null && data.getClipData() == null); } - private static Intent plainGalleryPickerIntent(boolean isGetContentPickerPreferred) { - /** + private static Intent plainGalleryPickerIntent(boolean openDocumentIntentPreferred) { + /* * Asking for ACCESS_MEDIA_LOCATION at runtime solved the location-loss issue * in the custom selector in Contributions fragment. * Detailed discussion: https://github.com/commons-app/apps-android-commons/issues/5015 @@ -217,8 +217,8 @@ public class FilePicker implements Constants { * Reported on the Google Issue Tracker: https://issuetracker.google.com/issues/243294058 * Status: Won't fix (Intended behaviour) * - * Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT - * (based on user's preference) as: + * Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT (by default; can + * be changed through the Setting page) as: * * ACTION_GET_CONTENT opens the 'best application' for choosing that kind of data * The best application is the new Photo Picker that redacts the location tags @@ -226,14 +226,15 @@ public class FilePicker implements Constants { * ACTION_OPEN_DOCUMENT, however, displays the various DocumentsProvider instances * installed on the device, letting the user interactively navigate through them. * - * So, this allows us to use the traditional file picker that does not redact location tags from EXIF. + * So, this allows us to use the traditional file picker that does not redact location tags + * from EXIF. * */ Intent intent; - if (isGetContentPickerPreferred) { - intent = new Intent(Intent.ACTION_GET_CONTENT); - } else { + if (openDocumentIntentPreferred) { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + } else { + intent = new Intent(Intent.ACTION_GET_CONTENT); } intent.setType("image/*"); return intent; diff --git a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java index ad1c7e039..fddb91df8 100644 --- a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java @@ -171,10 +171,10 @@ public class SettingsFragment extends PreferenceFragmentCompat { return true; }); - Preference getContentPickerPreference = findPreference("getContentPhotoPickerPref"); - getContentPickerPreference.setOnPreferenceChangeListener( + Preference documentBasedPickerPreference = findPreference("openDocumentPhotoPickerPref"); + documentBasedPickerPreference.setOnPreferenceChangeListener( (preference, newValue) -> { - boolean isGetContentPickerTurnedOn = (boolean) newValue; + boolean isGetContentPickerTurnedOn = !(boolean) newValue; if (isGetContentPickerTurnedOn) { showLocationLossWarning(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 767170a51..42a1b70dc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -451,9 +451,7 @@ Upload your first media by tapping on the add button. The app would not record location along with in-shots as the GPS is turned off Use document based photo picker The new Android photo picker risks losing location information. Enable if you seem to be using it. - Use GET_CONTENT photo picker - Disable if your pictures get uploaded without location - Please make sure that this new Android picker does not strip location from your pictures. + Turning this off could trigger the new Android photo picker. It risks losing location information.\n\nTap on \'Read more\' for more information. You won\'t see the campaigns anymore. However, you can re-enable this notification in Settings if you wish. This function requires network connection, please check your connection settings. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 183757b7c..8ac890545 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -57,6 +57,7 @@ android:title="Uploads"> + + -