5196: Fix location stripped from EXIF metadata (#5227)

* MainActivity: add ACCESS_MEDIA_LOCATION permission check to retain location info in EXIF metadata

* remove redundant permission check and optimise imports

* FilePicker: switch to ACTION_OPEN_DOCUMENT intent for opening image files

* add a comment explaining the change

* implement GET_CONTENT photo picker toggle switch

* add location loss warning pop up

* SettingsFragment: modify the comment about GET_CONTENT takeover for more clarity
This commit is contained in:
Ritika Pahwa 2023-06-15 06:35:55 +05:30 committed by GitHub
parent 4d71c305f2
commit 9a0f35c681
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 20 deletions

View file

@ -42,6 +42,7 @@ import fr.free.nrw.commons.recentlanguages.Language;
import fr.free.nrw.commons.recentlanguages.RecentLanguagesAdapter;
import fr.free.nrw.commons.recentlanguages.RecentLanguagesDao;
import fr.free.nrw.commons.upload.LanguagesAdapter;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import java.util.HashMap;
@ -71,6 +72,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
private TextView recentLanguagesTextView;
private View separator;
private ListView languageHistoryListView;
private static final String GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@ -150,6 +152,17 @@ public class SettingsFragment extends PreferenceFragmentCompat {
checkPermissionsAndSendLogs();
return true;
});
Preference getContentPickerPreference = findPreference("getContentPhotoPickerPref");
getContentPickerPreference.setOnPreferenceChangeListener(
(preference, newValue) -> {
boolean isGetContentPickerTurnedOn = (boolean) newValue;
if (isGetContentPickerTurnedOn) {
showLocationLossWarning();
}
return true;
}
);
// Disable some settings when not logged in.
if (defaultKvStore.getBoolean("login_skipped", false)) {
findPreference("useExternalStorage").setEnabled(false);
@ -162,6 +175,26 @@ public class SettingsFragment extends PreferenceFragmentCompat {
}
}
/**
* On some devices, the new Photo Picker with GET_CONTENT takeover
* redacts location tags from EXIF metadata
*
* Show warning to the user when ACTION_GET_CONTENT intent is enabled
*/
private void showLocationLossWarning() {
DialogUtil.showAlertDialog(
getActivity(),
null,
getString(R.string.location_loss_warning),
getString(R.string.ok),
getString(R.string.read_help_link),
() -> {},
() -> Utils.handleWebUrl(requireContext(), Uri.parse(GET_CONTENT_PICKER_HELP_URL)),
null,
true
);
}
@Override
protected Adapter onCreateAdapter(final PreferenceScreen preferenceScreen) {
return new PreferenceGroupAdapter(preferenceScreen) {