okdownload
okdownload copied to clipboard
Get a list of all current downloads that are running? Finished Downloads, also
OkDownload Version
v1.0.2-SNAPSHOT
Problem Describe
How can I get a list of all current downloads that are running? Finished Downloads, also. The aim is to combine a list of objects from a server and others from current downloads, and combine them into one, This way users can play or view a file that is already downloaded, or show progress for currently downloading. Otherwise, they can start a download for objects that do not fall among the two.
Something like:
Observable<Map<String, DownloadInfo>> downloadList = RxPump.getAllDownloadList()
.concatMap(new Function<List<DownloadInfo>, ObservableSource<DownloadInfo>>() {
@Override
public ObservableSource<DownloadInfo> apply(List<DownloadInfo> downloadInfoList) {
return Observable.fromIterable(downloadInfoList);
}
})
.toMap(new Function<DownloadInfo, String>() {
@Override
public String apply(DownloadInfo downloadInfo) {
return downloadInfo.getId();
}
}).toObservable()
.subscribeOn(Schedulers.io());
Observable<List<Music>> musicListObservable = Network.getMusicList()
.subscribeOn(Schedulers.io());
disposable = Observable.zip(downloadList, musicListObservable,
new BiFunction<Map<String, DownloadInfo>, List<Music>, List<Music>>() {
@Override
public List<Music> apply(Map<String, DownloadInfo> downloadInfoMap, List<Music> musicList) {
for (Music music : musicList) {
String id = music.id;
music.downloadInfo = downloadInfoMap.get(id);
}
downloadingMusicList = DownloadingTaskStore.restoreDownloadingList();
return musicList;
}
}).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<Music>>() {
@Override
public void accept(List<Music> musicList) {
}
OkDownload Version
v1.0.2-SNAPSHOT
Problem Describe
How can I get a list of all current downloads that are running? Finished Downloads, also. The aim is to combine a list of objects from a server and others from current downloads, and combine them into one, This way users can play or view a file that is already downloaded, or show progress for currently downloading. Otherwise, they can start a download for objects that do not fall among the two.
Something like:
Observable<Map<String, DownloadInfo>> downloadList = RxPump.getAllDownloadList() .concatMap(new Function<List<DownloadInfo>, ObservableSource<DownloadInfo>>() { @Override public ObservableSource<DownloadInfo> apply(List<DownloadInfo> downloadInfoList) { return Observable.fromIterable(downloadInfoList); } }) .toMap(new Function<DownloadInfo, String>() { @Override public String apply(DownloadInfo downloadInfo) { return downloadInfo.getId(); } }).toObservable() .subscribeOn(Schedulers.io()); Observable<List<Music>> musicListObservable = Network.getMusicList() .subscribeOn(Schedulers.io()); disposable = Observable.zip(downloadList, musicListObservable, new BiFunction<Map<String, DownloadInfo>, List<Music>, List<Music>>() { @Override public List<Music> apply(Map<String, DownloadInfo> downloadInfoMap, List<Music> musicList) { for (Music music : musicList) { String id = music.id; music.downloadInfo = downloadInfoMap.get(id); } downloadingMusicList = DownloadingTaskStore.restoreDownloadingList(); return musicList; } }).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<List<Music>>() { @Override public void accept(List<Music> musicList) { }
Exactly there should be a simple query to get all the running, completed, failed tasks list so we can show and merge them in existing recycleview.