Improve image loading performance by using UniversalImageLoader to background the task
Doing this required tweaking our `IconDownloader` which we give to the UIL init method in FDroidApp. It only knew how to load from HTTP, but we needed it to fetch `drawable://` images too (which the library supports). In addition, it has been renamed `ImageDownloader` as it also is now used for screenshots/feature images.
This commit is contained in:
parent
7796a3f374
commit
e4766645eb
@ -58,7 +58,7 @@ import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.InstalledAppProviderService;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.installer.InstallHistoryService;
|
||||
import org.fdroid.fdroid.net.IconDownloader;
|
||||
import org.fdroid.fdroid.net.ImageLoaderForUIL;
|
||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||
|
||||
import java.net.URL;
|
||||
@ -280,7 +280,7 @@ public class FDroidApp extends Application {
|
||||
bluetoothAdapter = getBluetoothAdapter();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
|
||||
.imageDownloader(new IconDownloader(getApplicationContext()))
|
||||
.imageDownloader(new ImageLoaderForUIL(getApplicationContext()))
|
||||
.diskCache(new LimitedAgeDiskCache(
|
||||
Utils.getIconsCacheDir(this),
|
||||
null,
|
||||
|
@ -2,16 +2,20 @@ package org.fdroid.fdroid.net;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.nostra13.universalimageloader.core.download.ImageDownloader;
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class IconDownloader implements ImageDownloader {
|
||||
/**
|
||||
* Class used by the Universal Image Loader library (UIL) to fetch images for displaying in F-Droid.
|
||||
* See {@link org.fdroid.fdroid.FDroidApp} for where this gets configured.
|
||||
*/
|
||||
public class ImageLoaderForUIL implements com.nostra13.universalimageloader.core.download.ImageDownloader {
|
||||
|
||||
private final Context context;
|
||||
|
||||
public IconDownloader(Context context) {
|
||||
public ImageLoaderForUIL(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@ -20,8 +24,13 @@ public class IconDownloader implements ImageDownloader {
|
||||
switch (Scheme.ofUri(imageUri)) {
|
||||
case ASSETS:
|
||||
return context.getAssets().open(Scheme.ASSETS.crop(imageUri));
|
||||
|
||||
case DRAWABLE:
|
||||
return new BaseImageDownloader(context).getStream(imageUri, extra);
|
||||
|
||||
default:
|
||||
return DownloaderFactory.create(context, imageUri).getInputStream();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
@ -20,6 +21,11 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
@ -36,6 +42,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
||||
|
||||
private final Activity activity;
|
||||
private final LoaderManager loaderManager;
|
||||
private final DisplayImageOptions displayImageOptions;
|
||||
|
||||
private String currentCategory;
|
||||
|
||||
@ -57,6 +64,13 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
||||
RecyclerView appCards = (RecyclerView) itemView.findViewById(R.id.app_cards);
|
||||
appCards.setAdapter(appCardsAdapter);
|
||||
appCards.addItemDecoration(new ItemDecorator(activity));
|
||||
|
||||
displayImageOptions = new DisplayImageOptions.Builder()
|
||||
.cacheInMemory(true)
|
||||
.imageScaleType(ImageScaleType.NONE)
|
||||
.displayer(new FadeInBitmapDisplayer(100, true, true, false))
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.build();
|
||||
}
|
||||
|
||||
void bindModel(@NonNull String categoryName) {
|
||||
@ -78,7 +92,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade
|
||||
image.setVisibility(View.GONE);
|
||||
} else {
|
||||
image.setVisibility(View.VISIBLE);
|
||||
image.setImageDrawable(ContextCompat.getDrawable(activity, categoryImageId));
|
||||
ImageLoader.getInstance().displayImage("drawable://" + categoryImageId, image, displayImageOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user