mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Added global singleton
to keep Quadtree data across activity lifecycle
This commit is contained in:
parent
920da3b592
commit
3d19d6be31
3 changed files with 19 additions and 6 deletions
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
@ -18,12 +18,11 @@ public class CacheController {
|
||||||
private Point[] pointsFound;
|
private Point[] pointsFound;
|
||||||
|
|
||||||
public CacheController() {
|
public CacheController() {
|
||||||
|
quadTree = new QuadTree(-180, -90, +180, +90);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initQuadTree(double decLongitude, double decLatitude) {
|
public void setQtPoint(double decLongitude, double decLatitude) {
|
||||||
quadTree = new QuadTree(-180, -90, +180, +90);
|
|
||||||
x = decLongitude;
|
x = decLongitude;
|
||||||
y = decLatitude;
|
y = decLatitude;
|
||||||
Log.d("Cache", "New QuadTree created");
|
Log.d("Cache", "New QuadTree created");
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,10 @@ public class ShareActivity
|
||||||
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
|
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
|
||||||
String filePath = uriObj.getFilePath();
|
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) {
|
if (filePath != null) {
|
||||||
//extract the coordinates of image in decimal degrees
|
//extract the coordinates of image in decimal degrees
|
||||||
|
|
@ -197,9 +200,9 @@ public class ShareActivity
|
||||||
|
|
||||||
if (decimalCoords != null) {
|
if (decimalCoords != null) {
|
||||||
Log.d("Coords", "Decimal coords of image: " + decimalCoords);
|
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
|
//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
|
//asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue