From 829c2d5faad3b9a059910a0835f168d58a868a97 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 3 Jan 2016 01:20:31 +0100 Subject: [PATCH] Description scrollable and show real manga status. --- .../mangafeed/data/database/models/Manga.java | 16 ++++++++++++++ .../ui/catalogue/CatalogueFragment.java | 10 ++++----- .../ui/catalogue/CataloguePresenter.java | 21 +++++++++---------- .../ui/manga/info/MangaInfoFragment.java | 2 +- .../main/res/layout/fragment_manga_info.xml | 20 +++++++++++------- app/src/main/res/values/strings.xml | 5 ++++- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java index 81dd902613..f5260a7fbb 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Manga.java @@ -1,10 +1,13 @@ package eu.kanade.mangafeed.data.database.models; +import android.content.Context; + import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; import java.io.Serializable; +import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.database.tables.MangaTable; import eu.kanade.mangafeed.util.UrlUtil; @@ -104,6 +107,19 @@ public class Manga implements Serializable { 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 public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java index 2abf00cd84..a3e8919903 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CatalogueFragment.java @@ -8,7 +8,6 @@ import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; -import android.util.Pair; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -41,7 +40,8 @@ import rx.android.schedulers.AndroidSchedulers; import rx.subjects.PublishSubject; @RequiresPresenter(CataloguePresenter.class) -public class CatalogueFragment extends BaseRxFragment implements FlexibleViewHolder.OnListItemClickListener { +public class CatalogueFragment extends BaseRxFragment + implements FlexibleViewHolder.OnListItemClickListener { @Bind(R.id.recycler) AutofitRecyclerView recycler; @Bind(R.id.progress) ProgressBar progress; @@ -207,13 +207,13 @@ public class CatalogueFragment extends BaseRxFragment implem } } - public void onAddPage(Pair> pair) { + public void onAddPage(int page, List mangas) { hideProgressBar(); - if (pair.first == 0) { + if (page == 1) { adapter.clear(); scrollListener.resetScroll(); } - adapter.addItems(pair.second); + adapter.addItems(mangas); } public void onAddPageError() { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java index ab649c1f3a..b491aaba27 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/catalogue/CataloguePresenter.java @@ -57,15 +57,8 @@ public class CataloguePresenter extends BasePresenter { mangaDetailSubject = PublishSubject.create(); restartableReplay(GET_MANGA_LIST, - () -> pager.pages().concatMap( - page -> getMangaObs(page + 1) - .map(mangas -> Pair.create(page, mangas)) - .doOnNext(pair -> { - if (mangaDetailSubject != null) - mangaDetailSubject.onNext(pair.second); - }) - .observeOn(AndroidSchedulers.mainThread())), - CatalogueFragment::onAddPage, + () -> pager.pages().concatMap(page -> getMangasPageObservable(page + 1)), + (view, pair) -> view.onAddPage(pair.first, pair.second), (view, error) -> { view.onAddPageError(); Timber.e(error.getMessage()); @@ -116,7 +109,7 @@ public class CataloguePresenter extends BasePresenter { pager.requestNext(++currentPage); } - private Observable> getMangaObs(int page) { + private Observable>> getMangasPageObservable(int page) { MangasPage nextMangasPage = new MangasPage(page); if (page != 1) { nextMangasPage.url = lastMangasPage.nextPageUrl; @@ -130,7 +123,13 @@ public class CataloguePresenter extends BasePresenter { .doOnNext(mangasPage -> lastMangasPage = mangasPage) .flatMap(mangasPage -> Observable.from(mangasPage.mangas)) .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) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoFragment.java index b456ecb08c..3f00868f38 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoFragment.java @@ -73,7 +73,7 @@ public class MangaInfoFragment extends BaseRxFragment { artist.setText(manga.artist); author.setText(manga.author); genres.setText(manga.genre); - status.setText("Ongoing"); //TODO + status.setText(manga.getStatus(getActivity())); description.setText(manga.description); setFavoriteText(manga.favorite); diff --git a/app/src/main/res/layout/fragment_manga_info.xml b/app/src/main/res/layout/fragment_manga_info.xml index 93e77c1309..6e70ea452c 100644 --- a/app/src/main/res/layout/fragment_manga_info.xml +++ b/app/src/main/res/layout/fragment_manga_info.xml @@ -212,14 +212,20 @@ android:singleLine="false" android:text="@string/description" /> - + android:layout_height="match_parent"> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4735d50c4c..9e33d981b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -123,8 +123,11 @@ Chapters Genres Artist - Status Description + Status + Ongoing + Unknown + Licensed Add to library Remove from library