This commit is contained in:
Martin Fietz 2016-04-12 11:39:46 +02:00
parent 9b563c1c87
commit 93eba24d08
2 changed files with 9 additions and 16 deletions

View File

@ -53,8 +53,7 @@ public class DownloadLogAdapter extends BaseAdapter {
holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.type = (TextView) convertView.findViewById(R.id.txtvType);
holder.reason = (TextView) convertView
.findViewById(R.id.txtvReason);
holder.reason = (TextView) convertView.findViewById(R.id.txtvReason);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();

View File

@ -219,21 +219,18 @@ public class HttpDownloader extends Downloader {
long freeSpace = StorageUtils.getFreeSpaceAvailable();
Log.d(TAG, "Free space is " + freeSpace);
if (request.getSize() != DownloadStatus.SIZE_UNKNOWN
&& request.getSize() > freeSpace) {
if (request.getSize() != DownloadStatus.SIZE_UNKNOWN && request.getSize() > freeSpace) {
onFail(DownloadError.ERROR_NOT_ENOUGH_SPACE, null);
return;
}
Log.d(TAG, "Starting download");
try {
while (!cancelled
&& (count = connection.read(buffer)) != -1) {
while (!cancelled && (count = connection.read(buffer)) != -1) {
out.write(buffer, 0, count);
request.setSoFar(request.getSoFar() + count);
request.setProgressPercent((int) (((double) request
.getSoFar() / (double) request
.getSize()) * 100));
int progressPercent = (int)(100.0 * request.getSoFar() / request.getSize());
request.setProgressPercent(progressPercent);
}
} catch(IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
@ -245,12 +242,8 @@ public class HttpDownloader extends Downloader {
// written file. This check cannot be made if compression was used
if (!isGzip && request.getSize() != DownloadStatus.SIZE_UNKNOWN &&
request.getSoFar() != request.getSize()) {
onFail(DownloadError.ERROR_IO_ERROR,
"Download completed but size: " +
request.getSoFar() +
" does not equal expected size " +
request.getSize()
);
onFail(DownloadError.ERROR_IO_ERROR, "Download completed but size: " +
request.getSoFar() + " does not equal expected size " + request.getSize());
return;
} else if(request.getSize() > 0 && request.getSoFar() == 0){
onFail(DownloadError.ERROR_IO_ERROR, "Download completed, but nothing was read");
@ -294,7 +287,8 @@ public class HttpDownloader extends Downloader {
}
private void onFail(DownloadError reason, String reasonDetailed) {
Log.d(TAG, "Download failed");
Log.d(TAG, "onFail() called with: " + "reason = [" + reason + "], " +
"reasonDetailed = [" + reasonDetailed + "]");
result.setFailed(reason, reasonDetailed);
if (request.isDeleteOnFailure()) {
cleanup();