Minor changes

This commit is contained in:
inorichi 2015-12-02 11:53:32 +01:00
parent 96f6e28c68
commit ab48686262
4 changed files with 18 additions and 16 deletions

View file

@ -340,6 +340,7 @@ public class DownloadManager {
public void deleteChapter(Source source, Manga manga, Chapter chapter) {
File path = getAbsoluteChapterDirectory(source, manga, chapter);
DiskUtils.deleteFiles(path);
queue.remove(chapter);
}
public DownloadQueue getQueue() {

View file

@ -35,7 +35,6 @@ public class Download {
this.source = source;
this.manga = manga;
this.chapter = chapter;
this.status = QUEUE;
}
public int getStatus() {

View file

@ -3,7 +3,7 @@ package eu.kanade.mangafeed.data.download.model;
import java.util.ArrayList;
import java.util.List;
import eu.kanade.mangafeed.data.download.model.Download;
import eu.kanade.mangafeed.data.database.models.Chapter;
import rx.Observable;
import rx.subjects.PublishSubject;
@ -19,14 +19,25 @@ public class DownloadQueue {
public void add(Download download) {
download.setStatusSubject(statusSubject);
download.setStatus(Download.QUEUE);
queue.add(download);
}
public void remove(Download download) {
queue.remove(download);
download.setStatus(Download.NOT_DOWNLOADED);
download.setStatusSubject(null);
}
public void remove(Chapter chapter) {
for (Download download : queue) {
if (download.chapter.id == chapter.id) {
remove(download);
break;
}
}
}
public List<Download> get() {
return queue;
}

View file

@ -22,7 +22,6 @@ import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
import eu.kanade.mangafeed.util.EventBusHook;
import eu.kanade.mangafeed.util.PostResult;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
@ -42,10 +41,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
private static final int DB_CHAPTERS = 1;
private static final int FETCH_CHAPTERS = 2;
private Subscription markReadSubscription;
private Subscription downloadSubscription;
private Subscription deleteSubscription;
@Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
@ -128,7 +123,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
}
public void markChaptersRead(Observable<Chapter> selectedChapters, boolean read) {
add(markReadSubscription = selectedChapters
add(selectedChapters
.subscribeOn(Schedulers.io())
.map(chapter -> {
chapter.read = read;
@ -138,27 +133,23 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
.toList()
.flatMap(chapters -> db.insertChapters(chapters).createObservable())
.observeOn(AndroidSchedulers.mainThread())
.doOnCompleted(() -> remove(markReadSubscription))
.subscribe(result -> {
}));
.subscribe());
}
public void downloadChapters(Observable<Chapter> selectedChapters) {
add(downloadSubscription = selectedChapters
add(selectedChapters
.toList()
.subscribe(chapters -> {
EventBus.getDefault().postSticky(new DownloadChaptersEvent(manga, chapters));
remove(downloadSubscription);
}));
}
public void deleteChapters(Observable<Chapter> selectedChapters) {
deleteSubscription = selectedChapters
.doOnCompleted(() -> remove(deleteSubscription))
add(selectedChapters
.subscribe(chapter -> {
downloadManager.deleteChapter(source, manga, chapter);
chapter.status = Download.NOT_DOWNLOADED;
});
}));
}