mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Added if cache found logic
This commit is contained in:
parent
0a33dc5dae
commit
85f0ae2a15
2 changed files with 21 additions and 10 deletions
|
|
@ -34,6 +34,7 @@ public class MwVolleyApi {
|
|||
private String coordsLog;
|
||||
|
||||
protected static Set<String> categorySet;
|
||||
private static List<String> categoryList;
|
||||
|
||||
private static final String MWURL = "https://commons.wikimedia.org/";
|
||||
|
||||
|
|
@ -44,8 +45,12 @@ public class MwVolleyApi {
|
|||
|
||||
//To get the list of categories for display
|
||||
public static List<String> getGpsCat() {
|
||||
List<String> list = new ArrayList<String>(categorySet);
|
||||
return list;
|
||||
categoryList = new ArrayList<String>(categorySet);
|
||||
return categoryList;
|
||||
}
|
||||
|
||||
public static void setGpsCat(List cachedList) {
|
||||
categoryList = new ArrayList<String>(cachedList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,8 +57,11 @@ 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.cacheData.cacheCategory();
|
||||
Log.d("Cache", "Cache the categories found");
|
||||
|
||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, new UploadController.ContributionUploadProgress() {
|
||||
public void onUploadStarted(Contribution contribution) {
|
||||
ShareActivity.this.contribution = contribution;
|
||||
|
|
@ -203,16 +206,19 @@ public class ShareActivity
|
|||
Log.d("Coords", "Decimal coords of image: " + decimalCoords);
|
||||
cacheObj.cacheData.setQtPoint(decLongitude, decLatitude);
|
||||
|
||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||
|
||||
List displayCatList = cacheObj.cacheData.findCategory();
|
||||
|
||||
//TODO: If categories found from cache in that area, skip API call and display those categories instead
|
||||
|
||||
//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);
|
||||
|
||||
//if no categories found in cache, call MW API to match image coords with nearby Commons categories
|
||||
if (displayCatList.size() == 0) {
|
||||
apiCall.request(decimalCoords);
|
||||
Log.d("Cache", "displayCatList size 0, calling MWAPI");
|
||||
} else {
|
||||
//TODO: Set categoryList in MwVolleyApi
|
||||
MwVolleyApi.setGpsCat(displayCatList);
|
||||
Log.d("Cache", "Cache found, setting categoryList in MwVolleyApi to " + displayCatList.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue