mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 10:37:51 +02:00
Add catalogue detail page. Add simple tests for sources
This commit is contained in:
@ -24,6 +24,7 @@ import nucleus.presenter.RxPresenter;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.internal.util.SubscriptionList;
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subjects.PublishSubject;
|
||||
import timber.log.Timber;
|
||||
@ -46,6 +47,7 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
private Subscription mMangaDetailFetchSubscription;
|
||||
private PublishSubject<Observable<String>> mSearchViewPublishSubject;
|
||||
private PublishSubject<Observable<List<Manga>>> mMangaDetailPublishSubject;
|
||||
private SubscriptionList mResultSubscriptions = new SubscriptionList();
|
||||
|
||||
private final String CURRENT_PAGE = "CATALOGUE_CURRENT_PAGE";
|
||||
|
||||
@ -81,6 +83,12 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
state.putInt(CURRENT_PAGE, mCurrentPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mResultSubscriptions.unsubscribe();
|
||||
}
|
||||
|
||||
private void initializeSearch() {
|
||||
remove(mSearchViewSubscription);
|
||||
|
||||
@ -126,16 +134,17 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
.filter(manga -> manga.initialized)
|
||||
.onBackpressureBuffer()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(manga -> {
|
||||
.compose(deliverReplay())
|
||||
.subscribe(this.split((view, manga) -> {
|
||||
// Get manga index in the adapter
|
||||
int index = getMangaIndex(manga);
|
||||
// Get the image view associated with the manga.
|
||||
// If it's null (not visible in the screen) there's no need to update the image.
|
||||
ImageView imageView = getView().getImageView(index);
|
||||
ImageView imageView = view.getImageView(index);
|
||||
if (imageView != null) {
|
||||
updateImage(imageView, manga.thumbnail_url);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
add(mMangaDetailFetchSubscription);
|
||||
}
|
||||
@ -143,11 +152,15 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
public void getMangasFromSource(int page) {
|
||||
mMangaFetchSubscription = getMangasSubscriber(
|
||||
selectedSource.pullPopularMangasFromNetwork(page));
|
||||
|
||||
mResultSubscriptions.add(mMangaFetchSubscription);
|
||||
}
|
||||
|
||||
public void getMangasFromSearch(int page) {
|
||||
mMangaSearchSubscription = getMangasSubscriber(
|
||||
selectedSource.searchMangasFromNetwork(mSearchName, page));
|
||||
|
||||
mResultSubscriptions.add(mMangaSearchSubscription);
|
||||
}
|
||||
|
||||
private Subscription getMangasSubscriber(Observable<List<Manga>> mangas) {
|
||||
@ -195,10 +208,12 @@ public class CataloguePresenter extends RxPresenter<CatalogueActivity> {
|
||||
// If going to search mode
|
||||
else if (mSearchName.equals("") && !query.equals("")) {
|
||||
mSearchMode = true;
|
||||
mResultSubscriptions.clear();
|
||||
}
|
||||
// If going to normal mode
|
||||
else if (!mSearchName.equals("") && query.equals("")) {
|
||||
mSearchMode = false;
|
||||
mResultSubscriptions.clear();
|
||||
}
|
||||
|
||||
mSearchName = query;
|
||||
|
@ -33,14 +33,6 @@ public class LibraryPresenter extends BasePresenter {
|
||||
public LibraryPresenter(LibraryView view) {
|
||||
this.view = view;
|
||||
App.getComponent(view.getActivity()).inject(this);
|
||||
|
||||
//TODO remove, only for testing
|
||||
if (prefs.isFirstRun()) {
|
||||
db.insertMangas(DummyDataUtil.createDummyManga()).toBlocking().single();
|
||||
db.insertChapters(DummyDataUtil.createDummyChapters()).subscribe();
|
||||
prefs.setNotFirstRun();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onMangaClick(int position) {
|
||||
|
@ -25,5 +25,6 @@ public class MangaCataloguePresenter extends BasePresenter {
|
||||
|
||||
private void initializeManga() {
|
||||
view.setTitle(manga.title);
|
||||
view.setMangaInformation(manga);
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,30 @@ package eu.kanade.mangafeed.ui.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
import eu.kanade.mangafeed.presenter.MangaCataloguePresenter;
|
||||
import eu.kanade.mangafeed.view.MangaCatalogueView;
|
||||
|
||||
public class MangaCatalogueActivity extends BaseActivity implements MangaCatalogueView {
|
||||
|
||||
@Bind(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
|
||||
@Bind(R.id.manga_artist) TextView mArtist;
|
||||
@Bind(R.id.manga_author) TextView mAuthor;
|
||||
@Bind(R.id.manga_chapters) TextView mChapters;
|
||||
@Bind(R.id.manga_genres) TextView mGenres;
|
||||
@Bind(R.id.manga_status) TextView mStatus;
|
||||
@Bind(R.id.manga_summary) TextView mDescription;
|
||||
@Bind(R.id.manga_cover) ImageView mCover;
|
||||
|
||||
private MangaCataloguePresenter presenter;
|
||||
|
||||
@ -40,8 +53,28 @@ public class MangaCatalogueActivity extends BaseActivity implements MangaCatalog
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
// MangaCatalogueView
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
setToolbarTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMangaInformation(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);
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(manga.thumbnail_url)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.into(mCover);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package eu.kanade.mangafeed.view;
|
||||
|
||||
import eu.kanade.mangafeed.data.models.Manga;
|
||||
|
||||
public interface MangaCatalogueView extends BaseView {
|
||||
void setTitle(String title);
|
||||
void setMangaInformation(Manga manga);
|
||||
}
|
||||
|
Reference in New Issue
Block a user