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

This commit is contained in:
inorichi 2016-01-07 02:48:46 +01:00
parent 690684bacf
commit 39c9fd5945
5 changed files with 33 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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) {

View file

@ -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);

View file

@ -57,4 +57,12 @@ public class AutofitRecyclerView extends RecyclerView {
}
}
public int getSpanCount() {
return manager.getSpanCount();
}
public int getItemWidth() {
return getMeasuredWidth() / getSpanCount();
}
}