Show chapter count
This commit is contained in:
@@ -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) {
|
||||
this.manga = manga;
|
||||
getMangaInfo();
|
||||
if (!manga.equals(this.manga)) {
|
||||
this.manga = manga;
|
||||
start(GET_MANGA);
|
||||
}
|
||||
}
|
||||
|
||||
private void getMangaInfo() {
|
||||
if (mangaInfoSubscription != null)
|
||||
remove(mangaInfoSubscription);
|
||||
|
||||
add(mangaInfoSubscription = Observable.just(manga)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(deliverLatestCache())
|
||||
.subscribe(split(MangaInfoFragment::setMangaInfo)));
|
||||
@EventBusHook
|
||||
public void onEventMainThread(ChapterCountEvent event) {
|
||||
if (count != event.getCount()) {
|
||||
count = event.getCount();
|
||||
start(GET_CHAPTER_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user