mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Further improve image loading, and remove unused code.
This commit is contained in:
parent
a9d58d4757
commit
85b15cd1c1
3 changed files with 18 additions and 21 deletions
|
|
@ -84,7 +84,6 @@ public class CommonsApplication extends Application {
|
|||
private AbstractHttpClient httpClient = null;
|
||||
private MWApi api = null;
|
||||
private CacheController cacheData = null;
|
||||
private RequestQueue volleyQueue = null;
|
||||
private DBOpenHelper dbOpenHelper = null;
|
||||
private NearbyPlaces nearbyPlaces = null;
|
||||
|
||||
|
|
@ -139,15 +138,6 @@ public class CommonsApplication extends Application {
|
|||
return cacheData;
|
||||
}
|
||||
|
||||
public RequestQueue getVolleyQueue() {
|
||||
if (volleyQueue == null) {
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
}
|
||||
return volleyQueue;
|
||||
}
|
||||
|
||||
public synchronized DBOpenHelper getDBOpenHelper() {
|
||||
if (dbOpenHelper == null) {
|
||||
dbOpenHelper = new DBOpenHelper(this);
|
||||
|
|
@ -190,12 +180,7 @@ public class CommonsApplication extends Application {
|
|||
cacheData = new CacheController();
|
||||
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
}
|
||||
|
||||
public MWApi getApi() {
|
||||
return api;
|
||||
new RequestQueue(cache, new BasicNetwork(new HurlStack())).start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -262,15 +247,14 @@ public class CommonsApplication extends Application {
|
|||
preferences.edit().clear().commit();
|
||||
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
|
||||
preferences.edit().putBoolean("firstrun", false).apply();
|
||||
updateAllDatabases(context);
|
||||
updateAllDatabases();
|
||||
currentAccount = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all tables and re-creates them.
|
||||
* @param context context
|
||||
*/
|
||||
public void updateAllDatabases(Context context) {
|
||||
public void updateAllDatabases() {
|
||||
DBOpenHelper dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
|
||||
dbOpenHelper.getReadableDatabase().close();
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mediawiki.api.ApiResult;
|
||||
|
||||
class MediaThumbnailFetchTask extends AsyncTask<String, String, String> {
|
||||
private static final String THUMB_SIZE = "640";
|
||||
protected final Media media;
|
||||
|
||||
public MediaThumbnailFetchTask(@NonNull Media media) {
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.AttributeSet;
|
||||
|
|
@ -27,15 +28,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
if (currentThumbnailTask != null) {
|
||||
currentThumbnailTask.cancel(true);
|
||||
}
|
||||
setImageURI((String) null);
|
||||
if(media == null) {
|
||||
setImageURI((String) null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thumbnailUrlCache.get(media.getFilename()) != null) {
|
||||
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
|
||||
} else {
|
||||
currentThumbnailTask = new ThumbnailFetchTask();
|
||||
setImageURI((String) null);
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
}
|
||||
|
|
@ -53,11 +55,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
}
|
||||
|
||||
private class ThumbnailFetchTask extends MediaThumbnailFetchTask {
|
||||
ThumbnailFetchTask(@NonNull Media media) {
|
||||
super(media);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if (isCancelled()) {
|
||||
return;
|
||||
}
|
||||
thumbnailUrlCache.put(media.getFilename(), result);
|
||||
setImageUrl(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue