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 f7cd202cb..205fb458a 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 @@ -12,22 +12,23 @@ import java.util.List; public class CacheController { private Context context; - private double decLongitude; - private double decLatitude; + private double x; + private double y; private QuadTree quadTree; private List categoryList; + private Point[] pointsFound; public CacheController(Context context, double decLongitude, double decLatitude) { this.context = context; - this.decLongitude = decLongitude; - this.decLatitude = decLatitude; + x = decLongitude; + y = decLatitude; } public void initQuadTree() { quadTree = new QuadTree(-180, -90, +180, +90); Log.d("Cache", "New QuadTree created"); - Log.d("Cache", "X (longitude) value: " + decLongitude + ", Y (latitude) value: " + decLatitude); + Log.d("Cache", "X (longitude) value: " + x + ", Y (latitude) value: " + y); } @@ -37,11 +38,21 @@ public class CacheController { categoryList = new ArrayList(); categoryList.add("UK"); categoryList.add("US"); - quadTree.set(decLongitude, decLatitude, categoryList); + quadTree.set(x, y, categoryList); } public void findCategory() { - //TODO: Convert decLatitude and decLongitude to a range - quadTree.searchWithin(final double xmin, final double ymin, final double xmax, final double ymax); + //TODO: Convert decLatitude and decLongitude to a range with proper formula, for testing just use 10 + pointsFound = quadTree.searchWithin(x-10, y-10, x+10, y+10); + Log.d("Cache", "Points found: " + pointsFound.toString()); + double x; + Object cat = null; + //TODO: This does not truly iterate, just for testing. In future probably need to store results in Array + for (Point point: pointsFound) { + x = point.getX(); + cat = point.getValue(); + } + Log.d("Cache", "Categories found: " + cat.toString()); + } } 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 94e60627f..303777834 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 @@ -194,6 +194,8 @@ public class ShareActivity CacheController cacheObj = new CacheController(this, decLongitude, decLatitude); cacheObj.initQuadTree(); + cacheObj.cacheCategory(); + cacheObj.findCategory(); //TODO: If no categories found from cache in that area, call MW API //asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories