Never fallback to UIL for handling image downloads, only use for displaying.

Our `IconDownloader` extended `BaseImageDownloader` from UIL. There was an
explicit check in the F-Droid `IconDownloader` which looks for
HTTP/HTTPS/Bluetooth schemes. If it wasn't one of these, it fell back
to the base class. This was what was happening for local cached image
files. As such, when the `getInputStream(...)` method was refactored
to only use F-Droids `DownloadFactory` and not delegate to the base class,
it failed on local "file://" URLs.

This change introduces a `LocalFileDownloader` and makes the `DownloaderFactory`
aware of it.

The `BaseImageDownloader` class only provides support for the following schemes:

 * HTTP
 * HTTPS
 * File
 * Android content providers
 * Android assets
 * Android drawables

F-Droid now supports HTTP, HTTPS, and File URLs. There is not currently any
need for content proiders, assets or drawables to get icons for apps in F-Droid.
If there is a need in the future (e.g. an issue currently discusses loading
icons from installed apps if possible) then that specific `Downloader` can get
introduced to solve the problem.
This commit is contained in:
Peter Serwylo 2015-11-08 10:00:01 +11:00
parent 447dbe73ea
commit 1a5bd84fad
3 changed files with 64 additions and 10 deletions

View File

@ -48,9 +48,10 @@ public class DownloaderFactory {
if (isBluetoothAddress(url)) {
String macAddress = url.getHost().replace("-", ":");
return new BluetoothDownloader(context, macAddress, url, destFile);
}
if (isOnionAddress(url)) {
} else if (isOnionAddress(url)) {
return new TorHttpDownloader(context, url, destFile);
} else if (isLocalFile(url)) {
return new LocalFileDownloader(context, url, destFile);
}
return new HttpDownloader(context, url, destFile);
}
@ -59,6 +60,10 @@ public class DownloaderFactory {
return "bluetooth".equalsIgnoreCase(url.getProtocol());
}
static boolean isLocalFile(URL url) {
return "file".equalsIgnoreCase(url.getProtocol());
}
public static AsyncDownloader createAsync(Context context, String urlString, File destFile, String title, String id, AsyncDownloader.Listener listener) throws IOException {
return createAsync(context, new URL(urlString), destFile, title, id, listener);
}

View File

@ -2,19 +2,17 @@ package org.fdroid.fdroid.net;
import android.content.Context;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.core.download.ImageDownloader;
import java.io.IOException;
import java.io.InputStream;
public class IconDownloader extends BaseImageDownloader {
public class IconDownloader implements ImageDownloader {
private final Context context;
public IconDownloader(Context context) {
super(context);
}
public IconDownloader(Context context, int connectTimeout, int readTimeout) {
super(context, connectTimeout, readTimeout);
this.context = context;
}
@Override
@ -22,5 +20,4 @@ public class IconDownloader extends BaseImageDownloader {
return DownloaderFactory.create(context, imageUri).getInputStream();
}
}

View File

@ -0,0 +1,52 @@
package org.fdroid.fdroid.net;
import android.content.Context;
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 {
LocalFileDownloader(Context context, URL url, File destFile) throws FileNotFoundException, MalformedURLException {
super(context, url, destFile);
}
private File getFileToDownload() {
return new File(sourceUrl.getPath());
}
@Override
protected InputStream getDownloadersInputStream() throws IOException {
return new FileInputStream(getFileToDownload());
}
@Override
protected void close() throws IOException {
// Do nothing.
}
@Override
public boolean hasChanged() {
return false;
}
@Override
public int totalDownloadSize() {
return 0;
}
@Override
public void download() throws IOException, InterruptedException {
downloadFromStream(1024 * 50);
}
@Override
public boolean isCached() {
return false;
}
}