use FileInputStream for file:// URLs when UIL loads images
This saves the levels of indirection that leads to a FileInputStream being created in LocalFileDownloader. Since there are already special cases for assets:// and drawable://, it seems a natural place to put the file:// case. Also, since this is used to load icons when scrolling through lists of apps, this is particularly sensitive to inefficient loading. This also removes custom code that UIL provides better.
This commit is contained in:
parent
b10fa425b5
commit
44fcfd36f9
@ -3,7 +3,6 @@ package org.fdroid.fdroid.net;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
@ -41,11 +40,9 @@ public class DownloaderFactory {
|
||||
localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
||||
}
|
||||
|
||||
if (isBluetoothAddress(url)) {
|
||||
if ("bluetooth".equalsIgnoreCase(url.getProtocol())) {
|
||||
String macAddress = url.getHost().replace("-", ":");
|
||||
downloader = new BluetoothDownloader(macAddress, url, destFile);
|
||||
} else if (isLocalFile(url)) {
|
||||
downloader = new LocalFileDownloader(url, destFile);
|
||||
} else {
|
||||
final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD};
|
||||
Repo repo = RepoProvider.Helper.findByUrl(context, Uri.parse(url.toString()), projection);
|
||||
@ -57,12 +54,4 @@ public class DownloaderFactory {
|
||||
}
|
||||
return downloader;
|
||||
}
|
||||
|
||||
private static boolean isBluetoothAddress(URL url) {
|
||||
return "bluetooth".equalsIgnoreCase(url.getProtocol());
|
||||
}
|
||||
|
||||
private static boolean isLocalFile(URL url) {
|
||||
return "file".equalsIgnoreCase(url.getProtocol());
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package org.fdroid.fdroid.net;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Class used by the Universal Image Loader library (UIL) to fetch images for
|
||||
* displaying in F-Droid. A custom subclass is needed since F-Droid's
|
||||
* {@link HttpDownloader} provides support for Tor, proxying, and automatic
|
||||
* mirror failover.
|
||||
*
|
||||
* @see org.fdroid.fdroid.FDroidApp#onCreate() for where this is setup
|
||||
*/
|
||||
public class ImageLoaderForUIL implements com.nostra13.universalimageloader.core.download.ImageDownloader {
|
||||
|
||||
@ -22,15 +25,10 @@ public class ImageLoaderForUIL implements com.nostra13.universalimageloader.core
|
||||
@Override
|
||||
public InputStream getStream(String imageUri, Object extra) throws IOException {
|
||||
switch (Scheme.ofUri(imageUri)) {
|
||||
case ASSETS:
|
||||
return context.getAssets().open(Scheme.ASSETS.crop(imageUri));
|
||||
|
||||
case DRAWABLE:
|
||||
return new BaseImageDownloader(context).getStream(imageUri, extra);
|
||||
|
||||
default:
|
||||
case HTTP:
|
||||
case HTTPS:
|
||||
return DownloaderFactory.create(context, imageUri).getInputStream();
|
||||
}
|
||||
return new BaseImageDownloader(context).getStream(imageUri, extra);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
package org.fdroid.fdroid.net;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class LocalFileDownloader extends Downloader {
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
LocalFileDownloader(URL url, File destFile) throws FileNotFoundException, MalformedURLException {
|
||||
super(url, destFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getDownloadersInputStream() throws IOException {
|
||||
inputStream = new FileInputStream(new File(sourceUrl.getPath()));
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void close() {
|
||||
if (inputStream != null) {
|
||||
Utils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChanged() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int totalDownloadSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download() throws IOException, InterruptedException {
|
||||
if (new File(sourceUrl.getPath()).exists()) {
|
||||
downloadFromStream(1024 * 50, false);
|
||||
} else {
|
||||
notFound = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user