Skip to content

Commit 4540f54

Browse files
authored
Fix document picker trigger bug (commons-app#5275)
* Revert "Revert a1b6973 until we find out why it uses OPEN_DOCUMENT by default on fresh install" This reverts commit 7ce3b7e. * 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 commons-app#5274
1 parent 7ce3b7e commit 4540f54

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public void initiateCustomGalleryPickWithPermission(final Activity activity) {
171171
*/
172172
private void initiateGalleryUpload(final Activity activity, final boolean allowMultipleUploads) {
173173
setPickerConfiguration(activity, allowMultipleUploads);
174-
boolean isGetContentPickerPreferred = defaultKvStore.getBoolean("getContentPhotoPickerPref");
175-
FilePicker.openGallery(activity, 0, isGetContentPickerPreferred);
174+
boolean openDocumentIntentPreferred = defaultKvStore.getBoolean("openDocumentPhotoPickerPref", true);
175+
FilePicker.openGallery(activity, 0, openDocumentIntentPreferred);
176176
}
177177

178178
/**

app/src/main/java/fr/free/nrw/commons/filepicker/FilePicker.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ private static Uri createCameraPictureFile(@NonNull Context context) throws IOEx
4747
}
4848

4949
private static Intent createGalleryIntent(@NonNull Context context, int type,
50-
boolean isGetContentPickerPreferred) {
50+
boolean openDocumentIntentPreferred) {
5151
// storing picked image type to shared preferences
5252
storeType(context, type);
53-
return plainGalleryPickerIntent(isGetContentPickerPreferred)
53+
return plainGalleryPickerIntent(openDocumentIntentPreferred)
5454
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configuration(context).allowsMultiplePickingInGallery());
5555
}
5656

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

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

204-
private static Intent plainGalleryPickerIntent(boolean isGetContentPickerPreferred) {
205-
/**
204+
private static Intent plainGalleryPickerIntent(boolean openDocumentIntentPreferred) {
205+
/*
206206
* Asking for ACCESS_MEDIA_LOCATION at runtime solved the location-loss issue
207207
* in the custom selector in Contributions fragment.
208208
* Detailed discussion: https://github.com/commons-app/apps-android-commons/issues/5015
@@ -217,23 +217,24 @@ private static Intent plainGalleryPickerIntent(boolean isGetContentPickerPreferr
217217
* Reported on the Google Issue Tracker: https://issuetracker.google.com/issues/243294058
218218
* Status: Won't fix (Intended behaviour)
219219
*
220-
* Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT
221-
* (based on user's preference) as:
220+
* Switched intent from ACTION_GET_CONTENT to ACTION_OPEN_DOCUMENT (by default; can
221+
* be changed through the Setting page) as:
222222
*
223223
* ACTION_GET_CONTENT opens the 'best application' for choosing that kind of data
224224
* The best application is the new Photo Picker that redacts the location tags
225225
*
226226
* ACTION_OPEN_DOCUMENT, however, displays the various DocumentsProvider instances
227227
* installed on the device, letting the user interactively navigate through them.
228228
*
229-
* So, this allows us to use the traditional file picker that does not redact location tags from EXIF.
229+
* So, this allows us to use the traditional file picker that does not redact location tags
230+
* from EXIF.
230231
*
231232
*/
232233
Intent intent;
233-
if (isGetContentPickerPreferred) {
234-
intent = new Intent(Intent.ACTION_GET_CONTENT);
235-
} else {
234+
if (openDocumentIntentPreferred) {
236235
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
236+
} else {
237+
intent = new Intent(Intent.ACTION_GET_CONTENT);
237238
}
238239
intent.setType("image/*");
239240
return intent;

app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ public boolean onPreferenceClick(Preference preference) {
171171
return true;
172172
});
173173

174-
Preference getContentPickerPreference = findPreference("getContentPhotoPickerPref");
175-
getContentPickerPreference.setOnPreferenceChangeListener(
174+
Preference documentBasedPickerPreference = findPreference("openDocumentPhotoPickerPref");
175+
documentBasedPickerPreference.setOnPreferenceChangeListener(
176176
(preference, newValue) -> {
177-
boolean isGetContentPickerTurnedOn = (boolean) newValue;
177+
boolean isGetContentPickerTurnedOn = !(boolean) newValue;
178178
if (isGetContentPickerTurnedOn) {
179179
showLocationLossWarning();
180180
}

app/src/main/res/values/strings.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,7 @@ Upload your first media by tapping on the add button.</string>
451451
<string name="in_app_camera_location_unavailable">The app would not record location along with in-shots as the GPS is turned off</string>
452452
<string name="open_document_photo_picker_title">Use document based photo picker</string>
453453
<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>
454-
<string name="get_content_photo_picker_title">Use GET_CONTENT photo picker</string>
455-
<string name="get_content_photo_picker_explanation">Disable if your pictures get uploaded without location</string>
456-
<string name="location_loss_warning">Please make sure that this new Android picker does not strip location from your pictures.</string>
454+
<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>
457455

458456
<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>
459457
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>

app/src/main/res/xml/preferences.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
android:title="Uploads">
5858

5959
<SwitchPreference
60+
6061
android:defaultValue="true"
6162
android:key="useExternalStorage"
6263
app:singleLineTitle="false"
@@ -68,6 +69,12 @@
6869
android:title="@string/in_app_camera_location_permission_title"
6970
android:summary="@string/in_app_camera_location_switch_pref_summary"/>
7071

72+
<SwitchPreference
73+
android:defaultValue="true"
74+
android:key="openDocumentPhotoPickerPref"
75+
android:summary="@string/open_document_photo_picker_explanation"
76+
android:title="@string/open_document_photo_picker_title"/>
77+
7178
<SwitchPreference
7279
android:key="useAuthorName"
7380
app:singleLineTitle="false"
@@ -81,11 +88,6 @@
8188
app:useSimpleSummaryProvider="true"
8289
android:title="@string/preference_author_name" />
8390

84-
<SwitchPreference
85-
android:defaultValue="false"
86-
android:key="getContentPhotoPickerPref"
87-
android:summary="@string/get_content_photo_picker_explanation"
88-
android:title="@string/get_content_photo_picker_title"/>
8991
</PreferenceCategory>
9092

9193
<PreferenceCategory

0 commit comments

Comments
 (0)