Skip to content

Commit

Permalink
Updated, Changed setListener to addListener
Browse files Browse the repository at this point in the history
  • Loading branch information
arefbhrn committed Dec 21, 2019
1 parent 539335c commit 3116679
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private Constants() {
// no instance
}

public static final int UPDATE = 0x01;
public static final String RANGE = "Range";
public static final String ETAG = "ETag";
public static final String USER_AGENT = "User-Agent";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.arefbhrn.eprdownloader.Response;
import com.arefbhrn.eprdownloader.Status;
import com.arefbhrn.eprdownloader.database.DownloadModel;
import com.arefbhrn.eprdownloader.handler.ProgressHandler;
import com.arefbhrn.eprdownloader.httpclient.HttpClient;
import com.arefbhrn.eprdownloader.internal.stream.FileDownloadOutputStream;
import com.arefbhrn.eprdownloader.internal.stream.FileDownloadRandomAccessFile;
Expand All @@ -36,7 +35,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.util.ArrayList;

/**
* Created by amitshekhar on 13/11/17.
Expand All @@ -49,7 +47,6 @@ public class DownloadTask {
private static final long TIME_GAP_FOR_SYNC = 2000;
private static final long MIN_BYTES_FOR_SYNC = 65536;
private final DownloadRequest request;
private ArrayList<ProgressHandler> progressHandlers = new ArrayList<>();
private long lastSyncTime;
private long lastSyncBytes;
private InputStream inputStream;
Expand Down Expand Up @@ -83,13 +80,6 @@ Response run() {

try {

progressHandlers.clear();
for (final OnProgressListener onProgressListener : request.getOnProgressListeners()) {
if (onProgressListener != null) {
progressHandlers.add(new ProgressHandler(onProgressListener));
}
}

tempPath = Utils.getTempPath(request.getDirPath(), request.getFileName());

File file = new File(tempPath);
Expand Down Expand Up @@ -312,12 +302,10 @@ private void removeNoMoreNeededModelFromDatabase() {

private void sendProgress() {
if (request.getStatus() != Status.CANCELLED) {
for (final ProgressHandler progressHandler : progressHandlers) {
if (progressHandler != null) {
progressHandler
.obtainMessage(Constants.UPDATE,
new Progress(request.getDownloadedBytes(),
totalBytes)).sendToTarget();
for (final OnProgressListener onProgressListener : request.getOnProgressListeners()) {
if (onProgressListener != null) {
Progress progress = new Progress(request.getDownloadedBytes(), totalBytes);
onProgressListener.onProgress(progress);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,27 +208,57 @@ public ArrayList<OnProgressListener> getOnProgressListeners() {
}

public DownloadRequest addOnDownloadListener(OnDownloadListener onDownloadListener) {
this.onDownloadListeners.add(onDownloadListener);
if (!this.onDownloadListeners.contains(onDownloadListener))
this.onDownloadListeners.add(onDownloadListener);
return this;
}

public DownloadRequest addOnStartOrResumeListener(OnStartOrResumeListener onStartOrResumeListeners) {
this.onStartOrResumeListeners.add(onStartOrResumeListeners);
public DownloadRequest addOnStartOrResumeListener(OnStartOrResumeListener onStartOrResumeListener) {
if (!this.onStartOrResumeListeners.contains(onStartOrResumeListener))
this.onStartOrResumeListeners.add(onStartOrResumeListener);
return this;
}

public DownloadRequest addOnProgressListener(OnProgressListener onProgressListeners) {
this.onProgressListeners.add(onProgressListeners);
public DownloadRequest addOnProgressListener(OnProgressListener onProgressListener) {
if (!this.onProgressListeners.contains(onProgressListener))
this.onProgressListeners.add(onProgressListener);
return this;
}

public DownloadRequest addOnPauseListener(OnPauseListener onPauseListeners) {
this.onPauseListeners.add(onPauseListeners);
public DownloadRequest addOnPauseListener(OnPauseListener onPauseListener) {
if (!this.onPauseListeners.contains(onPauseListener))
this.onPauseListeners.add(onPauseListener);
return this;
}

public DownloadRequest addOnCancelListener(OnCancelListener onCancelListeners) {
this.onCancelListeners.add(onCancelListeners);
public DownloadRequest addOnCancelListener(OnCancelListener onCancelListener) {
if (!this.onCancelListeners.contains(onCancelListener))
this.onCancelListeners.add(onCancelListener);
return this;
}

public DownloadRequest removeOnDownloadListener(OnDownloadListener onDownloadListener) {
this.onDownloadListeners.remove(onDownloadListener);
return this;
}

public DownloadRequest removeOnStartOrResumeListener(OnStartOrResumeListener onStartOrResumeListener) {
this.onStartOrResumeListeners.remove(onStartOrResumeListener);
return this;
}

public DownloadRequest removeOnProgressListener(OnProgressListener onProgressListener) {
this.onProgressListeners.remove(onProgressListener);
return this;
}

public DownloadRequest removeOnPauseListener(OnPauseListener onPauseListener) {
this.onPauseListeners.remove(onPauseListener);
return this;
}

public DownloadRequest removeOnCancelListener(OnCancelListener onCancelListener) {
this.onCancelListeners.remove(onCancelListener);
return this;
}

Expand Down

0 comments on commit 3116679

Please sign in to comment.