Skip to content

Commit

Permalink
Revert a1b6973 until we find out why it uses OPEN_DOCUMENT by default…
Browse files Browse the repository at this point in the history
… on fresh install
  • Loading branch information
nicolas-raoul committed Sep 3, 2023
1 parent 5073ca0 commit 7ce3b7e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public void initiateCustomGalleryPickWithPermission(final Activity activity) {
*/
private void initiateGalleryUpload(final Activity activity, final boolean allowMultipleUploads) {
setPickerConfiguration(activity, allowMultipleUploads);
boolean openDocumentIntentPreferred = defaultKvStore.getBoolean("openDocumentPhotoPickerPref");
FilePicker.openGallery(activity, 0, openDocumentIntentPreferred);
boolean isGetContentPickerPreferred = defaultKvStore.getBoolean("getContentPhotoPickerPref");
FilePicker.openGallery(activity, 0, isGetContentPickerPreferred);
}

/**
Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ private static Uri createCameraPictureFile(@NonNull Context context) throws IOEx
}

private static Intent createGalleryIntent(@NonNull Context context, int type,
boolean openDocumentIntentPreferred) {
boolean isGetContentPickerPreferred) {
// storing picked image type to shared preferences
storeType(context, type);
return plainGalleryPickerIntent(openDocumentIntentPreferred)
return plainGalleryPickerIntent(isGetContentPickerPreferred)
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery());
}

Expand Down Expand Up @@ -106,8 +106,8 @@ private static int restoreType(@NonNull Context context) {
*
* @param type Custom type of your choice, which will be returned with the images
*/
public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) {
Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred);
public static void openGallery(Activity activity, int type, boolean isGetContentPickerPreferred) {
Intent intent = createGalleryIntent(activity, type, isGetContentPickerPreferred);
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY);
}

Expand Down Expand Up @@ -201,8 +201,8 @@ private static boolean isPhoto(Intent data) {
return data == null || (data.getData() == null && data.getClipData() == null);
}

private static Intent plainGalleryPickerIntent(boolean openDocumentIntentPreferred) {
/*
private static Intent plainGalleryPickerIntent(boolean isGetContentPickerPreferred) {
/**
* 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
Expand All @@ -217,24 +217,23 @@ private static Intent plainGalleryPickerIntent(boolean openDocumentIntentPreferr
* 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 (by default; can
* be changed through the Setting page) as:
* Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT
* (based on user's preference) 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
*
* 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 (openDocumentIntentPreferred) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
} else {
if (isGetContentPickerPreferred) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
}
intent.setType("image/*");
return intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ public boolean onPreferenceClick(Preference preference) {
return true;
});

Preference documentBasedPickerPreference = findPreference("openDocumentPhotoPickerPref");
documentBasedPickerPreference.setOnPreferenceChangeListener(
Preference getContentPickerPreference = findPreference("getContentPhotoPickerPref");
getContentPickerPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
boolean isGetContentPickerTurnedOn = !(boolean) newValue;
boolean isGetContentPickerTurnedOn = (boolean) newValue;
if (isGetContentPickerTurnedOn) {
showLocationLossWarning();
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ 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="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="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_title">Use GET_CONTENT photo picker</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="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
android:title="Uploads">

<SwitchPreference

android:defaultValue="true"
android:key="useExternalStorage"
app:singleLineTitle="false"
Expand All @@ -69,12 +68,6 @@
android:title="@string/in_app_camera_location_permission_title"
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
android:key="useAuthorName"
app:singleLineTitle="false"
Expand All @@ -88,6 +81,11 @@
app:useSimpleSummaryProvider="true"
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
Expand Down

0 comments on commit 7ce3b7e

Please sign in to comment.