Show chapter count

This commit is contained in:
inorichi 2015-10-19 17:27:41 +02:00
parent 9ad6efbada
commit 0c77a7034a
6 changed files with 71 additions and 17 deletions

View File

@ -8,11 +8,14 @@ import java.util.List;
import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
import eu.kanade.mangafeed.data.helpers.SourceManager;
import eu.kanade.mangafeed.data.models.Chapter;
import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.ui.fragment.MangaChaptersFragment;
import eu.kanade.mangafeed.util.EventBusHook;
import eu.kanade.mangafeed.util.events.ChapterCountEvent;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
@ -34,7 +37,10 @@ public class MangaChaptersPresenter extends BasePresenter<MangaChaptersFragment>
restartableLatestCache(DB_CHAPTERS,
this::getDbChaptersObs,
MangaChaptersFragment::onNextChapters
(view, chapters) -> {
view.onNextChapters(chapters);
EventBus.getDefault().postSticky(new ChapterCountEvent(chapters.size()));
}
);
restartableLatestCache(ONLINE_CHAPTERS,
@ -55,6 +61,7 @@ public class MangaChaptersPresenter extends BasePresenter<MangaChaptersFragment>
super.onDropView();
}
@EventBusHook
public void onEventMainThread(Manga manga) {
if (this.manga == null) {
this.manga = manga;

View File

@ -1,20 +1,42 @@
package eu.kanade.mangafeed.presenter;
import android.os.Bundle;
import javax.inject.Inject;
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.ui.fragment.MangaInfoFragment;
import eu.kanade.mangafeed.util.EventBusHook;
import eu.kanade.mangafeed.util.events.ChapterCountEvent;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
@Inject DatabaseHelper db;
private Manga manga;
private Subscription mangaInfoSubscription;
private int count = -1;
private static final int GET_MANGA = 1;
private static final int GET_CHAPTER_COUNT = 2;
@Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
restartableLatestCache(GET_MANGA,
() -> Observable.just(manga),
MangaInfoFragment::setMangaInfo);
restartableLatestCache(GET_CHAPTER_COUNT,
() -> Observable.just(count),
MangaInfoFragment::setChapterCount);
}
@Override
protected void onTakeView(MangaInfoFragment view) {
@ -28,18 +50,20 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
super.onDropView();
}
@EventBusHook
public void onEventMainThread(Manga manga) {
if (!manga.equals(this.manga)) {
this.manga = manga;
getMangaInfo();
start(GET_MANGA);
}
}
private void getMangaInfo() {
if (mangaInfoSubscription != null)
remove(mangaInfoSubscription);
@EventBusHook
public void onEventMainThread(ChapterCountEvent event) {
if (count != event.getCount()) {
count = event.getCount();
start(GET_CHAPTER_COUNT);
}
}
add(mangaInfoSubscription = Observable.just(manga)
.observeOn(AndroidSchedulers.mainThread())
.compose(deliverLatestCache())
.subscribe(split(MangaInfoFragment::setMangaInfo)));
}
}

View File

@ -27,7 +27,7 @@ import uk.co.ribot.easyadapter.EasyRecyclerAdapter;
public class MangaChaptersFragment extends BaseFragment<MangaChaptersPresenter> {
@Bind(R.id.chapter_list) RecyclerView chapters;
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipe_refresh;
@Bind(R.id.swipe_refresh) SwipeRefreshLayout swipeRefresh;
private EasyRecyclerAdapter<Chapter> adapter;
@ -77,7 +77,7 @@ public class MangaChaptersFragment extends BaseFragment<MangaChaptersPresenter>
}
private void setSwipeRefreshListener() {
swipe_refresh.setOnRefreshListener(() -> getPresenter().refreshChapters(this));
swipeRefresh.setOnRefreshListener(() -> getPresenter().refreshChapters(this));
}
public void onNextChapters(List<Chapter> chapters) {
@ -85,10 +85,10 @@ public class MangaChaptersFragment extends BaseFragment<MangaChaptersPresenter>
}
public void onNextOnlineChapters() {
swipe_refresh.setRefreshing(false);
swipeRefresh.setRefreshing(false);
}
public void setSwipeRefreshing() {
swipe_refresh.setRefreshing(true);
swipeRefresh.setRefreshing(true);
}
}

View File

@ -50,7 +50,6 @@ public class MangaInfoFragment extends BaseFragment<MangaInfoPresenter> {
public void setMangaInfo(Manga manga) {
mArtist.setText(manga.artist);
mAuthor.setText(manga.author);
mChapters.setText("0"); // TODO
mGenres.setText(manga.genre);
mStatus.setText("Ongoing"); //TODO
mDescription.setText(manga.description);
@ -61,4 +60,8 @@ public class MangaInfoFragment extends BaseFragment<MangaInfoPresenter> {
.centerCrop()
.into(mCover);
}
public void setChapterCount(int count) {
mChapters.setText(String.valueOf(count));
}
}

View File

@ -0,0 +1,7 @@
package eu.kanade.mangafeed.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
public @interface EventBusHook {}

View File

@ -0,0 +1,13 @@
package eu.kanade.mangafeed.util.events;
public class ChapterCountEvent {
private int count;
public ChapterCountEvent(int count) {
this.count = count;
}
public int getCount() {
return count;
}
}