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 7ce3b7ebb1.

* 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
This commit is contained in:
Kaartic Sivaraam 2023-09-04 07:48:58 +05:30 committed by GitHub
parent 7ce3b7ebb1
commit 4540f54d59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 25 deletions

View file

@ -171,8 +171,8 @@ public class ContributionController {
*/ */
private void initiateGalleryUpload(final Activity activity, final boolean allowMultipleUploads) { private void initiateGalleryUpload(final Activity activity, final boolean allowMultipleUploads) {
setPickerConfiguration(activity, allowMultipleUploads); setPickerConfiguration(activity, allowMultipleUploads);
boolean isGetContentPickerPreferred = defaultKvStore.getBoolean("getContentPhotoPickerPref"); boolean openDocumentIntentPreferred = defaultKvStore.getBoolean("openDocumentPhotoPickerPref", true);
FilePicker.openGallery(activity, 0, isGetContentPickerPreferred); FilePicker.openGallery(activity, 0, openDocumentIntentPreferred);
} }
/** /**

View file

@ -47,10 +47,10 @@ public class FilePicker implements Constants {
} }
private static Intent createGalleryIntent(@NonNull Context context, int type, private static Intent createGalleryIntent(@NonNull Context context, int type,
boolean isGetContentPickerPreferred) { boolean openDocumentIntentPreferred) {
// storing picked image type to shared preferences // storing picked image type to shared preferences
storeType(context, type); storeType(context, type);
return plainGalleryPickerIntent(isGetContentPickerPreferred) return plainGalleryPickerIntent(openDocumentIntentPreferred)
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery()); .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 * @param type Custom type of your choice, which will be returned with the images
*/ */
public static void openGallery(Activity activity, int type, boolean isGetContentPickerPreferred) { public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) {
Intent intent = createGalleryIntent(activity, type, isGetContentPickerPreferred); Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred);
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY); 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); 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 * Asking for ACCESS_MEDIA_LOCATION at runtime solved the location-loss issue
* in the custom selector in Contributions fragment. * in the custom selector in Contributions fragment.
* Detailed discussion: https://github.com/commons-app/apps-android-commons/issues/5015 * 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 * Reported on the Google Issue Tracker: https://issuetracker.google.com/issues/243294058
* Status: Won't fix (Intended behaviour) * Status: Won't fix (Intended behaviour)
* *
* Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT * Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT (by default; can
* (based on user's preference) as: * be changed through the Setting page) as:
* *
* ACTION_GET_CONTENT opens the 'best application' for choosing that kind of data * 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 * 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 * ACTION_OPEN_DOCUMENT, however, displays the various DocumentsProvider instances
* installed on the device, letting the user interactively navigate through them. * 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; Intent intent;
if (isGetContentPickerPreferred) { if (openDocumentIntentPreferred) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT);
} }
intent.setType("image/*"); intent.setType("image/*");
return intent; return intent;

View file

@ -171,10 +171,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
Preference getContentPickerPreference = findPreference("getContentPhotoPickerPref"); Preference documentBasedPickerPreference = findPreference("openDocumentPhotoPickerPref");
getContentPickerPreference.setOnPreferenceChangeListener( documentBasedPickerPreference.setOnPreferenceChangeListener(
(preference, newValue) -> { (preference, newValue) -> {
boolean isGetContentPickerTurnedOn = (boolean) newValue; boolean isGetContentPickerTurnedOn = !(boolean) newValue;
if (isGetContentPickerTurnedOn) { if (isGetContentPickerTurnedOn) {
showLocationLossWarning(); showLocationLossWarning();
} }

View file

@ -451,9 +451,7 @@ Upload your first media by tapping on the add button.</string>
<string name="in_app_camera_location_unavailable">The app would not record location along with in-shots as the GPS is turned off</string> <string name="in_app_camera_location_unavailable">The app would not record location along with in-shots as the GPS is turned off</string>
<string name="open_document_photo_picker_title">Use document based photo picker</string> <string name="open_document_photo_picker_title">Use document based photo picker</string>
<string name="open_document_photo_picker_explanation">The new Android photo picker risks losing location information. Enable if you seem to be using it.</string> <string name="open_document_photo_picker_explanation">The new Android photo picker risks losing location information. Enable if you seem to be using it.</string>
<string name="get_content_photo_picker_title">Use GET_CONTENT photo picker</string> <string name="location_loss_warning">Turning this off could trigger the new Android photo picker. It risks losing location information.\n\nTap on \'Read more\' for more information.</string>
<string name="get_content_photo_picker_explanation">Disable if your pictures get uploaded without location</string>
<string name="location_loss_warning">Please make sure that this new Android picker does not strip location from your pictures.</string>
<string name="nearby_campaign_dismiss_message">You won\'t see the campaigns anymore. However, you can re-enable this notification in Settings if you wish.</string> <string name="nearby_campaign_dismiss_message">You won\'t see the campaigns anymore. However, you can re-enable this notification in Settings if you wish.</string>
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string> <string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>

View file

@ -57,6 +57,7 @@
android:title="Uploads"> android:title="Uploads">
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="useExternalStorage" android:key="useExternalStorage"
app:singleLineTitle="false" app:singleLineTitle="false"
@ -68,6 +69,12 @@
android:title="@string/in_app_camera_location_permission_title" android:title="@string/in_app_camera_location_permission_title"
android:summary="@string/in_app_camera_location_switch_pref_summary"/> android:summary="@string/in_app_camera_location_switch_pref_summary"/>
<SwitchPreference
android:defaultValue="true"
android:key="openDocumentPhotoPickerPref"
android:summary="@string/open_document_photo_picker_explanation"
android:title="@string/open_document_photo_picker_title"/>
<SwitchPreference <SwitchPreference
android:key="useAuthorName" android:key="useAuthorName"
app:singleLineTitle="false" app:singleLineTitle="false"
@ -81,11 +88,6 @@
app:useSimpleSummaryProvider="true" app:useSimpleSummaryProvider="true"
android:title="@string/preference_author_name" /> android:title="@string/preference_author_name" />
<SwitchPreference
android:defaultValue="false"
android:key="getContentPhotoPickerPref"
android:summary="@string/get_content_photo_picker_explanation"
android:title="@string/get_content_photo_picker_title"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory