Skip to content

Commit

Permalink
Show movie posters
Browse files Browse the repository at this point in the history
  • Loading branch information
xwz committed Sep 16, 2015
1 parent db62050 commit fd36f6d
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ private void updateMediaSessionData() {

Point size = new Point(getResources().getDimensionPixelSize(R.dimen.card_width),
getResources().getDimensionPixelSize(R.dimen.card_height));

Picasso.with(this).load(mCurrentEpisode.getThumbnail()).resize(size.x, size.y).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Expand Down
26 changes: 26 additions & 0 deletions base/src/main/java/io/github/xwz/base/adapters/CardSelector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.xwz.base.adapters;

import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.PresenterSelector;

import io.github.xwz.base.api.CategoryModel;
import io.github.xwz.base.api.IEpisodeModel;

public class CardSelector extends PresenterSelector {
final EpisodePresenter card = new EpisodePresenter();
final CategoryPresenter cat = new CategoryPresenter();
final FilmPresenter film = new FilmPresenter();

@Override
public Presenter getPresenter(Object item) {
if (item instanceof IEpisodeModel) {
IEpisodeModel model = (IEpisodeModel) item;
if (model instanceof CategoryModel) {
return cat;
} else if (model.hasCover()) {
return film;
}
}
return card;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
package io.github.xwz.base.adapters;

import android.content.Context;
import android.graphics.Point;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import io.github.xwz.base.views.EpisodeCardView;
import io.github.xwz.base.R;
import io.github.xwz.base.api.IEpisodeModel;
import io.github.xwz.base.views.EpisodeCardView;

public class EpisodePresenter extends Presenter {
private static final String TAG = "EpisodePresenter";

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
ImageCardView cardView = new ImageCardView(parent.getContext());
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
return new EpisodeCardView(parent.getContext(), cardView);
Context context = parent.getContext();
return new EpisodeCardView(context, getCardView(context), getCardSize(context));
}

protected Point getCardSize(Context context) {
return new Point(context.getResources().getDimensionPixelSize(R.dimen.card_width),
context.getResources().getDimensionPixelSize(R.dimen.card_height));
}

protected ImageCardView getCardView(Context context) {
ImageCardView card = new ImageCardView(context);
card.setFocusable(true);
card.setFocusableInTouchMode(true);
card.setMainImageScaleType(ImageView.ScaleType.CENTER_CROP);
Point size = getCardSize(context);
card.setMainImageDimensions(size.x, size.y);
return card;
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions base/src/main/java/io/github/xwz/base/adapters/FilmPresenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.xwz.base.adapters;

import android.content.Context;
import android.graphics.Point;
import android.support.v17.leanback.widget.BaseCardView;
import android.support.v17.leanback.widget.ImageCardView;
import android.view.View;
import android.view.ViewGroup;

import io.github.xwz.base.R;

public class FilmPresenter extends EpisodePresenter {
@Override
protected Point getCardSize(Context context) {
return new Point(context.getResources().getDimensionPixelSize(R.dimen.poster_width),
context.getResources().getDimensionPixelSize(R.dimen.poster_height));
}

@Override
protected ImageCardView getCardView(Context context) {
ImageCardView card = super.getCardView(context);
card.setCardType(BaseCardView.CARD_TYPE_MAIN_ONLY);
return card;
}
}
5 changes: 5 additions & 0 deletions base/src/main/java/io/github/xwz/base/api/CategoryModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ public boolean isFilm() {
public String getCover() {
return null;
}

@Override
public boolean hasCover() {
return false;
}
}
2 changes: 2 additions & 0 deletions base/src/main/java/io/github/xwz/base/api/IEpisodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ public interface IEpisodeModel extends Serializable {
boolean isFilm();

String getCover();

boolean hasCover();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

import io.github.xwz.base.R;
import io.github.xwz.base.Utils;
import io.github.xwz.base.adapters.EpisodePresenter;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.base.adapters.CardSelector;
import io.github.xwz.base.api.IEpisodeModel;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.base.views.EpisodeDetailsView;

public abstract class DetailsFragment extends android.support.v17.leanback.app.RowsFragment {
Expand Down Expand Up @@ -113,7 +113,7 @@ private void setupListeners() {

private void setupAdapter(IEpisodeModel episode) {
ArrayObjectAdapter adapter = new ArrayObjectAdapter(new ListRowPresenter());
otherEpisodes = new ArrayObjectAdapter(new EpisodePresenter());
otherEpisodes = new ArrayObjectAdapter(new CardSelector());
otherEpisodes.add(0, episode);
adapter.add(new ListRow(new HeaderItem(0, null), otherEpisodes));
setAdapter(adapter);
Expand Down Expand Up @@ -156,7 +156,7 @@ private void updateRelatedEpisodes(Map<String, List<IEpisodeModel>> others) {
if (IContentManager.OTHER_EPISODES.equals(title)) {
otherEpisodes.addAll(otherEpisodes.size(), list.getValue());
} else {
ArrayObjectAdapter more = new ArrayObjectAdapter(new EpisodePresenter());
ArrayObjectAdapter more = new ArrayObjectAdapter(new CardSelector());
more.addAll(0, list.getValue());
adapter.add(new ListRow(new HeaderItem(0, title), more));
}
Expand Down
16 changes: 3 additions & 13 deletions base/src/main/java/io/github/xwz/base/fragments/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.PresenterSelector;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v4.content.LocalBroadcastManager;
Expand All @@ -32,11 +31,10 @@

import io.github.xwz.base.R;
import io.github.xwz.base.adapters.BaseArrayAdapter;
import io.github.xwz.base.adapters.CategoryPresenter;
import io.github.xwz.base.adapters.EpisodePresenter;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.base.adapters.CardSelector;
import io.github.xwz.base.api.CategoryModel;
import io.github.xwz.base.api.IEpisodeModel;
import io.github.xwz.base.content.IContentManager;

public abstract class MainFragment extends BrowseFragment {

Expand Down Expand Up @@ -152,14 +150,6 @@ private void updateRows(ArrayObjectAdapter adapter) {
LinkedHashMap<String, List<IEpisodeModel>> all = getContentManger().getAllShowsByCategories();
int currentRows = adapter.size();
int newRows = all.size();
final EpisodePresenter card = new EpisodePresenter();
final CategoryPresenter cat = new CategoryPresenter();
PresenterSelector selector = new PresenterSelector() {
@Override
public Presenter getPresenter(Object item) {
return item instanceof CategoryModel ? cat : card;
}
};
List<String> categories = new ArrayList<>(all.keySet());
for (int i = 0; i < newRows; i++) {
String category = categories.get(i);
Expand All @@ -175,7 +165,7 @@ public Presenter getPresenter(Object item) {
BaseArrayAdapter<IEpisodeModel> items = (BaseArrayAdapter<IEpisodeModel>) row.getAdapter();
items.replaceItems(episodes);
} else { // add
BaseArrayAdapter<IEpisodeModel> items = new BaseArrayAdapter<>(selector);
BaseArrayAdapter<IEpisodeModel> items = new BaseArrayAdapter<>(new CardSelector());
items.addAll(0, episodes);
HeaderItem header = new HeaderItem(category);
ListRow row = new ListRow(header, items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import java.util.List;

import io.github.xwz.base.R;
import io.github.xwz.base.adapters.EpisodePresenter;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.base.adapters.CardSelector;
import io.github.xwz.base.api.IEpisodeModel;
import io.github.xwz.base.content.IContentManager;

public abstract class SearchFragment extends android.support.v17.leanback.app.SearchFragment
implements android.support.v17.leanback.app.SearchFragment.SearchResultProvider {
Expand Down Expand Up @@ -99,8 +99,7 @@ public void setQuery(String str) {
public void run() {
Log.d(TAG, "Searching: " + query);
List<IEpisodeModel> results = getContentManger().searchShows(query);
EpisodePresenter card = new EpisodePresenter();
ArrayObjectAdapter row = new ArrayObjectAdapter(card);
ArrayObjectAdapter row = new ArrayObjectAdapter(new CardSelector());
row.addAll(0, results);
HeaderItem header = new HeaderItem(0, getResources().getString(R.string.search_results));
adapter.add(new ListRow(header, row));
Expand Down
15 changes: 8 additions & 7 deletions base/src/main/java/io/github/xwz/base/views/EpisodeCardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import android.graphics.Point;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.view.View;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import io.github.xwz.base.R;
import io.github.xwz.base.api.IEpisodeModel;

public class EpisodeCardView extends Presenter.ViewHolder {
Expand All @@ -18,14 +18,11 @@ public class EpisodeCardView extends Presenter.ViewHolder {
private final Context mContext;
private final Point size;

public EpisodeCardView(Context context, ImageCardView view) {
public EpisodeCardView(Context context, ImageCardView view, Point s) {
super(view);
mContext = context;
card = view;
size = new Point(mContext.getResources().getDimensionPixelSize(R.dimen.card_width),
mContext.getResources().getDimensionPixelSize(R.dimen.card_height));
card.setMainImageDimensions(size.x, size.y);
card.setMainImageScaleType(ImageView.ScaleType.CENTER_CROP);
size = s;
}

public void setEpisode(IEpisodeModel ep) {
Expand All @@ -47,8 +44,12 @@ public void setEpisode(IEpisodeModel ep) {
} else {
card.setBadgeImage(null);
}
String image = ep.getThumbnail();
if (ep.hasCover()) {
image = ep.getCover();
}
Picasso.with(mContext)
.load(ep.getThumbnail())
.load(image)
.resize(size.x, size.y)
.into(card.getMainImageView());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Point;
import android.os.Handler;
import android.support.v17.leanback.widget.BaseCardView;
import android.support.v17.leanback.widget.ImageCardView;
Expand Down Expand Up @@ -91,7 +92,9 @@ public VideoPlayerView(Context context, MediaController controller, View root) {
card.setFocusableInTouchMode(true);
card.setInfoVisibility(View.VISIBLE);
card.setExtraVisibility(View.VISIBLE);
nextEpisode = new EpisodeCardView(context, card);
Point size = new Point(context.getResources().getDimensionPixelSize(R.dimen.card_width),
context.getResources().getDimensionPixelSize(R.dimen.card_height));
nextEpisode = new EpisodeCardView(context, card, size);
nextEpisode.getImageCardView().setCardType(BaseCardView.CARD_TYPE_INFO_OVER);

debugView.setVisibility(View.GONE);
Expand Down
2 changes: 2 additions & 0 deletions base/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

<dimen name="card_width">208dp</dimen>
<dimen name="card_height">117dp</dimen>
<dimen name="poster_height">169dp</dimen>
<dimen name="poster_width">113dp</dimen>

<dimen name="episode_detail_padding_top">@dimen/marginBaseQuintuple</dimen>
<dimen name="episode_detail_padding_left">300dp</dimen>
Expand Down
5 changes: 5 additions & 0 deletions iview/src/main/java/io/github/xwz/iview/api/EpisodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,9 @@ public boolean isFilm() {
public String getCover() {
return null;
}

@Override
public boolean hasCover() {
return false;
}
}
7 changes: 7 additions & 0 deletions sbs/src/main/java/io/github/xwz/sbs/api/EpisodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ private void set(SBSApi.Entry data) {
duration = data.getDuration();
rating = data.getRating();
episodeCount = 0;
film = data.isFilm();
cover = data.getCover();
categories.addAll(data.getCategories());

description = data.synopsis;
Expand Down Expand Up @@ -281,4 +283,9 @@ public boolean isFilm() {
public String getCover() {
return cover;
}

@Override
public boolean hasCover() {
return isFilm() && getCover() != null && getCover().length() > 0;
}
}
Loading

0 comments on commit fd36f6d

Please sign in to comment.