diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java index 9c908e7a7..8e87b4347 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java @@ -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()); - } } diff --git a/app/src/main/java/org/fdroid/fdroid/net/ImageLoaderForUIL.java b/app/src/main/java/org/fdroid/fdroid/net/ImageLoaderForUIL.java index 508d9df06..883c2d9d2 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/ImageLoaderForUIL.java +++ b/app/src/main/java/org/fdroid/fdroid/net/ImageLoaderForUIL.java @@ -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); } - } diff --git a/app/src/main/java/org/fdroid/fdroid/net/LocalFileDownloader.java b/app/src/main/java/org/fdroid/fdroid/net/LocalFileDownloader.java deleted file mode 100644 index d9d85e5d6..000000000 --- a/app/src/main/java/org/fdroid/fdroid/net/LocalFileDownloader.java +++ /dev/null @@ -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; - } - } -}