mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Used CommonsApplication singleton to persist cache data
This commit is contained in:
parent
3d19d6be31
commit
0c15a3515b
3 changed files with 12 additions and 16 deletions
|
|
@ -1,11 +0,0 @@
|
|||
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();
|
||||
}
|
||||
|
|
@ -28,6 +28,8 @@ import org.apache.http.params.BasicHttpParams;
|
|||
import org.mediawiki.api.*;
|
||||
import org.apache.http.impl.client.*;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.data.*;
|
||||
|
||||
import com.android.volley.toolbox.*;
|
||||
|
|
@ -67,6 +69,8 @@ public class CommonsApplication extends Application {
|
|||
|
||||
public RequestQueue volleyQueue;
|
||||
|
||||
public CacheController cacheData;
|
||||
|
||||
public static AbstractHttpClient createHttpClient() {
|
||||
BasicHttpParams params = new BasicHttpParams();
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
|
|
@ -143,8 +147,11 @@ public class CommonsApplication extends Application {
|
|||
return bitmapSize / 1024;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
cacheData = new CacheController();
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class ShareActivity
|
|||
|
||||
private UploadController uploadController;
|
||||
|
||||
private CacheController cacheObj;
|
||||
private CommonsApplication cacheObj;
|
||||
|
||||
public ShareActivity() {
|
||||
super(WikiAccountAuthenticator.COMMONS_ACCOUNT_TYPE);
|
||||
|
|
@ -57,7 +57,7 @@ public class ShareActivity
|
|||
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
|
||||
startingToast.show();
|
||||
//Has to be called after apiCall.request()
|
||||
cacheObj.cacheCategory();
|
||||
cacheObj.cacheData.cacheCategory();
|
||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, new UploadController.ContributionUploadProgress() {
|
||||
public void onUploadStarted(Contribution contribution) {
|
||||
ShareActivity.this.contribution = contribution;
|
||||
|
|
@ -184,7 +184,7 @@ public class ShareActivity
|
|||
String filePath = uriObj.getFilePath();
|
||||
|
||||
//Using global singleton to get CacheController to last longer than the activity lifecycle
|
||||
CacheApplication cacheObj = ((CacheApplication)this.getApplication());
|
||||
cacheObj = ((CommonsApplication)this.getApplication());
|
||||
|
||||
|
||||
|
||||
|
|
@ -200,9 +200,9 @@ public class ShareActivity
|
|||
|
||||
if (decimalCoords != null) {
|
||||
Log.d("Coords", "Decimal coords of image: " + decimalCoords);
|
||||
cacheObj.data.setQtPoint(decLongitude, decLatitude);
|
||||
cacheObj.cacheData.setQtPoint(decLongitude, decLatitude);
|
||||
|
||||
cacheObj.data.findCategory();
|
||||
cacheObj.cacheData.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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue