Make most fields in AsyncDownloader final

This commit is contained in:
Daniel Martí 2015-09-11 15:48:21 -07:00
parent 0c9c93e493
commit b4e23c2cbc
4 changed files with 17 additions and 15 deletions

View File

@ -31,12 +31,11 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
private final Context context; private final Context context;
private final DownloadManager dm; private final DownloadManager dm;
private final LocalBroadcastManager localBroadcastManager; private final LocalBroadcastManager localBroadcastManager;
private File localFile; private final File localFile;
private String remoteAddress; private final String remoteAddress;
private String downloadTitle; private final String downloadTitle;
private String uniqueDownloadId; private final String uniqueDownloadId;
private Listener listener; private final Listener listener;
private Thread progressThread;
private boolean isCancelled; private boolean isCancelled;
private long downloadManagerId = -1; private long downloadManagerId = -1;
@ -50,7 +49,6 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
*/ */
public AsyncDownloaderFromAndroid(Context context, Listener listener, String downloadTitle, String downloadId, String remoteAddress, File localFile) { public AsyncDownloaderFromAndroid(Context context, Listener listener, String downloadTitle, String downloadId, String remoteAddress, File localFile) {
this.context = context; this.context = context;
this.downloadTitle = downloadTitle;
this.uniqueDownloadId = downloadId; this.uniqueDownloadId = downloadId;
this.remoteAddress = remoteAddress; this.remoteAddress = remoteAddress;
this.listener = listener; this.listener = listener;
@ -58,6 +56,8 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
if (TextUtils.isEmpty(downloadTitle)) { if (TextUtils.isEmpty(downloadTitle)) {
this.downloadTitle = remoteAddress; this.downloadTitle = remoteAddress;
} else {
this.downloadTitle = downloadTitle;
} }
dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
@ -101,11 +101,14 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
context.registerReceiver(receiver, context.registerReceiver(receiver,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
progressThread = new Thread() { Thread progressThread = new Thread() {
@Override @Override
public void run() { public void run() {
while (!isCancelled && isDownloading(context, uniqueDownloadId) >= 0) { while (!isCancelled && isDownloading(context, uniqueDownloadId) >= 0) {
try { Thread.sleep(1000); } catch (Exception e) {} try {
Thread.sleep(1000);
} catch (Exception e) {
}
sendProgress(getBytesRead(), getTotalBytes()); sendProgress(getBytesRead(), getTotalBytes());
} }
} }
@ -313,7 +316,7 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
/** /**
* Broadcast receiver to listen for ACTION_DOWNLOAD_COMPLETE broadcasts * Broadcast receiver to listen for ACTION_DOWNLOAD_COMPLETE broadcasts
*/ */
BroadcastReceiver receiver = new BroadcastReceiver() { final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {

View File

@ -156,8 +156,7 @@ public abstract class Downloader {
sendProgress(bytesRead, totalBytes); sendProgress(bytesRead, totalBytes);
while (bytesRead < totalBytes) { while (bytesRead < totalBytes) {
int count = -1; int count;
if (input.available()>0) { if (input.available()>0) {
int readLength = Math.min(input.available(), buffer.length); int readLength = Math.min(input.available(), buffer.length);

View File

@ -38,8 +38,7 @@ public class IconDownloader extends BaseImageDownloader {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = downloader.getInputStream(); InputStream is = downloader.getInputStream();
int b = -1; int b;
while ((b = is.read())!=-1) while ((b = is.read())!=-1)
baos.write(b); baos.write(b);

View File

@ -197,7 +197,8 @@ public class WifiStateChangeService extends Service {
InetAddress inetAddress = inetAddresses.nextElement(); InetAddress inetAddress = inetAddresses.nextElement();
if (inetAddress.isLoopbackAddress() || inetAddress instanceof Inet6Address) { if (inetAddress.isLoopbackAddress() || inetAddress instanceof Inet6Address) {
continue; continue;
} else if (netIf.getDisplayName().contains("wlan0") }
if (netIf.getDisplayName().contains("wlan0")
|| netIf.getDisplayName().contains("eth0") || netIf.getDisplayName().contains("eth0")
|| netIf.getDisplayName().contains("ap0")) { || netIf.getDisplayName().contains("ap0")) {
FDroidApp.ipAddressString = inetAddress.getHostAddress(); FDroidApp.ipAddressString = inetAddress.getHostAddress();