diff --git a/F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java b/F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java index 2ca730c25..579b3874c 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java +++ b/F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java @@ -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); } diff --git a/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java index c0389a390..943b23cb7 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java @@ -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(); } - } diff --git a/F-Droid/src/org/fdroid/fdroid/net/LocalFileDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/LocalFileDownloader.java new file mode 100644 index 000000000..3189c1740 --- /dev/null +++ b/F-Droid/src/org/fdroid/fdroid/net/LocalFileDownloader.java @@ -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; + } +}