implemented IconDownloader for UIL downloads with FDroid classes
This lets UniversalImageLoader (UIL) use FDroid's generic Downloader infrastucture so that connection configuration all happens based on the URL in DownloaderFactory. refs #2598 https://dev.guardianproject.info/issues/2598 refs #2367 https://dev.guardianproject.info/issues/2367
This commit is contained in:
parent
d19e77049a
commit
c1b5bf5279
@ -47,6 +47,7 @@ import org.fdroid.fdroid.data.AppProvider;
|
|||||||
import org.fdroid.fdroid.data.InstalledAppCacheUpdater;
|
import org.fdroid.fdroid.data.InstalledAppCacheUpdater;
|
||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoService;
|
import org.fdroid.fdroid.localrepo.LocalRepoService;
|
||||||
|
import org.fdroid.fdroid.net.IconDownloader;
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||||
import org.thoughtcrime.ssl.pinning.PinningTrustManager;
|
import org.thoughtcrime.ssl.pinning.PinningTrustManager;
|
||||||
import org.thoughtcrime.ssl.pinning.SystemKeyStore;
|
import org.thoughtcrime.ssl.pinning.SystemKeyStore;
|
||||||
@ -152,7 +153,8 @@ public class FDroidApp extends Application {
|
|||||||
bluetoothAdapter = getBluetoothAdapter();
|
bluetoothAdapter = getBluetoothAdapter();
|
||||||
|
|
||||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
|
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
|
||||||
.discCache(new LimitedAgeDiscCache(
|
.imageDownloader(new IconDownloader(getApplicationContext()))
|
||||||
|
.diskCache(new LimitedAgeDiscCache(
|
||||||
new File(StorageUtils.getCacheDirectory(getApplicationContext(), true),
|
new File(StorageUtils.getCacheDirectory(getApplicationContext(), true),
|
||||||
"icons"),
|
"icons"),
|
||||||
null,
|
null,
|
||||||
|
@ -41,6 +41,8 @@ public class HttpDownloader extends Downloader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
|
setupConnection();
|
||||||
|
// TODO check out BaseImageDownloader.getStreamFromNetwork() for optims
|
||||||
return connection.getInputStream();
|
return connection.getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ public class HttpDownloader extends Downloader {
|
|||||||
@Override
|
@Override
|
||||||
public void download() throws IOException, InterruptedException {
|
public void download() throws IOException, InterruptedException {
|
||||||
try {
|
try {
|
||||||
connection = (HttpURLConnection) sourceUrl.openConnection();
|
setupConnection();
|
||||||
doDownload();
|
doDownload();
|
||||||
} catch (SSLHandshakeException e) {
|
} catch (SSLHandshakeException e) {
|
||||||
// TODO this should be handled better, it is not internationalised here
|
// TODO this should be handled better, it is not internationalised here
|
||||||
@ -65,6 +67,12 @@ public class HttpDownloader extends Downloader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setupConnection() throws IOException {
|
||||||
|
if (connection != null)
|
||||||
|
return;
|
||||||
|
connection = (HttpURLConnection) sourceUrl.openConnection();
|
||||||
|
}
|
||||||
|
|
||||||
protected void doDownload() throws IOException, InterruptedException {
|
protected void doDownload() throws IOException, InterruptedException {
|
||||||
if (wantToCheckCache()) {
|
if (wantToCheckCache()) {
|
||||||
setupCacheCheck();
|
setupCacheCheck();
|
||||||
|
32
src/org/fdroid/fdroid/net/IconDownloader.java
Normal file
32
src/org/fdroid/fdroid/net/IconDownloader.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class IconDownloader extends BaseImageDownloader {
|
||||||
|
|
||||||
|
public IconDownloader(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconDownloader(Context context, int connectTimeout, int readTimeout) {
|
||||||
|
super(context, connectTimeout, readTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getStream(String imageUri, Object extra) throws IOException {
|
||||||
|
switch (Scheme.ofUri(imageUri)) {
|
||||||
|
case HTTP:
|
||||||
|
case HTTPS:
|
||||||
|
Downloader downloader = DownloaderFactory.create(imageUri, context);
|
||||||
|
return downloader.getInputStream();
|
||||||
|
default:
|
||||||
|
return super.getStream(imageUri, extra);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -13,8 +12,6 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
|
||||||
|
|
||||||
public class TorHttpDownloader extends HttpDownloader {
|
public class TorHttpDownloader extends HttpDownloader {
|
||||||
|
|
||||||
TorHttpDownloader(String url, Context ctx) throws IOException {
|
TorHttpDownloader(String url, Context ctx) throws IOException {
|
||||||
@ -27,19 +24,9 @@ public class TorHttpDownloader extends HttpDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download() throws IOException, InterruptedException {
|
protected void setupConnection() throws IOException {
|
||||||
try {
|
|
||||||
SocketAddress sa = new InetSocketAddress("127.0.0.1", 8118);
|
SocketAddress sa = new InetSocketAddress("127.0.0.1", 8118);
|
||||||
Proxy tor = new Proxy(Proxy.Type.HTTP, sa);
|
Proxy tor = new Proxy(Proxy.Type.HTTP, sa);
|
||||||
connection = (HttpURLConnection) sourceUrl.openConnection(tor);
|
connection = (HttpURLConnection) sourceUrl.openConnection(tor);
|
||||||
doDownload();
|
|
||||||
} catch (SSLHandshakeException e) {
|
|
||||||
throw new IOException(
|
|
||||||
"A problem occurred while establishing an SSL " +
|
|
||||||
"connection. If this problem persists, AND you have a " +
|
|
||||||
"very old device, you could try using http instead of " +
|
|
||||||
"https for the repo URL." + Log.getStackTraceString(e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user