Attempting real categories cache

This commit is contained in:
misaochan 2016-01-06 16:11:57 +13:00
parent 5f44ba2975
commit a527425baa
3 changed files with 40 additions and 21 deletions

View file

@ -6,6 +6,8 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import fr.free.nrw.commons.upload.MwVolleyApi;
public class CacheController {
private Context context;
@ -15,15 +17,15 @@ public class CacheController {
private List<String> categoryList;
private Point[] pointsFound;
public CacheController(Context context, double decLongitude, double decLatitude) {
this.context = context;
x = decLongitude;
y = decLatitude;
public CacheController() {
}
public void initQuadTree() {
public void initQuadTree(double decLongitude, double decLatitude) {
quadTree = new QuadTree(-180, -90, +180, +90);
x = decLongitude;
y = decLatitude;
Log.d("Cache", "New QuadTree created");
Log.d("Cache", "X (longitude) value: " + x + ", Y (latitude) value: " + y);
}
@ -31,25 +33,36 @@ public class CacheController {
public void cacheCategory() {
//TODO: Remove later, only setting categories manually for debugging
categoryList = new ArrayList<String>();
categoryList.add("UK");
categoryList.add("US");
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) {
categoryList = new ArrayList<String>(MwVolleyApi.getGpsCat());
Log.d("Cache", "Categories being cached: " + categoryList);
} else {
Log.d("Cache", "No categories found, so no categories cached");
}
//categoryList = new ArrayList<String>();
//categoryList.add("UK");
//categoryList.add("US");
quadTree.set(x, y, categoryList);
}
public void findCategory() {
//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", "Points found in quadtree: " + pointsFound);
if (pointsFound != null) {
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());
} else {
Log.d("Cache", "No categories found in cache");
}
Log.d("Cache", "Categories found: " + cat.toString());
}
}

View file

@ -24,6 +24,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import fr.free.nrw.commons.caching.CacheController;
public class MwVolleyApi {
private static RequestQueue REQUEST_QUEUE;

View file

@ -47,6 +47,8 @@ public class ShareActivity
private UploadController uploadController;
private CacheController cacheObj;
public ShareActivity() {
super(WikiAccountAuthenticator.COMMONS_ACCOUNT_TYPE);
}
@ -54,6 +56,8 @@ public class ShareActivity
public void uploadActionInitiated(String title, String description) {
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
startingToast.show();
//Has to be called after apiCall.request()
cacheObj.cacheCategory();
uploadController.startUpload(title, mediaUri, description, mimeType, source, new UploadController.ContributionUploadProgress() {
public void onUploadStarted(Contribution contribution) {
ShareActivity.this.contribution = contribution;
@ -179,6 +183,8 @@ public class ShareActivity
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
String filePath = uriObj.getFilePath();
cacheObj = new CacheController();
if (filePath != null) {
//extract the coordinates of image in decimal degrees
Log.d("Image", "Calling GPSExtractor");
@ -191,10 +197,8 @@ public class ShareActivity
if (decimalCoords != null) {
Log.d("Coords", "Decimal coords of image: " + decimalCoords);
cacheObj.initQuadTree(decLongitude, decLatitude);
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
@ -202,7 +206,7 @@ public class ShareActivity
MwVolleyApi apiCall = new MwVolleyApi(this);
apiCall.request(decimalCoords);
//TODO: Set Category object for this point
}
}