Description scrollable and show real manga status.

This commit is contained in:
inorichi 2016-01-03 01:20:31 +01:00
parent 868058a50b
commit 829c2d5faa
6 changed files with 49 additions and 25 deletions

View file

@ -1,10 +1,13 @@
package eu.kanade.mangafeed.data.database.models; package eu.kanade.mangafeed.data.database.models;
import android.content.Context;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import java.io.Serializable; import java.io.Serializable;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.database.tables.MangaTable; import eu.kanade.mangafeed.data.database.tables.MangaTable;
import eu.kanade.mangafeed.util.UrlUtil; import eu.kanade.mangafeed.util.UrlUtil;
@ -104,6 +107,19 @@ public class Manga implements Serializable {
initialized = true; initialized = true;
} }
public String getStatus(Context context) {
switch (status) {
case ONGOING:
return context.getString(R.string.ongoing);
case COMPLETED:
return context.getString(R.string.completed);
case LICENSED:
return context.getString(R.string.licensed);
default:
return context.getString(R.string.unknown);
}
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View file

@ -8,7 +8,6 @@ import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -41,7 +40,8 @@ import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject; import rx.subjects.PublishSubject;
@RequiresPresenter(CataloguePresenter.class) @RequiresPresenter(CataloguePresenter.class)
public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> implements FlexibleViewHolder.OnListItemClickListener { public class CatalogueFragment extends BaseRxFragment<CataloguePresenter>
implements FlexibleViewHolder.OnListItemClickListener {
@Bind(R.id.recycler) AutofitRecyclerView recycler; @Bind(R.id.recycler) AutofitRecyclerView recycler;
@Bind(R.id.progress) ProgressBar progress; @Bind(R.id.progress) ProgressBar progress;
@ -207,13 +207,13 @@ public class CatalogueFragment extends BaseRxFragment<CataloguePresenter> implem
} }
} }
public void onAddPage(Pair<Integer, List<Manga>> pair) { public void onAddPage(int page, List<Manga> mangas) {
hideProgressBar(); hideProgressBar();
if (pair.first == 0) { if (page == 1) {
adapter.clear(); adapter.clear();
scrollListener.resetScroll(); scrollListener.resetScroll();
} }
adapter.addItems(pair.second); adapter.addItems(mangas);
} }
public void onAddPageError() { public void onAddPageError() {

View file

@ -57,15 +57,8 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
mangaDetailSubject = PublishSubject.create(); mangaDetailSubject = PublishSubject.create();
restartableReplay(GET_MANGA_LIST, restartableReplay(GET_MANGA_LIST,
() -> pager.pages().concatMap( () -> pager.pages().concatMap(page -> getMangasPageObservable(page + 1)),
page -> getMangaObs(page + 1) (view, pair) -> view.onAddPage(pair.first, pair.second),
.map(mangas -> Pair.create(page, mangas))
.doOnNext(pair -> {
if (mangaDetailSubject != null)
mangaDetailSubject.onNext(pair.second);
})
.observeOn(AndroidSchedulers.mainThread())),
CatalogueFragment::onAddPage,
(view, error) -> { (view, error) -> {
view.onAddPageError(); view.onAddPageError();
Timber.e(error.getMessage()); Timber.e(error.getMessage());
@ -116,7 +109,7 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
pager.requestNext(++currentPage); pager.requestNext(++currentPage);
} }
private Observable<List<Manga>> getMangaObs(int page) { private Observable<Pair<Integer, List<Manga>>> getMangasPageObservable(int page) {
MangasPage nextMangasPage = new MangasPage(page); MangasPage nextMangasPage = new MangasPage(page);
if (page != 1) { if (page != 1) {
nextMangasPage.url = lastMangasPage.nextPageUrl; nextMangasPage.url = lastMangasPage.nextPageUrl;
@ -130,7 +123,13 @@ public class CataloguePresenter extends BasePresenter<CatalogueFragment> {
.doOnNext(mangasPage -> lastMangasPage = mangasPage) .doOnNext(mangasPage -> lastMangasPage = mangasPage)
.flatMap(mangasPage -> Observable.from(mangasPage.mangas)) .flatMap(mangasPage -> Observable.from(mangasPage.mangas))
.map(this::networkToLocalManga) .map(this::networkToLocalManga)
.toList(); .toList()
.map(mangas -> Pair.create(page, mangas))
.doOnNext(pair -> {
if (mangaDetailSubject != null)
mangaDetailSubject.onNext(pair.second);
})
.observeOn(AndroidSchedulers.mainThread());
} }
private Manga networkToLocalManga(Manga networkManga) { private Manga networkToLocalManga(Manga networkManga) {

View file

@ -73,7 +73,7 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
artist.setText(manga.artist); artist.setText(manga.artist);
author.setText(manga.author); author.setText(manga.author);
genres.setText(manga.genre); genres.setText(manga.genre);
status.setText("Ongoing"); //TODO status.setText(manga.getStatus(getActivity()));
description.setText(manga.description); description.setText(manga.description);
setFavoriteText(manga.favorite); setFavoriteText(manga.favorite);

View file

@ -212,14 +212,20 @@
android:singleLine="false" android:singleLine="false"
android:text="@string/description" /> android:text="@string/description" />
<TextView <ScrollView
android:id="@+id/manga_summary"
style="@style/manga_detail_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:focusable="false"
android:focusableInTouchMode="false" <TextView
android:singleLine="false" /> android:id="@+id/manga_summary"
style="@style/manga_detail_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="false" />
</ScrollView>
</LinearLayout> </LinearLayout>

View file

@ -123,8 +123,11 @@
<string name="chapters">Chapters</string> <string name="chapters">Chapters</string>
<string name="genres">Genres</string> <string name="genres">Genres</string>
<string name="artist">Artist</string> <string name="artist">Artist</string>
<string name="status">Status</string>
<string name="description">Description</string> <string name="description">Description</string>
<string name="status">Status</string>
<string name="ongoing">Ongoing</string>
<string name="unknown">Unknown</string>
<string name="licensed">Licensed</string>
<string name="add_to_library">Add to library</string> <string name="add_to_library">Add to library</string>
<string name="remove_from_library">Remove from library</string> <string name="remove_from_library">Remove from library</string>