Minor changes

This commit is contained in:
inorichi 2016-01-25 13:19:03 +01:00
parent a54425f47d
commit 27b95e9d73
4 changed files with 39 additions and 25 deletions

View File

@ -24,6 +24,7 @@ import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga;
import eu.kanade.tachiyomi.data.download.DownloadService;
import eu.kanade.tachiyomi.data.download.model.Download;
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
@ -71,26 +72,14 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
// Init RecyclerView and adapter
linearLayout = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayout);
recyclerView.addItemDecoration(new DividerItemDecoration(ContextCompat.getDrawable(getContext(), R.drawable.line_divider)));
recyclerView.addItemDecoration(new DividerItemDecoration(
ContextCompat.getDrawable(getContext(), R.drawable.line_divider)));
recyclerView.setHasFixedSize(true);
adapter = new ChaptersAdapter(this);
recyclerView.setAdapter(adapter);
// Set initial values
setReadFilter();
setDownloadedFilter();
setSortIcon();
// Init listeners
swipeRefresh.setOnRefreshListener(this::fetchChapters);
readCb.setOnCheckedChangeListener((arg, isChecked) ->
getPresenter().setReadFilter(isChecked));
downloadedCb.setOnCheckedChangeListener((v, isChecked) ->
getPresenter().setDownloadedFilter(isChecked));
sortBtn.setOnClickListener(v -> {
getPresenter().revertSortOrder();
setSortIcon();
});
nextUnreadBtn.setOnClickListener(v -> {
Chapter chapter = getPresenter().getNextUnreadChapter();
if (chapter != null) {
@ -103,6 +92,28 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
return view;
}
public void onNextManga(Manga manga) {
// Remove listeners before setting the values
readCb.setOnCheckedChangeListener(null);
downloadedCb.setOnCheckedChangeListener(null);
sortBtn.setOnClickListener(null);
// Set initial values
setReadFilter();
setDownloadedFilter();
setSortIcon();
// Init listeners
readCb.setOnCheckedChangeListener((arg, isChecked) ->
getPresenter().setReadFilter(isChecked));
downloadedCb.setOnCheckedChangeListener((v, isChecked) ->
getPresenter().setDownloadedFilter(isChecked));
sortBtn.setOnClickListener(v -> {
getPresenter().revertSortOrder();
setSortIcon();
});
}
public void onNextChapters(List<Chapter> chapters) {
// If the list is empty, fetch chapters from source if the conditions are met
// We use presenter chapters instead because they are always unfiltered

View File

@ -45,9 +45,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
private PublishSubject<List<Chapter>> chaptersSubject;
private static final int DB_CHAPTERS = 1;
private static final int FETCH_CHAPTERS = 2;
private static final int CHAPTER_STATUS_CHANGES = 3;
private static final int GET_MANGA = 1;
private static final int DB_CHAPTERS = 2;
private static final int FETCH_CHAPTERS = 3;
private static final int CHAPTER_STATUS_CHANGES = 4;
@Override
protected void onCreate(Bundle savedState) {
@ -59,6 +60,10 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
chaptersSubject = PublishSubject.create();
restartableLatestCache(GET_MANGA,
() -> Observable.just(manga),
ChaptersFragment::onNextManga);
restartableLatestCache(DB_CHAPTERS,
this::getDbChaptersObs,
ChaptersFragment::onNextChapters);
@ -77,6 +82,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
}
private void onProcessRestart() {
stop(GET_MANGA);
stop(DB_CHAPTERS);
stop(FETCH_CHAPTERS);
stop(CHAPTER_STATUS_CHANGES);
@ -92,6 +98,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
@EventBusHook
public void onEventMainThread(MangaEvent event) {
this.manga = event.manga;
start(GET_MANGA);
if (isUnsubscribed(DB_CHAPTERS)) {
source = sourceManager.get(manga.source);

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.manga.info;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -63,9 +62,7 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
return view;
}
public void onNextManga(Pair<Manga,Source> info) {
Manga manga = info.first;
Source source = info.second;
public void onNextManga(Manga manga, Source source) {
if (manga.initialized) {
setMangaInfo(manga, source);
} else {

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.manga.info;
import android.os.Bundle;
import android.util.Pair;
import javax.inject.Inject;
@ -41,8 +40,8 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
}
restartableLatestCache(GET_MANGA,
() -> Observable.just(new Pair<>(manga, source)),
MangaInfoFragment::onNextManga);
() -> Observable.just(manga),
(view, manga) -> view.onNextManga(manga, source));
restartableLatestCache(GET_CHAPTER_COUNT,
() -> Observable.just(count),