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