Moved some code to ProgressDialogImpltementation
This commit is contained in:
parent
9470285d3f
commit
8db4893db8
2 changed files with 20 additions and 33 deletions
|
@ -14,6 +14,7 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
|
||||
private String taskName;
|
||||
private int progress;
|
||||
private int deltaProgress;
|
||||
private int work;
|
||||
private String message = ""; //$NON-NLS-1$
|
||||
|
||||
|
@ -116,9 +117,13 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
|
||||
@Override
|
||||
public void progress(int deltaWork) {
|
||||
this.progress += deltaWork;
|
||||
final int prg = progress;
|
||||
if (!isIndeterminate() && dialog != null) {
|
||||
this.deltaProgress += deltaWork;
|
||||
//update only each percent
|
||||
if ((deltaProgress > (work / 100)) || ((progress + deltaProgress) >= work)) {
|
||||
this.progress += deltaProgress;
|
||||
this.deltaProgress = 0;
|
||||
final int prg = progress;
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
|
@ -131,6 +136,7 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remaining(int remainingWork) {
|
||||
|
@ -182,6 +188,7 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
this.work = 1;
|
||||
}
|
||||
progress = 0;
|
||||
deltaProgress = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -89,24 +89,14 @@ public class DownloadFileHelper {
|
|||
}
|
||||
|
||||
first = false;
|
||||
int prg = 0;
|
||||
while ((read = is.read(buffer)) != -1) {
|
||||
if(interruptDownloading){
|
||||
throw new InterruptedException();
|
||||
}
|
||||
out.write(buffer, 0, read);
|
||||
if (length > -1) {
|
||||
prg += read;
|
||||
if (prg > length / 100) {
|
||||
progress.progress(prg);
|
||||
prg = 0;
|
||||
}
|
||||
}
|
||||
progress.progress(read);
|
||||
fileread += read;
|
||||
}
|
||||
if (prg > 0) {
|
||||
progress.progress(prg);
|
||||
}
|
||||
if(length <= fileread){
|
||||
triesDownload = 0;
|
||||
}
|
||||
|
@ -188,19 +178,9 @@ public class DownloadFileHelper {
|
|||
out = new FileOutputStream(fs);
|
||||
int read;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int prg = 0;
|
||||
while ((read = zipIn.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
if (size > -1) {
|
||||
prg += read;
|
||||
if (prg > size/100) {
|
||||
progress.progress(prg);
|
||||
prg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prg > 0) {
|
||||
progress.progress(prg);
|
||||
progress.progress(read);
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue