Przeglądaj źródła

Keep covers aspect ratio. Unsubscribe from the library when it's not needed.

inorichi 9 lat temu
rodzic
commit
39c9fd5945

+ 4 - 0
app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryAdapter.java

@@ -66,6 +66,10 @@ public class LibraryCategoryAdapter extends FlexibleAdapter<LibraryHolder, Manga
         holder.itemView.setActivated(isSelected(position));
     }
 
+    public int getCoverHeight() {
+        return fragment.recycler.getItemWidth() / 9 * 12;
+    }
+
     @Override
     public Filter getFilter() {
         return filter;

+ 1 - 0
app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryCategoryFragment.java

@@ -116,6 +116,7 @@ public class LibraryCategoryFragment extends BaseFragment
     }
 
     protected void openManga(Manga manga) {
+        getLibraryPresenter().onOpenManga(manga);
         Intent intent = MangaActivity.newIntent(getActivity(), manga);
         startActivity(intent);
     }

+ 5 - 2
app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryHolder.java

@@ -6,22 +6,25 @@ import android.widget.TextView;
 
 import butterknife.Bind;
 import butterknife.ButterKnife;
-import eu.davidea.flexibleadapter.FlexibleAdapter;
 import eu.kanade.mangafeed.R;
 import eu.kanade.mangafeed.data.cache.CoverCache;
 import eu.kanade.mangafeed.data.database.models.Manga;
 import eu.kanade.mangafeed.data.source.base.Source;
 import eu.kanade.mangafeed.ui.base.adapter.FlexibleViewHolder;
 
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+import static android.widget.RelativeLayout.LayoutParams;
+
 public class LibraryHolder extends FlexibleViewHolder {
 
     @Bind(R.id.thumbnail) ImageView thumbnail;
     @Bind(R.id.title) TextView title;
     @Bind(R.id.unreadText) TextView unreadText;
 
-    public LibraryHolder(View view, FlexibleAdapter adapter, OnListItemClickListener listener) {
+    public LibraryHolder(View view, LibraryCategoryAdapter adapter, OnListItemClickListener listener) {
         super(view, adapter, listener);
         ButterKnife.bind(this, view);
+        thumbnail.setLayoutParams(new LayoutParams(MATCH_PARENT, adapter.getCoverHeight()));
     }
 
     public void onSetValues(Manga manga, LibraryPresenter presenter) {

+ 15 - 0
app/src/main/java/eu/kanade/mangafeed/ui/library/LibraryPresenter.java

@@ -53,6 +53,14 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
         super.onDestroy();
     }
 
+    @Override
+    protected void onTakeView(LibraryFragment libraryFragment) {
+        super.onTakeView(libraryFragment);
+        if (!isSubscribed(GET_LIBRARY)) {
+            start(GET_LIBRARY);
+        }
+    }
+
     private Observable<Pair<List<Category>, Map<Integer, List<Manga>>>> getLibraryObservable() {
         return Observable.combineLatest(getCategoriesObservable(), getLibraryMangasObservable(),
                 Pair::create)
@@ -73,6 +81,13 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
                         .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);

+ 8 - 0
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();
+    }
+
 }