From 27b95e9d73cb004a95f081792e1d3b0cd1ec6183 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 25 Jan 2016 13:19:03 +0100 Subject: [PATCH] Minor changes --- .../ui/manga/chapter/ChaptersFragment.java | 41 ++++++++++++------- .../ui/manga/chapter/ChaptersPresenter.java | 13 ++++-- .../ui/manga/info/MangaInfoFragment.java | 5 +-- .../ui/manga/info/MangaInfoPresenter.java | 5 +-- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java index ce0a685577..6fb96fa16d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java @@ -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 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 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 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index 38051672e1..b87e35093b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java @@ -45,9 +45,10 @@ public class ChaptersPresenter extends BasePresenter { private PublishSubject> 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 { 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 { } 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 { @EventBusHook public void onEventMainThread(MangaEvent event) { this.manga = event.manga; + start(GET_MANGA); if (isUnsubscribed(DB_CHAPTERS)) { source = sourceManager.get(manga.source); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java index 236d0a1ad8..bee8651f45 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.java @@ -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 { return view; } - public void onNextManga(Pair info) { - Manga manga = info.first; - Source source = info.second; + public void onNextManga(Manga manga, Source source) { if (manga.initialized) { setMangaInfo(manga, source); } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java index dbd4410e2f..ea69a76fcd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.java @@ -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 { } 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),