diff --git a/base/src/main/java/io/github/xwz/base/activities/VideoPlayerActivity.java b/base/src/main/java/io/github/xwz/base/activities/VideoPlayerActivity.java index 77887cd..d06a48b 100644 --- a/base/src/main/java/io/github/xwz/base/activities/VideoPlayerActivity.java +++ b/base/src/main/java/io/github/xwz/base/activities/VideoPlayerActivity.java @@ -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) { diff --git a/base/src/main/java/io/github/xwz/base/adapters/CardSelector.java b/base/src/main/java/io/github/xwz/base/adapters/CardSelector.java new file mode 100644 index 0000000..6176490 --- /dev/null +++ b/base/src/main/java/io/github/xwz/base/adapters/CardSelector.java @@ -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; + } +} diff --git a/base/src/main/java/io/github/xwz/base/adapters/EpisodePresenter.java b/base/src/main/java/io/github/xwz/base/adapters/EpisodePresenter.java index 6a3d91b..785a1a3 100644 --- a/base/src/main/java/io/github/xwz/base/adapters/EpisodePresenter.java +++ b/base/src/main/java/io/github/xwz/base/adapters/EpisodePresenter.java @@ -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 diff --git a/base/src/main/java/io/github/xwz/base/adapters/FilmPresenter.java b/base/src/main/java/io/github/xwz/base/adapters/FilmPresenter.java new file mode 100644 index 0000000..745e10d --- /dev/null +++ b/base/src/main/java/io/github/xwz/base/adapters/FilmPresenter.java @@ -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; + } +} diff --git a/base/src/main/java/io/github/xwz/base/api/CategoryModel.java b/base/src/main/java/io/github/xwz/base/api/CategoryModel.java index 4424f15..4bd2ba6 100644 --- a/base/src/main/java/io/github/xwz/base/api/CategoryModel.java +++ b/base/src/main/java/io/github/xwz/base/api/CategoryModel.java @@ -171,4 +171,9 @@ public boolean isFilm() { public String getCover() { return null; } + + @Override + public boolean hasCover() { + return false; + } } diff --git a/base/src/main/java/io/github/xwz/base/api/IEpisodeModel.java b/base/src/main/java/io/github/xwz/base/api/IEpisodeModel.java index d4ddd5d..9fac752 100644 --- a/base/src/main/java/io/github/xwz/base/api/IEpisodeModel.java +++ b/base/src/main/java/io/github/xwz/base/api/IEpisodeModel.java @@ -69,4 +69,6 @@ public interface IEpisodeModel extends Serializable { boolean isFilm(); String getCover(); + + boolean hasCover(); } diff --git a/base/src/main/java/io/github/xwz/base/fragments/DetailsFragment.java b/base/src/main/java/io/github/xwz/base/fragments/DetailsFragment.java index f479e99..eda5667 100644 --- a/base/src/main/java/io/github/xwz/base/fragments/DetailsFragment.java +++ b/base/src/main/java/io/github/xwz/base/fragments/DetailsFragment.java @@ -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 { @@ -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); @@ -156,7 +156,7 @@ private void updateRelatedEpisodes(Map> 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)); } diff --git a/base/src/main/java/io/github/xwz/base/fragments/MainFragment.java b/base/src/main/java/io/github/xwz/base/fragments/MainFragment.java index f525de7..80474a9 100644 --- a/base/src/main/java/io/github/xwz/base/fragments/MainFragment.java +++ b/base/src/main/java/io/github/xwz/base/fragments/MainFragment.java @@ -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; @@ -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 { @@ -152,14 +150,6 @@ private void updateRows(ArrayObjectAdapter adapter) { LinkedHashMap> 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 categories = new ArrayList<>(all.keySet()); for (int i = 0; i < newRows; i++) { String category = categories.get(i); @@ -175,7 +165,7 @@ public Presenter getPresenter(Object item) { BaseArrayAdapter items = (BaseArrayAdapter) row.getAdapter(); items.replaceItems(episodes); } else { // add - BaseArrayAdapter items = new BaseArrayAdapter<>(selector); + BaseArrayAdapter items = new BaseArrayAdapter<>(new CardSelector()); items.addAll(0, episodes); HeaderItem header = new HeaderItem(category); ListRow row = new ListRow(header, items); diff --git a/base/src/main/java/io/github/xwz/base/fragments/SearchFragment.java b/base/src/main/java/io/github/xwz/base/fragments/SearchFragment.java index 6b2bbb3..7faa5bb 100644 --- a/base/src/main/java/io/github/xwz/base/fragments/SearchFragment.java +++ b/base/src/main/java/io/github/xwz/base/fragments/SearchFragment.java @@ -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 { @@ -99,8 +99,7 @@ public void setQuery(String str) { public void run() { Log.d(TAG, "Searching: " + query); List 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)); diff --git a/base/src/main/java/io/github/xwz/base/views/EpisodeCardView.java b/base/src/main/java/io/github/xwz/base/views/EpisodeCardView.java index 3d39c14..36f8424 100644 --- a/base/src/main/java/io/github/xwz/base/views/EpisodeCardView.java +++ b/base/src/main/java/io/github/xwz/base/views/EpisodeCardView.java @@ -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 { @@ -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) { @@ -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()); } diff --git a/base/src/main/java/io/github/xwz/base/views/VideoPlayerView.java b/base/src/main/java/io/github/xwz/base/views/VideoPlayerView.java index f00e0f6..583082e 100644 --- a/base/src/main/java/io/github/xwz/base/views/VideoPlayerView.java +++ b/base/src/main/java/io/github/xwz/base/views/VideoPlayerView.java @@ -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; @@ -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); diff --git a/base/src/main/res/values/dimens.xml b/base/src/main/res/values/dimens.xml index 375384b..ad3e2b8 100644 --- a/base/src/main/res/values/dimens.xml +++ b/base/src/main/res/values/dimens.xml @@ -19,6 +19,8 @@ 208dp 117dp + 169dp + 113dp @dimen/marginBaseQuintuple 300dp diff --git a/iview/src/main/java/io/github/xwz/iview/api/EpisodeModel.java b/iview/src/main/java/io/github/xwz/iview/api/EpisodeModel.java index e24e62a..0101244 100644 --- a/iview/src/main/java/io/github/xwz/iview/api/EpisodeModel.java +++ b/iview/src/main/java/io/github/xwz/iview/api/EpisodeModel.java @@ -352,4 +352,9 @@ public boolean isFilm() { public String getCover() { return null; } + + @Override + public boolean hasCover() { + return false; + } } diff --git a/sbs/src/main/java/io/github/xwz/sbs/api/EpisodeModel.java b/sbs/src/main/java/io/github/xwz/sbs/api/EpisodeModel.java index d59e46e..2fb33dc 100644 --- a/sbs/src/main/java/io/github/xwz/sbs/api/EpisodeModel.java +++ b/sbs/src/main/java/io/github/xwz/sbs/api/EpisodeModel.java @@ -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; @@ -281,4 +283,9 @@ public boolean isFilm() { public String getCover() { return cover; } + + @Override + public boolean hasCover() { + return isFilm() && getCover() != null && getCover().length() > 0; + } } diff --git a/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java b/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java index 0515d4e..1ae3b77 100644 --- a/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java +++ b/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java @@ -26,6 +26,8 @@ abstract class SBSApiBase extends HttpApiBase { + private static final String TAG = "SBSApiBase"; + private static final String API_URL = BuildConfig.API_URL; private static final String RELATED_URL = BuildConfig.RELATED_URL; private static final String VIDEO_URL = BuildConfig.VIDEO_URL; @@ -175,6 +177,24 @@ static class Thumbnail { @SerializedName("plfile$downloadUrl") private String url; + @SerializedName("plfile$assetTypes") + private List types; + + public boolean hasPoster() { + return hasType("Poster"); + } + + public boolean hasType(String str) { + if (types != null) { + for (String type : types) { + if (type != null && type.contains(str)) { + return true; + } + } + } + return false; + } + public String toString() { return width + "x" + height + ":" + url; } @@ -245,6 +265,23 @@ public String getThumbnail() { return thumbnail; } + public String getCover() { + Thumbnail largest = null; + if (thumbnails != null) { + for (Thumbnail t : thumbnails) { + if (t.hasPoster()) { + if (largest == null || (t.height > t.width && t.height > largest.height)) { + largest = t; + } + } + } + } + if (largest != null) { + return largest.url; + } + return null; + } + public List getCategories() { List cats = new ArrayList<>(); if (categories != null) { @@ -278,7 +315,7 @@ public String getChannel() { public String getRating() { if (ratings != null && ratings.size() > 0) { String details = ratings.get(0).rating; - return details != null ? details.toUpperCase() : details; + return details != null && details.length() > 0 ? details.toUpperCase() : null; } return ""; } @@ -293,5 +330,14 @@ public int getDuration() { } return 0; } + + public boolean isFilm() { + for (String cat : getCategories()) { + if (cat.contains("Film/")) { + return true; + } + } + return false; + } } }