Skip to content

Commit f1f41e5

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/2.8-release'
2 parents d7b956e + 2d831c0 commit f1f41e5

File tree

14 files changed

+78
-197
lines changed

14 files changed

+78
-197
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
2525
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
2626
import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE;
27+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
2728

2829
public class ContributionController {
2930

@@ -91,6 +92,7 @@ public void startGalleryPick() {
9192
}
9293

9394
public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload, String wikiDataEntityId) {
95+
Timber.d("Is direct upload %s and the Wikidata entity ID is %s", isDirectUpload, wikiDataEntityId);
9496
FragmentActivity activity = fragment.getActivity();
9597
Timber.d("handleImagePicked() called with onActivityResult()");
9698
Intent shareIntent = new Intent(activity, ShareActivity.class);
@@ -119,7 +121,7 @@ public void handleImagePicked(int requestCode, Intent data, boolean isDirectUplo
119121
try {
120122
shareIntent.putExtra("isDirectUpload", isDirectUpload);
121123
if (wikiDataEntityId != null && !wikiDataEntityId.equals("")) {
122-
shareIntent.putExtra("wikiDataEntityId", wikiDataEntityId);
124+
shareIntent.putExtra(WIKIDATA_ENTITY_ID_PREF, wikiDataEntityId);
123125
}
124126
activity.startActivity(shareIntent);
125127
} catch (SecurityException e) {

app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import static android.app.Activity.RESULT_OK;
3737
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
38+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
3839

3940
public class NearbyListFragment extends DaggerFragment {
4041
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
@@ -146,7 +147,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
146147
if (resultCode == RESULT_OK) {
147148
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
148149
requestCode, resultCode, data);
149-
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
150+
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
150151
} else {
151152
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
152153
requestCode, resultCode, data);

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
import static android.app.Activity.RESULT_OK;
6565
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
66+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
6667

6768
public class NearbyMapFragment extends DaggerFragment {
6869

@@ -711,15 +712,15 @@ private void passInfoToSheet(Place place) {
711712

712713
fabCamera.setOnClickListener(view -> {
713714
if (fabCamera.isShown()) {
714-
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
715+
Timber.d("Camera button tapped. Place: %s", place.toString());
715716
storeSharedPrefs();
716717
directUpload.initiateCameraUpload();
717718
}
718719
});
719720

720721
fabGallery.setOnClickListener(view -> {
721722
if (fabGallery.isShown()) {
722-
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
723+
Timber.d("Gallery button tapped. Place: %s", place.toString());
723724
storeSharedPrefs();
724725
directUpload.initiateGalleryUpload();
725726
}
@@ -731,7 +732,7 @@ void storeSharedPrefs() {
731732
editor.putString("Title", place.getName());
732733
editor.putString("Desc", place.getLongDescription());
733734
editor.putString("Category", place.getCategory());
734-
editor.putString("WikiDataEntityId", place.getWikiDataEntityId());
735+
editor.putString(WIKIDATA_ENTITY_ID_PREF, place.getWikiDataEntityId());
735736
editor.apply();
736737
}
737738

@@ -767,7 +768,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
767768
if (resultCode == RESULT_OK) {
768769
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
769770
requestCode, resultCode, data);
770-
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
771+
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
771772
} else {
772773
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
773774
requestCode, resultCode, data);

app/src/main/java/fr/free/nrw/commons/nearby/Place.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import fr.free.nrw.commons.R;
1212
import fr.free.nrw.commons.location.LatLng;
13+
import timber.log.Timber;
1314

1415
public class Place {
1516

@@ -58,10 +59,12 @@ public void setDistance(String distance) {
5859
@Nullable
5960
public String getWikiDataEntityId() {
6061
if (!hasWikidataLink()) {
62+
Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString());
6163
return null;
6264
}
6365

6466
String wikiDataLink = siteLinks.getWikidataLink().toString();
67+
Timber.d("Wikidata entity is %s", wikiDataLink);
6568
return wikiDataLink.replace("http://www.wikidata.org/entity/", "");
6669
}
6770

@@ -94,7 +97,18 @@ public int hashCode() {
9497

9598
@Override
9699
public String toString() {
97-
return String.format("Place(%s@%s)", name, location);
100+
return "Place{" +
101+
"name='" + name + '\'' +
102+
", label='" + label + '\'' +
103+
", longDescription='" + longDescription + '\'' +
104+
", secondaryImageUrl='" + secondaryImageUrl + '\'' +
105+
", location='" + location + '\'' +
106+
", category='" + category + '\'' +
107+
", image='" + image + '\'' +
108+
", secondaryImage=" + secondaryImage +
109+
", distance='" + distance + '\'' +
110+
", siteLinks='" + siteLinks.toString() + '\'' +
111+
'}';
98112
}
99113

100114
/**

app/src/main/java/fr/free/nrw/commons/nearby/Sitelinks.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ private static Uri sanitiseString(String stringUrl) {
5858
return Uri.parse(sanitisedStringUrl);
5959
}
6060

61+
@Override
62+
public String toString() {
63+
return "Sitelinks{" +
64+
"wikipediaLink='" + wikipediaLink + '\'' +
65+
", commonsLink='" + commonsLink + '\'' +
66+
", wikidataLink='" + wikidataLink + '\'' +
67+
'}';
68+
}
69+
6170
private Sitelinks(Sitelinks.Builder builder) {
6271
this.wikidataLink = builder.wikidataLink;
6372
this.wikipediaLink = builder.wikipediaLink;

app/src/main/java/fr/free/nrw/commons/upload/FileProcessor.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ GPSExtractor processFileCoordinates(boolean gpsEnabled) {
106106
ParcelFileDescriptor descriptor = contentResolver.openFileDescriptor(mediaUri, "r");
107107
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
108108
if (descriptor != null) {
109-
imageObj = new GPSExtractor(descriptor.getFileDescriptor(), context, prefs);
109+
imageObj = new GPSExtractor(descriptor.getFileDescriptor());
110110
}
111111
} else {
112112
String filePath = getPathOfMediaOrCopy();
113113
if (filePath != null) {
114-
imageObj = new GPSExtractor(filePath, context, prefs);
114+
imageObj = new GPSExtractor(filePath);
115115
}
116116
}
117117

118-
decimalCoords = imageObj.getCoords(gpsEnabled);
118+
decimalCoords = imageObj.getCoords();
119119
if (decimalCoords == null || !imageObj.imageCoordsExists) {
120120
//Find other photos taken around the same time which has gps coordinates
121121
if (!haveCheckedForOtherImages)
122-
findOtherImages(gpsEnabled);// Do not do repeat the process
122+
findOtherImages();// Do not do repeat the process
123123
} else {
124124
useImageCoords();
125125
}
@@ -137,9 +137,8 @@ String getDecimalCoords() {
137137
/**
138138
* Find other images around the same location that were taken within the last 20 sec
139139
*
140-
* @param gpsEnabled True if GPS is enabled
141140
*/
142-
private void findOtherImages(boolean gpsEnabled) {
141+
private void findOtherImages() {
143142
Timber.d("filePath" + getPathOfMediaOrCopy());
144143

145144
long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created
@@ -161,17 +160,17 @@ private void findOtherImages(boolean gpsEnabled) {
161160
}
162161
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
163162
if (descriptor != null) {
164-
tempImageObj = new GPSExtractor(descriptor.getFileDescriptor(), context, prefs);
163+
tempImageObj = new GPSExtractor(descriptor.getFileDescriptor());
165164
}
166165
} else {
167166
if (filePath != null) {
168-
tempImageObj = new GPSExtractor(file.getAbsolutePath(), context, prefs);
167+
tempImageObj = new GPSExtractor(file.getAbsolutePath());
169168
}
170169
}
171170

172171
if (tempImageObj != null) {
173-
Timber.d("not null fild EXIF" + tempImageObj.imageCoordsExists + " coords" + tempImageObj.getCoords(gpsEnabled));
174-
if (tempImageObj.getCoords(gpsEnabled) != null && tempImageObj.imageCoordsExists) {
172+
Timber.d("not null fild EXIF" + tempImageObj.imageCoordsExists + " coords" + tempImageObj.getCoords());
173+
if (tempImageObj.getCoords() != null && tempImageObj.imageCoordsExists) {
175174
// Current image has gps coordinates and it's not current gps locaiton
176175
Timber.d("This file has image coords:" + file.getAbsolutePath());
177176
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
@@ -250,7 +249,7 @@ void detectUnwantedPictures() {
250249
@Override
251250
public void onPositiveResponse() {
252251
imageObj = tempImageObj;
253-
decimalCoords = imageObj.getCoords(false);// Not necessary to use gps as image already ha EXIF data
252+
decimalCoords = imageObj.getCoords();// Not necessary to use gps as image already ha EXIF data
254253
Timber.d("EXIF from tempImageObj");
255254
useImageCoords();
256255
}

app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java

Lines changed: 7 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package fr.free.nrw.commons.upload;
22

3-
import android.content.Context;
4-
import android.content.SharedPreferences;
5-
import android.location.Criteria;
6-
import android.location.Location;
7-
import android.location.LocationListener;
8-
import android.location.LocationManager;
93
import android.media.ExifInterface;
10-
import android.os.Bundle;
114
import android.support.annotation.NonNull;
125
import android.support.annotation.Nullable;
136
import android.support.annotation.RequiresApi;
@@ -19,31 +12,21 @@
1912

2013
/**
2114
* Extracts geolocation to be passed to API for category suggestions. If a picture with geolocation
22-
* is uploaded, extract latitude and longitude from EXIF data of image. If a picture without
23-
* geolocation is uploaded, retrieve user's location (if enabled in Settings).
15+
* is uploaded, extract latitude and longitude from EXIF data of image.
2416
*/
2517
public class GPSExtractor {
2618

27-
private final Context context;
28-
private SharedPreferences prefs;
2919
private ExifInterface exif;
3020
private double decLatitude;
3121
private double decLongitude;
32-
private Double currentLatitude = null;
33-
private Double currentLongitude = null;
3422
public boolean imageCoordsExists;
35-
private MyLocationListener myLocationListener;
36-
private LocationManager locationManager;
3723

3824
/**
3925
* Construct from the file descriptor of the image (only for API 24 or newer).
4026
* @param fileDescriptor the file descriptor of the image
41-
* @param context the context
4227
*/
4328
@RequiresApi(24)
44-
public GPSExtractor(@NonNull FileDescriptor fileDescriptor, Context context, SharedPreferences prefs) {
45-
this.context = context;
46-
this.prefs = prefs;
29+
public GPSExtractor(@NonNull FileDescriptor fileDescriptor) {
4730
try {
4831
exif = new ExifInterface(fileDescriptor);
4932
} catch (IOException | IllegalArgumentException e) {
@@ -54,96 +37,32 @@ public GPSExtractor(@NonNull FileDescriptor fileDescriptor, Context context, Sha
5437
/**
5538
* Construct from the file path of the image.
5639
* @param path file path of the image
57-
* @param context the context
40+
*
5841
*/
59-
public GPSExtractor(@NonNull String path, Context context, SharedPreferences prefs) {
60-
this.prefs = prefs;
42+
public GPSExtractor(@NonNull String path) {
6143
try {
6244
exif = new ExifInterface(path);
6345
} catch (IOException | IllegalArgumentException e) {
6446
Timber.w(e);
6547
}
66-
this.context = context;
67-
}
68-
69-
/**
70-
* Check if user enabled retrieval of their current location in Settings
71-
* @return true if enabled, false if disabled
72-
*/
73-
private boolean gpsPreferenceEnabled() {
74-
boolean gpsPref = prefs.getBoolean("allowGps", false);
75-
Timber.d("Gps pref set to: %b", gpsPref);
76-
return gpsPref;
77-
}
78-
79-
/**
80-
* Registers a LocationManager to listen for current location
81-
*/
82-
protected void registerLocationManager() {
83-
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
84-
Criteria criteria = new Criteria();
85-
String provider = locationManager.getBestProvider(criteria, true);
86-
myLocationListener = new MyLocationListener();
87-
88-
try {
89-
locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
90-
Location location = locationManager.getLastKnownLocation(provider);
91-
if (location != null) {
92-
myLocationListener.onLocationChanged(location);
93-
}
94-
} catch (IllegalArgumentException e) {
95-
Timber.e(e, "Illegal argument exception");
96-
} catch (SecurityException e) {
97-
Timber.e(e, "Security exception");
98-
}
99-
}
100-
101-
protected void unregisterLocationManager() {
102-
try {
103-
locationManager.removeUpdates(myLocationListener);
104-
} catch (SecurityException e) {
105-
Timber.e(e, "Security exception");
106-
}
10748
}
10849

10950
/**
11051
* Extracts geolocation (either of image from EXIF data, or of user)
111-
* @param useGPS set to true if location permissions allowed (by API 23), false if disallowed
11252
* @return coordinates as string (needs to be passed as a String in API query)
11353
*/
11454
@Nullable
115-
public String getCoords(boolean useGPS) {
55+
public String getCoords() {
11656
String latitude;
11757
String longitude;
11858
String latitudeRef;
11959
String longitudeRef;
12060
String decimalCoords;
12161

12262
//If image has no EXIF data and user has enabled GPS setting, get user's location
63+
//TODO: Always return null as a temporary fix for #1599
12364
if (exif == null || exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) == null) {
124-
if (useGPS) {
125-
registerLocationManager();
126-
127-
imageCoordsExists = false;
128-
Timber.d("EXIF data has no location info");
129-
130-
//Check what user's preference is for automatic location detection
131-
boolean gpsPrefEnabled = gpsPreferenceEnabled();
132-
133-
//Check that currentLatitude and currentLongitude have been
134-
// explicitly set by MyLocationListener
135-
// and do not default to (0.0,0.0)
136-
if (gpsPrefEnabled && currentLatitude != null && currentLongitude != null) {
137-
Timber.d("Current location values: Lat = %f Long = %f",
138-
currentLatitude, currentLongitude);
139-
return String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude);
140-
} else {
141-
// No coords found
142-
return null;
143-
}
144-
} else {
145-
return null;
146-
}
65+
return null;
14766
} else {
14867
//If image has EXIF data, extract image coords
14968
imageCoordsExists = true;
@@ -166,33 +85,6 @@ public String getCoords(boolean useGPS) {
16685
}
16786
}
16887

169-
/**
170-
* Listen for user's location when it changes
171-
*/
172-
private class MyLocationListener implements LocationListener {
173-
174-
@Override
175-
public void onLocationChanged(Location location) {
176-
currentLatitude = location.getLatitude();
177-
currentLongitude = location.getLongitude();
178-
}
179-
180-
@Override
181-
public void onStatusChanged(String provider, int status, Bundle extras) {
182-
Timber.d("%s's status changed to %d", provider, status);
183-
}
184-
185-
@Override
186-
public void onProviderEnabled(String provider) {
187-
Timber.d("Provider %s enabled", provider);
188-
}
189-
190-
@Override
191-
public void onProviderDisabled(String provider) {
192-
Timber.d("Provider %s disabled", provider);
193-
}
194-
}
195-
19688
public double getDecLatitude() {
19789
return decLatitude;
19890
}

0 commit comments

Comments
 (0)