Setting up cacheCategory() and findCategory()

This commit is contained in:
misaochan 2016-01-05 19:24:43 +13:00
parent 74dcd9df8f
commit e311753988
2 changed files with 24 additions and 6 deletions

View file

@ -3,6 +3,9 @@ package fr.free.nrw.commons.caching;
import android.content.Context;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
/**
* Created by misao on 05-Jan-16.
*/
@ -12,20 +15,33 @@ public class CacheController {
private double decLongitude;
private double decLatitude;
private QuadTree quadTree;
private String category = "test";
private List<String> categoryList;
public CacheController(Context context, double decLongitude, double decLatitude) {
this.context = context;
this.decLongitude = decLongitude;
this.decLatitude = decLatitude;
}
public void callQuadTree() {
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);
quadTree.set(decLongitude, decLatitude, category);
}
public void cacheCategory() {
//TODO: Remove later, only setting categories manually for debugging
categoryList = new ArrayList<String>();
categoryList.add("UK");
categoryList.add("US");
quadTree.set(decLongitude, decLatitude, 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);
}
}

View file

@ -192,13 +192,15 @@ public class ShareActivity
if (decimalCoords != null) {
Log.d("Coords", "Decimal coords of image: " + decimalCoords);
//TODO: Insert cache query here, only send API request if no cached categories
CacheController cacheObj = new CacheController(this, decLongitude, decLatitude);
cacheObj.callQuadTree();
cacheObj.initQuadTree();
//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
MwVolleyApi apiCall = new MwVolleyApi(this);
apiCall.request(decimalCoords);
//TODO: Set Category object for this point
}
}