mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 13:51:50 +01:00
Improve the refresh of chapter filters
This commit is contained in:
parent
ab216a3608
commit
b986309b81
@ -340,7 +340,6 @@ public class DownloadManager {
|
|||||||
public void deleteChapter(Source source, Manga manga, Chapter chapter) {
|
public void deleteChapter(Source source, Manga manga, Chapter chapter) {
|
||||||
File path = getAbsoluteChapterDirectory(source, manga, chapter);
|
File path = getAbsoluteChapterDirectory(source, manga, chapter);
|
||||||
DiskUtils.deleteFiles(path);
|
DiskUtils.deleteFiles(path);
|
||||||
queue.remove(chapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadQueue getQueue() {
|
public DownloadQueue getQueue() {
|
||||||
|
@ -35,12 +35,13 @@ import eu.kanade.mangafeed.util.EventBusHook;
|
|||||||
import eu.kanade.mangafeed.util.ToastUtil;
|
import eu.kanade.mangafeed.util.ToastUtil;
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
@RequiresPresenter(ChaptersPresenter.class)
|
@RequiresPresenter(ChaptersPresenter.class)
|
||||||
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
|
public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implements
|
||||||
ActionMode.Callback, ChaptersAdapter.OnItemClickListener {
|
ActionMode.Callback, ChaptersAdapter.OnItemClickListener {
|
||||||
|
|
||||||
@Bind(R.id.chapter_list) RecyclerView chapters;
|
@Bind(R.id.chapter_list) RecyclerView recyclerView;
|
||||||
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
|
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
|
||||||
@Bind(R.id.toolbar_bottom) Toolbar toolbarBottom;
|
@Bind(R.id.toolbar_bottom) Toolbar toolbarBottom;
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
@Bind(R.id.action_show_downloaded) CheckBox downloadedCb;
|
@Bind(R.id.action_show_downloaded) CheckBox downloadedCb;
|
||||||
|
|
||||||
private ChaptersAdapter adapter;
|
private ChaptersAdapter adapter;
|
||||||
|
private LinearLayoutManager linearLayout;
|
||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
|
|
||||||
public static ChaptersFragment newInstance() {
|
public static ChaptersFragment newInstance() {
|
||||||
@ -61,7 +62,6 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
public void onCreate(Bundle savedState) {
|
public void onCreate(Bundle savedState) {
|
||||||
super.onCreate(savedState);
|
super.onCreate(savedState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
getPresenter().setIsCatalogueManga(isCatalogueManga());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,10 +72,11 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
// Init RecyclerView and adapter
|
// Init RecyclerView and adapter
|
||||||
chapters.setLayoutManager(new LinearLayoutManager(getActivity()));
|
linearLayout = new LinearLayoutManager(getActivity());
|
||||||
chapters.addItemDecoration(new DividerItemDecoration(ContextCompat.getDrawable(this.getContext(), R.drawable.line_divider)));
|
recyclerView.setLayoutManager(linearLayout);
|
||||||
|
recyclerView.addItemDecoration(new DividerItemDecoration(ContextCompat.getDrawable(getContext(), R.drawable.line_divider)));
|
||||||
adapter = new ChaptersAdapter(this);
|
adapter = new ChaptersAdapter(this);
|
||||||
chapters.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
// Set initial values
|
// Set initial values
|
||||||
setReadFilter();
|
setReadFilter();
|
||||||
@ -133,13 +134,18 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onNextChapters(List<Chapter> chapters) {
|
public void onNextChapters(List<Chapter> chapters) {
|
||||||
|
if (chapters.isEmpty() && isCatalogueManga()) {
|
||||||
|
swipeRefresh.setRefreshing(true);
|
||||||
|
getPresenter().fetchChaptersFromSource();
|
||||||
|
}
|
||||||
|
|
||||||
closeActionMode();
|
closeActionMode();
|
||||||
adapter.setItems(chapters);
|
adapter.setItems(chapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFetchChapters() {
|
public void onFetchChapters() {
|
||||||
swipeRefresh.setRefreshing(true);
|
swipeRefresh.setRefreshing(true);
|
||||||
getPresenter().fetchChapters();
|
getPresenter().fetchChaptersFromSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFetchChaptersFinish() {
|
public void onFetchChaptersFinish() {
|
||||||
@ -163,11 +169,13 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
|
|||||||
if (manga != null && !event.getChapter().manga_id.equals(manga.id))
|
if (manga != null && !event.getChapter().manga_id.equals(manga.id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
getPresenter().updateChapterStatus(event);
|
||||||
|
|
||||||
Chapter chapter;
|
Chapter chapter;
|
||||||
for (int i = 0; i < adapter.getItemCount(); i++) {
|
for (int i = linearLayout.findFirstVisibleItemPosition(); i < linearLayout.findLastVisibleItemPosition(); i++) {
|
||||||
chapter = adapter.getItem(i);
|
int pos = recyclerView.getChildAdapterPosition(linearLayout.findViewByPosition(i));
|
||||||
|
chapter = adapter.getItem(pos);
|
||||||
if (event.getChapter().id.equals(chapter.id)) {
|
if (event.getChapter().id.equals(chapter.id)) {
|
||||||
chapter.status = event.getStatus();
|
|
||||||
adapter.notifyItemChanged(i);
|
adapter.notifyItemChanged(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import eu.kanade.mangafeed.data.source.SourceManager;
|
|||||||
import eu.kanade.mangafeed.data.source.base.Source;
|
import eu.kanade.mangafeed.data.source.base.Source;
|
||||||
import eu.kanade.mangafeed.event.ChapterCountEvent;
|
import eu.kanade.mangafeed.event.ChapterCountEvent;
|
||||||
import eu.kanade.mangafeed.event.DownloadChaptersEvent;
|
import eu.kanade.mangafeed.event.DownloadChaptersEvent;
|
||||||
|
import eu.kanade.mangafeed.event.DownloadStatusEvent;
|
||||||
import eu.kanade.mangafeed.event.ReaderEvent;
|
import eu.kanade.mangafeed.event.ReaderEvent;
|
||||||
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
||||||
import eu.kanade.mangafeed.util.EventBusHook;
|
import eu.kanade.mangafeed.util.EventBusHook;
|
||||||
@ -25,6 +26,7 @@ import rx.Observable;
|
|||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
||||||
|
|
||||||
@ -36,7 +38,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
private Manga manga;
|
private Manga manga;
|
||||||
private Source source;
|
private Source source;
|
||||||
private List<Chapter> chapters;
|
private List<Chapter> chapters;
|
||||||
private boolean isCatalogueManga;
|
|
||||||
private boolean sortOrderAToZ = true;
|
private boolean sortOrderAToZ = true;
|
||||||
private boolean onlyUnread = true;
|
private boolean onlyUnread = true;
|
||||||
private boolean onlyDownloaded;
|
private boolean onlyDownloaded;
|
||||||
@ -83,7 +84,9 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
|
|
||||||
@EventBusHook
|
@EventBusHook
|
||||||
public void onEventMainThread(Manga manga) {
|
public void onEventMainThread(Manga manga) {
|
||||||
if (this.manga == null) {
|
if (this.manga != null)
|
||||||
|
return;
|
||||||
|
|
||||||
this.manga = manga;
|
this.manga = manga;
|
||||||
source = sourceManager.get(manga.source);
|
source = sourceManager.get(manga.source);
|
||||||
start(DB_CHAPTERS);
|
start(DB_CHAPTERS);
|
||||||
@ -93,20 +96,21 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
.doOnNext(chapters -> {
|
.doOnNext(chapters -> {
|
||||||
this.chapters = chapters;
|
this.chapters = chapters;
|
||||||
EventBus.getDefault().postSticky(new ChapterCountEvent(chapters.size()));
|
EventBus.getDefault().postSticky(new ChapterCountEvent(chapters.size()));
|
||||||
|
for (Chapter chapter : chapters) {
|
||||||
|
setChapterStatus(chapter);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.subscribe(chaptersSubject::onNext));
|
.subscribe(chaptersSubject::onNext));
|
||||||
|
|
||||||
// Get chapters if it's an online source
|
|
||||||
if (isCatalogueManga) {
|
|
||||||
fetchChapters();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchChapters() {
|
public void fetchChaptersFromSource() {
|
||||||
start(FETCH_CHAPTERS);
|
start(FETCH_CHAPTERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshChapters() {
|
||||||
|
chaptersSubject.onNext(chapters);
|
||||||
|
}
|
||||||
|
|
||||||
private Observable<PostResult> getOnlineChaptersObs() {
|
private Observable<PostResult> getOnlineChaptersObs() {
|
||||||
return source
|
return source
|
||||||
.pullChaptersFromNetwork(manga.url)
|
.pullChaptersFromNetwork(manga.url)
|
||||||
@ -127,8 +131,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
if (onlyUnread) {
|
if (onlyUnread) {
|
||||||
observable = observable.filter(chapter -> !chapter.read);
|
observable = observable.filter(chapter -> !chapter.read);
|
||||||
}
|
}
|
||||||
|
|
||||||
observable = observable.doOnNext(this::setChapterStatus);
|
|
||||||
if (onlyDownloaded) {
|
if (onlyDownloaded) {
|
||||||
observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED);
|
observable = observable.filter(chapter -> chapter.status == Download.DOWNLOADED);
|
||||||
}
|
}
|
||||||
@ -156,6 +158,17 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateChapterStatus(DownloadStatusEvent event) {
|
||||||
|
for (Chapter chapter : chapters) {
|
||||||
|
if (event.getChapter().id.equals(chapter.id)) {
|
||||||
|
chapter.status = event.getStatus();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (onlyDownloaded && event.getStatus() == Download.DOWNLOADED)
|
||||||
|
refreshChapters();
|
||||||
|
}
|
||||||
|
|
||||||
public void onOpenChapter(Chapter chapter) {
|
public void onOpenChapter(Chapter chapter) {
|
||||||
EventBus.getDefault().postSticky(new ReaderEvent(source, manga, chapter));
|
EventBus.getDefault().postSticky(new ReaderEvent(source, manga, chapter));
|
||||||
}
|
}
|
||||||
@ -190,30 +203,33 @@ 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.deleteChapter(source, manga, chapter);
|
||||||
|
downloadManager.getQueue().remove(chapter);
|
||||||
chapter.status = Download.NOT_DOWNLOADED;
|
chapter.status = Download.NOT_DOWNLOADED;
|
||||||
|
}, error -> {
|
||||||
|
Timber.e(error.getMessage());
|
||||||
|
}, () -> {
|
||||||
|
if (onlyDownloaded)
|
||||||
|
refreshChapters();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revertSortOrder() {
|
public void revertSortOrder() {
|
||||||
//TODO manga.chapter_order
|
//TODO manga.chapter_order
|
||||||
sortOrderAToZ = !sortOrderAToZ;
|
sortOrderAToZ = !sortOrderAToZ;
|
||||||
chaptersSubject.onNext(chapters);
|
refreshChapters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReadFilter(boolean onlyUnread) {
|
public void setReadFilter(boolean onlyUnread) {
|
||||||
//TODO do we need save filter for manga?
|
//TODO do we need save filter for manga?
|
||||||
this.onlyUnread = onlyUnread;
|
this.onlyUnread = onlyUnread;
|
||||||
chaptersSubject.onNext(chapters);
|
refreshChapters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadedFilter(boolean onlyDownloaded) {
|
public void setDownloadedFilter(boolean onlyDownloaded) {
|
||||||
this.onlyDownloaded = onlyDownloaded;
|
this.onlyDownloaded = onlyDownloaded;
|
||||||
chaptersSubject.onNext(chapters);
|
refreshChapters();
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsCatalogueManga(boolean value) {
|
|
||||||
isCatalogueManga = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSortOrder() {
|
public boolean getSortOrder() {
|
||||||
|
Loading…
Reference in New Issue
Block a user