Initial download queue fragment. Update progress working
This commit is contained in:
@@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import eu.kanade.mangafeed.sources.base.Source;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
public class Download {
|
||||
public Source source;
|
||||
@@ -12,9 +13,38 @@ public class Download {
|
||||
public List<Page> pages;
|
||||
public File directory;
|
||||
|
||||
public transient volatile int totalProgress;
|
||||
private transient volatile int status;
|
||||
|
||||
private transient PublishSubject<Download> statusSubject;
|
||||
|
||||
public static final int QUEUE = 0;
|
||||
public static final int DOWNLOADING = 1;
|
||||
public static final int DOWNLOADED = 2;
|
||||
public static final int ERROR = 3;
|
||||
|
||||
|
||||
public Download(Source source, Manga manga, Chapter chapter) {
|
||||
this.source = source;
|
||||
this.manga = manga;
|
||||
this.chapter = chapter;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
notifyStatus();
|
||||
}
|
||||
|
||||
public void setStatusSubject(PublishSubject<Download> subject) {
|
||||
this.statusSubject = subject;
|
||||
}
|
||||
|
||||
private void notifyStatus() {
|
||||
if (statusSubject != null)
|
||||
statusSubject.onNext(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package eu.kanade.mangafeed.data.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
public class DownloadQueue {
|
||||
|
||||
private List<Download> queue;
|
||||
private PublishSubject<Download> statusSubject;
|
||||
|
||||
public DownloadQueue() {
|
||||
queue = new ArrayList<>();
|
||||
statusSubject = PublishSubject.create();
|
||||
}
|
||||
|
||||
public void add(Download download) {
|
||||
download.setStatusSubject(statusSubject);
|
||||
queue.add(download);
|
||||
}
|
||||
|
||||
public void remove(Download download) {
|
||||
queue.remove(download);
|
||||
download.setStatusSubject(null);
|
||||
}
|
||||
|
||||
public List<Download> get() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
public Observable<Download> getActiveDownloads() {
|
||||
return Observable.from(queue)
|
||||
.filter(download -> download.getStatus() == Download.DOWNLOADING);
|
||||
}
|
||||
|
||||
public Observable<Download> getStatusObservable() {
|
||||
return statusSubject
|
||||
.startWith(getActiveDownloads());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,8 +9,8 @@ public class Page implements NetworkHelper.ProgressListener {
|
||||
private String url;
|
||||
private String imageUrl;
|
||||
private String imagePath;
|
||||
private transient int status;
|
||||
private transient int progress;
|
||||
private transient volatile int status;
|
||||
private transient volatile int progress;
|
||||
|
||||
private transient BehaviorSubject<Integer> statusSubject;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user