diff --git a/commons/src/main/java/fr/free/nrw/commons/caching/CacheController.java b/commons/src/main/java/fr/free/nrw/commons/caching/CacheController.java index 1f2244bf8..6a125e8c4 100644 --- a/commons/src/main/java/fr/free/nrw/commons/caching/CacheController.java +++ b/commons/src/main/java/fr/free/nrw/commons/caching/CacheController.java @@ -9,15 +9,23 @@ import android.util.Log; public class CacheController { private Context context; - private String coords; + private double decLongitude; + private double decLatitude; + private QuadTree quadTree; + private String category = "test"; - public CacheController(Context context, String coords) { + public CacheController(Context context, double decLongitude, double decLatitude) { this.context = context; - this.coords = coords; + this.decLongitude = decLongitude; + this.decLatitude = decLatitude; + } - public String getCoords() { - Log.d("Cache", "Coords passed to cache: " + coords); - return coords; + + public void callQuadTree() { + quadTree = new QuadTree(-180, -90, +180, +90); + Log.d("Cache", "New QuadTree created"); + Log.d("Cache", "X (longitude) value: " + decLongitude + ", Y (latitude) value: " + decLatitude); + quadTree.set(decLongitude, decLatitude, category); } } diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index e699fe067..28685353d 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -9,6 +9,7 @@ import java.io.IOException; public class GPSExtractor { private String filePath; + private double decLatitude, decLongitude; public GPSExtractor(String filePath){ this.filePath = filePath; @@ -56,10 +57,18 @@ public class GPSExtractor { } } + public double getDecLatitude() { + return decLatitude; + } + + public double getDecLongitude() { + return decLongitude; + } + //Converts format of coords into decimal coords as required by MediaWiki API private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) { - double decLatitude, decLongitude; + if(latitude_ref.equals("N")){ decLatitude = convertToDegree(latitude); diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java b/commons/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java index 3ba4a8b1a..8e6b6ae75 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java @@ -185,16 +185,16 @@ public class ShareActivity GPSExtractor imageObj = new GPSExtractor(filePath); //decimalCoords for MediaWiki API, xyCoords for Quadtree String decimalCoords = imageObj.getCoords(false); - String xyCoords = imageObj.getCoords(true); + + double decLongitude = imageObj.getDecLongitude(); + double decLatitude = imageObj.getDecLatitude(); if (decimalCoords != null) { Log.d("Coords", "Decimal coords of image: " + decimalCoords); - Log.d("Coords", "XY coords of image: " + xyCoords); //TODO: Insert cache query here, only send API request if no cached categories - CacheController cacheObj = new CacheController(this, xyCoords); - cacheObj.getCoords(); - + CacheController cacheObj = new CacheController(this, decLongitude, decLatitude); + cacheObj.callQuadTree(); //asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories MwVolleyApi apiCall = new MwVolleyApi(this);