diff --git a/commons/src/main/java/fr/free/nrw/commons/CacheApplication.java b/commons/src/main/java/fr/free/nrw/commons/CacheApplication.java new file mode 100644 index 000000000..edd279d6f --- /dev/null +++ b/commons/src/main/java/fr/free/nrw/commons/CacheApplication.java @@ -0,0 +1,11 @@ +package fr.free.nrw.commons; + +import android.app.Application; + +import fr.free.nrw.commons.caching.CacheController; + + +public class CacheApplication extends Application +{ + public CacheController data = new CacheController(); +} \ No newline at end of file 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 2152f780d..453b8d66f 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 @@ -18,12 +18,11 @@ public class CacheController { private Point[] pointsFound; public CacheController() { - + quadTree = new QuadTree(-180, -90, +180, +90); } - public void initQuadTree(double decLongitude, double decLatitude) { - quadTree = new QuadTree(-180, -90, +180, +90); + public void setQtPoint(double decLongitude, double decLatitude) { x = decLongitude; y = decLatitude; Log.d("Cache", "New QuadTree created"); 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 86ac2eca3..651b3be36 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 @@ -183,7 +183,10 @@ public class ShareActivity FilePathConverter uriObj = new FilePathConverter(this, mediaUri); String filePath = uriObj.getFilePath(); - cacheObj = new CacheController(); + //Using global singleton to get CacheController to last longer than the activity lifecycle + CacheApplication cacheObj = ((CacheApplication)this.getApplication()); + + if (filePath != null) { //extract the coordinates of image in decimal degrees @@ -197,9 +200,9 @@ public class ShareActivity if (decimalCoords != null) { Log.d("Coords", "Decimal coords of image: " + decimalCoords); - cacheObj.initQuadTree(decLongitude, decLatitude); + cacheObj.data.setQtPoint(decLongitude, decLatitude); - cacheObj.findCategory(); + cacheObj.data.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