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.date = (TextView) convertView.findViewById(R.id.txtvDate);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.type = (TextView) convertView.findViewById(R.id.txtvType); holder.type = (TextView) convertView.findViewById(R.id.txtvType);
holder.reason = (TextView) convertView holder.reason = (TextView) convertView.findViewById(R.id.txtvReason);
.findViewById(R.id.txtvReason);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();

View File

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