mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 01:59:19 +01:00
Remove chapters on a background thread.
This commit is contained in:
parent
8f7443a686
commit
8a3bb2b7ee
@ -395,7 +395,7 @@ public class DownloadManager {
|
|||||||
|
|
||||||
for (Download download : queue.get()) {
|
for (Download download : queue.get()) {
|
||||||
if (download.getStatus() != Download.DOWNLOADED) {
|
if (download.getStatus() != Download.DOWNLOADED) {
|
||||||
download.setStatus(Download.QUEUE);
|
if (download.getStatus() != Download.QUEUE) download.setStatus(Download.QUEUE);
|
||||||
if (!hasPendingDownloads) hasPendingDownloads = true;
|
if (!hasPendingDownloads) hasPendingDownloads = true;
|
||||||
downloadsQueueSubject.onNext(download);
|
downloadsQueueSubject.onNext(download);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
@ -35,6 +37,8 @@ import eu.kanade.mangafeed.util.ToastUtil;
|
|||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Subscription;
|
import rx.Subscription;
|
||||||
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
@RequiresPresenter(ChaptersPresenter.class)
|
@RequiresPresenter(ChaptersPresenter.class)
|
||||||
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
|
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
|
||||||
@ -192,10 +196,10 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
holder.onProgressChange(getContext(), download.downloadedImages, download.pages.size());
|
holder.onProgressChange(getContext(), download.downloadedImages, download.pages.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChapterStatusChange(Download download) {
|
public void onChapterStatusChange(Chapter chapter) {
|
||||||
ChaptersHolder holder = getHolder(download.chapter);
|
ChaptersHolder holder = getHolder(chapter);
|
||||||
if (holder != null)
|
if (holder != null)
|
||||||
holder.onStatusChange(download.getStatus());
|
holder.onStatusChange(chapter.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -240,8 +244,13 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Observable<Chapter> getSelectedChapters() {
|
private Observable<Chapter> getSelectedChapters() {
|
||||||
return Observable.from(adapter.getSelectedItems())
|
// Create a blocking copy of the selected chapters.
|
||||||
.map(adapter::getItem);
|
// When the action mode is closed the list is cleared. If we use background
|
||||||
|
// threads with this observable, some emissions could be lost.
|
||||||
|
List<Chapter> chapters = Observable.from(adapter.getSelectedItems())
|
||||||
|
.map(adapter::getItem).toList().toBlocking().single();
|
||||||
|
|
||||||
|
return Observable.from(chapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeActionMode() {
|
public void closeActionMode() {
|
||||||
@ -268,13 +277,45 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
|
|
||||||
protected boolean onDownload(Observable<Chapter> chapters) {
|
protected boolean onDownload(Observable<Chapter> chapters) {
|
||||||
DownloadService.start(getActivity());
|
DownloadService.start(getActivity());
|
||||||
getPresenter().downloadChapters(chapters);
|
|
||||||
|
Observable<Chapter> observable = chapters
|
||||||
|
.doOnNext(chapter -> {
|
||||||
|
// Force update of the UI. We already receive updates when it's added to the queue,
|
||||||
|
// but sometimes it does nothing.
|
||||||
|
// TODO remove this when status updates works properly
|
||||||
|
chapter.status = Download.QUEUE;
|
||||||
|
onChapterStatusChange(chapter);
|
||||||
|
});
|
||||||
|
|
||||||
|
getPresenter().downloadChapters(observable);
|
||||||
closeActionMode();
|
closeActionMode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean onDelete(Observable<Chapter> chapters) {
|
protected boolean onDelete(Observable<Chapter> chapters) {
|
||||||
getPresenter().deleteChapters(chapters);
|
int size = adapter.getSelectedItemCount();
|
||||||
|
|
||||||
|
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
|
||||||
|
.title(R.string.deleting)
|
||||||
|
.progress(false, size, true)
|
||||||
|
.cancelable(false)
|
||||||
|
.show();
|
||||||
|
|
||||||
|
Observable<Chapter> observable = chapters
|
||||||
|
.concatMap(chapter -> {
|
||||||
|
getPresenter().deleteChapter(chapter);
|
||||||
|
return Observable.just(chapter);
|
||||||
|
})
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext(chapter -> {
|
||||||
|
dialog.incrementProgress(1);
|
||||||
|
chapter.status = Download.NOT_DOWNLOADED;
|
||||||
|
onChapterStatusChange(chapter);
|
||||||
|
})
|
||||||
|
.finallyDo(dialog::dismiss);
|
||||||
|
|
||||||
|
getPresenter().deleteChapters(observable);
|
||||||
closeActionMode();
|
closeActionMode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
|
|
||||||
restartableLatestCache(CHAPTER_STATUS_CHANGES,
|
restartableLatestCache(CHAPTER_STATUS_CHANGES,
|
||||||
this::getChapterStatusObs,
|
this::getChapterStatusObs,
|
||||||
(view, download) -> view.onChapterStatusChange(download),
|
(view, download) -> view.onChapterStatusChange(download.chapter),
|
||||||
(view, error) -> Timber.e(error.getCause(), error.getMessage()));
|
(view, error) -> Timber.e(error.getCause(), error.getMessage()));
|
||||||
|
|
||||||
registerForStickyEvents();
|
registerForStickyEvents();
|
||||||
@ -210,10 +210,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
public void deleteChapters(Observable<Chapter> selectedChapters) {
|
public void deleteChapters(Observable<Chapter> selectedChapters) {
|
||||||
add(selectedChapters
|
add(selectedChapters
|
||||||
.subscribe(chapter -> {
|
.subscribe(chapter -> {
|
||||||
// Somehow I can't delete files on Schedulers.io()
|
|
||||||
downloadManager.deleteChapter(source, manga, chapter);
|
|
||||||
downloadManager.getQueue().remove(chapter);
|
downloadManager.getQueue().remove(chapter);
|
||||||
chapter.status = Download.NOT_DOWNLOADED;
|
|
||||||
}, error -> {
|
}, error -> {
|
||||||
Timber.e(error.getMessage());
|
Timber.e(error.getMessage());
|
||||||
}, () -> {
|
}, () -> {
|
||||||
@ -222,6 +219,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteChapter(Chapter chapter) {
|
||||||
|
downloadManager.deleteChapter(source, manga, chapter);
|
||||||
|
}
|
||||||
|
|
||||||
public void revertSortOrder() {
|
public void revertSortOrder() {
|
||||||
//TODO manga.chapter_order
|
//TODO manga.chapter_order
|
||||||
sortOrderAToZ = !sortOrderAToZ;
|
sortOrderAToZ = !sortOrderAToZ;
|
||||||
|
@ -60,7 +60,7 @@ public class SettingsCacheFragment extends SettingsNestedFragment implements Pre
|
|||||||
File[] files = cacheManager.getCacheDir().listFiles();
|
File[] files = cacheManager.getCacheDir().listFiles();
|
||||||
|
|
||||||
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
|
MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
|
||||||
.title(R.string.deleting_files)
|
.title(R.string.deleting)
|
||||||
.progress(false, files.length, true)
|
.progress(false, files.length, true)
|
||||||
.cancelable(false)
|
.cancelable(false)
|
||||||
.dismissListener(d -> {
|
.dismissListener(d -> {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<string name="button_cancel">Cancel</string>
|
<string name="button_cancel">Cancel</string>
|
||||||
|
|
||||||
<!-- Operations -->
|
<!-- Operations -->
|
||||||
<string name="deleting_files">Deleting files…</string>
|
<string name="deleting">Deleting…</string>
|
||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
|
|
||||||
<!-- Preferences -->
|
<!-- Preferences -->
|
||||||
|
Loading…
Reference in New Issue
Block a user