Merge pull request #282 from misaochan/fix-gpsextractor-not-called

Fix 'GPSExtractor not called' bug
This commit is contained in:
Josephine Lim 2016-09-17 18:05:49 +12:00 committed by GitHub
commit 6210089826
4 changed files with 32 additions and 24 deletions

View file

@ -1,5 +1,9 @@
# Wikimedia Commons for Android # Wikimedia Commons for Android
##v1.31
- Fixed bug with geolocation category suggestions not being displayed
- Fixed bug with (0,0) being recorded as image location occasionally
##v1.30 ##v1.30
- Fixed {{Location|null}} template bug - Fixed {{Location|null}} template bug

View file

@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.free.nrw.commons" package="fr.free.nrw.commons"
android:versionCode="48" android:versionCode="49"
android:versionName="1.30" > android:versionName="1.31" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

View file

@ -82,6 +82,7 @@ public class GPSExtractor {
/** /**
* Extracts geolocation (either of image from EXIF data, or of user) * Extracts geolocation (either of image from EXIF data, or of user)
* @param useGPS set to true if location permissions allowed (by API 23), false if disallowed
* @return coordinates as string (needs to be passed as a String in API query) * @return coordinates as string (needs to be passed as a String in API query)
*/ */
@Nullable @Nullable

View file

@ -92,7 +92,8 @@ public class ShareActivity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Check for Storage permission that is required for upload. Do not allow user to proceed without permission, otherwise will crash //Check for Storage permission that is required for upload. Do not allow user to proceed without permission, otherwise will crash
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4); //See http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
} else { } else {
uploadBegins(); uploadBegins();
} }
@ -102,6 +103,11 @@ public class ShareActivity
} }
private void uploadBegins() { private void uploadBegins() {
if (locationPermission) {
getFileMetadata(true);
} else {
getFileMetadata(false);
}
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG); Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
startingToast.show(); startingToast.show();
@ -290,11 +296,11 @@ public class ShareActivity
}).show(); }).show();
} }
} else if (useNewPermissions && storagePermission && !locationPermission) { } else if (useNewPermissions && storagePermission && !locationPermission) {
getFileMetadata(); getFileMetadata(true);
} else if(!useNewPermissions || (storagePermission && locationPermission)) { } else if(!useNewPermissions || (storagePermission && locationPermission)) {
getFileMetadata(); getFileMetadata(true);
getLocationData();
} }
} }
@Override @Override
@ -305,7 +311,7 @@ public class ShareActivity
case 1: { case 1: {
if (grantResults.length > 0 if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getFileMetadata(); getFileMetadata(true);
} }
return; return;
} }
@ -313,7 +319,7 @@ public class ShareActivity
case 2: { case 2: {
if (grantResults.length > 0 if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getLocationData(); getFileMetadata(false);
} }
return; return;
} }
@ -321,11 +327,11 @@ public class ShareActivity
case 3: { case 3: {
if (grantResults.length > 1 if (grantResults.length > 1
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getFileMetadata(); getFileMetadata(true);
} }
if (grantResults.length > 1 if (grantResults.length > 1
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) { && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
getLocationData(); getFileMetadata(false);
} }
return; return;
} }
@ -336,7 +342,7 @@ public class ShareActivity
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//It is OK to call this at both (1) and (4) because if perm had been granted at //It is OK to call this at both (1) and (4) because if perm had been granted at
//snackbar, user should not be prompted at submit button //snackbar, user should not be prompted at submit button
getFileMetadata(); getFileMetadata(true);
//Uploading only begins if storage permission granted from arrow icon //Uploading only begins if storage permission granted from arrow icon
uploadBegins(); uploadBegins();
@ -347,26 +353,23 @@ public class ShareActivity
} }
} }
public void getFileMetadata() { /**
* Gets coordinates for category suggestions, either from EXIF data or user location
* @param gpsEnabled
*/
public void getFileMetadata(boolean gpsEnabled) {
filePath = FileUtils.getPath(this, mediaUri); filePath = FileUtils.getPath(this, mediaUri);
Log.d(TAG, "Filepath: " + filePath); Log.d(TAG, "Filepath: " + filePath);
Log.d(TAG, "Calling GPSExtractor"); Log.d(TAG, "Calling GPSExtractor");
imageObj = new GPSExtractor(filePath, this);
if (filePath != null && !filePath.equals("")) {
// Gets image coords from exif data
decimalCoords = imageObj.getCoords(false);
useImageCoords();
}
}
public void getLocationData() {
if(imageObj == null) { if(imageObj == null) {
imageObj = new GPSExtractor(filePath, this); imageObj = new GPSExtractor(filePath, this);
} }
decimalCoords = imageObj.getCoords(true); if (filePath != null && !filePath.equals("")) {
useImageCoords(); // Gets image coords from exif data or user location
decimalCoords = imageObj.getCoords(gpsEnabled);
useImageCoords();
}
} }
/** /**