Browse Source

Minor changes

inorichi 9 years ago
parent
commit
27b95e9d73

+ 23 - 12
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,18 +72,38 @@ 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);
 
+        swipeRefresh.setOnRefreshListener(this::fetchChapters);
+
+        nextUnreadBtn.setOnClickListener(v -> {
+            Chapter chapter = getPresenter().getNextUnreadChapter();
+            if (chapter != null) {
+                openChapter(chapter);
+            } else {
+                ToastUtil.showShort(getContext(), R.string.no_next_chapter);
+            }
+        });
+
+        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
-        swipeRefresh.setOnRefreshListener(this::fetchChapters);
         readCb.setOnCheckedChangeListener((arg, isChecked) ->
                 getPresenter().setReadFilter(isChecked));
         downloadedCb.setOnCheckedChangeListener((v, isChecked) ->
@@ -91,16 +112,6 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
             getPresenter().revertSortOrder();
             setSortIcon();
         });
-        nextUnreadBtn.setOnClickListener(v -> {
-            Chapter chapter = getPresenter().getNextUnreadChapter();
-            if (chapter != null) {
-                openChapter(chapter);
-            } else {
-                ToastUtil.showShort(getContext(), R.string.no_next_chapter);
-            }
-        });
-
-        return view;
     }
 
     public void onNextChapters(List<Chapter> chapters) {

+ 10 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java

@@ -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);

+ 1 - 4
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<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 {

+ 2 - 3
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<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),