From 39c9fd594566119d030fbdb96b195969aea62799 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 7 Jan 2016 02:48:46 +0100 Subject: [PATCH] Keep covers aspect ratio. Unsubscribe from the library when it's not needed. --- .../ui/library/LibraryCategoryAdapter.java | 4 ++++ .../ui/library/LibraryCategoryFragment.java | 1 + .../mangafeed/ui/library/LibraryHolder.java | 7 +++++-- .../mangafeed/ui/library/LibraryPresenter.java | 15 +++++++++++++++ .../mangafeed/widget/AutofitRecyclerView.java | 8 ++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryAdapter.java index 76ff470fad..2a443f721d 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryAdapter.java @@ -66,6 +66,10 @@ public class LibraryCategoryAdapter extends FlexibleAdapter { super.onDestroy(); } + @Override + protected void onTakeView(LibraryFragment libraryFragment) { + super.onTakeView(libraryFragment); + if (!isSubscribed(GET_LIBRARY)) { + start(GET_LIBRARY); + } + } + private Observable, Map>>> getLibraryObservable() { return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable(), Pair::create) @@ -73,6 +81,13 @@ public class LibraryPresenter extends BasePresenter { .toMap(pair -> pair.first, pair -> pair.second)); } + + + public void onOpenManga(Manga manga) { + // Avoid further db updates for the library when it's not needed + stop(GET_LIBRARY); + } + public void setSelection(Manga manga, boolean selected) { if (selected) { selectedMangas.add(manga); diff --git a/app/src/main/java/eu/kanade/mangafeed/widget/AutofitRecyclerView.java b/app/src/main/java/eu/kanade/mangafeed/widget/AutofitRecyclerView.java index 97e382eb2d..e90256b82a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/widget/AutofitRecyclerView.java +++ b/app/src/main/java/eu/kanade/mangafeed/widget/AutofitRecyclerView.java @@ -57,4 +57,12 @@ public class AutofitRecyclerView extends RecyclerView { } } + public int getSpanCount() { + return manager.getSpanCount(); + } + + public int getItemWidth() { + return getMeasuredWidth() / getSpanCount(); + } + } \ No newline at end of file