Skip to content

Commit

Permalink
Show category grid
Browse files Browse the repository at this point in the history
  • Loading branch information
xwz committed Sep 17, 2015
1 parent fd36f6d commit 8c595da
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 20 deletions.
14 changes: 6 additions & 8 deletions base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.xwz.base">

<application android:allowBackup="true"
android:label="@string/app_name"
>

</application>
<manifest
package="io.github.xwz.base"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:label="@string/app_name"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EpisodePresenter extends Presenter {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
Context context = parent.getContext();
return new EpisodeCardView(context, getCardView(context), getCardSize(context));
return new EpisodeCardView(context, getCardView(context), getCardSize(context), false);
}

protected Point getCardSize(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@
import android.view.ViewGroup;

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

public class FilmPresenter extends EpisodePresenter {

private boolean showDetails = false;

public FilmPresenter() {

}

public FilmPresenter(boolean details) {
showDetails = details;
}

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

@Override
protected Point getCardSize(Context context) {
return new Point(context.getResources().getDimensionPixelSize(R.dimen.poster_width),
Expand All @@ -19,7 +37,7 @@ protected Point getCardSize(Context context) {
@Override
protected ImageCardView getCardView(Context context) {
ImageCardView card = super.getCardView(context);
card.setCardType(BaseCardView.CARD_TYPE_MAIN_ONLY);
card.setCardType(showDetails ? BaseCardView.CARD_TYPE_INFO_UNDER_WITH_EXTRA : BaseCardView.CARD_TYPE_MAIN_ONLY);
return card;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setCategories(List<String> cats) {

@Override
public String toString() {
return category;
return "Category: " + category;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public List<IEpisodeModel> getAllShows() {
return mCache.getAllShows();
}

public List<IEpisodeModel> getAllShowsByCategory(String cat) {
List<IEpisodeModel> all = getAllShowsByCategories().get(cat);
if (all == null) {
all = new ArrayList<>();
}
return all;
}

public IEpisodeModel getEpisode(String href) {
return mCache.getEpisode(href);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public interface IContentManager {
String KEY_EXTRA_NAME = SearchManager.EXTRA_DATA_KEY;

LinkedHashMap<String, List<IEpisodeModel>> getAllShowsByCategories();
List<IEpisodeModel> getAllShowsByCategory(String cat);
void fetchShowList(boolean force);
IEpisodeModel getEpisode(String href);
void fetchEpisode(IEpisodeModel episode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package io.github.xwz.base.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v17.leanback.app.VerticalGridFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.OnItemViewClickedListener;
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.support.v17.leanback.widget.VerticalGridPresenter;
import android.util.Log;
import android.view.View;

import java.util.List;

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

public abstract class CategoryFragment extends VerticalGridFragment {
private static final String TAG = "CategoryFragment";

private static final int FILM_COLUMNS = 10;
private static final int SHOW_COLUMNS = 5;
private String category;
private boolean isFilm = false;

@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
category = getActivity().getIntent().getStringExtra(IContentManager.CONTENT_ID);
isFilm = category.contains("Film/") || category.equals("Film");
setupFragment();
setupListeners();
}

private void setupFragment() {
VerticalGridPresenter gridPresenter = new VerticalGridPresenter();
gridPresenter.setNumberOfColumns(isFilm ? FILM_COLUMNS : SHOW_COLUMNS);
setGridPresenter(gridPresenter);
setTitle(category);

List<IEpisodeModel> all = getContentManger().getAllShowsByCategory(category);
ArrayObjectAdapter adapter;
if (isFilm) {
adapter = new ArrayObjectAdapter(new FilmPresenter(true));
} else {
adapter = new ArrayObjectAdapter(new EpisodePresenter());
}
adapter.addAll(0, all);

setAdapter(adapter);
}

private void setupListeners() {
setOnSearchClickedListener(getSearchClickedListener());
setOnItemViewClickedListener(getItemClickedListener());
}

private View.OnClickListener getSearchClickedListener() {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), getSearchActivityClass());
startActivity(intent);
}
};
}

private OnItemViewClickedListener getItemClickedListener() {
return new OnItemViewClickedListener() {
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof IEpisodeModel) {
Intent intent = new Intent(getActivity(), getDetailsActivityClass());
intent.putExtra(IContentManager.CONTENT_ID, (IEpisodeModel) item);
startActivity(intent);
}
}
};
}

protected abstract IContentManager getContentManger();

protected abstract Class<?> getSearchActivityClass();

protected abstract Class<?> getDetailsActivityClass();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class MainFragment extends BrowseFragment {
private static final String TAG = "MainFragment";
private ProgressBar progress;
private TextView progressText;
private static final int SHOW_CATEGORY_COUNT = -1;
private static final int SHOW_CATEGORY_COUNT = 20;

private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
Expand Down Expand Up @@ -129,7 +129,7 @@ private OnItemViewClickedListener getItemClickedListener() {
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof CategoryModel) {
Intent intent = new Intent(getActivity(), getCategoryActivityClass());
intent.putExtra(IContentManager.CONTENT_ID, (IEpisodeModel) item);
intent.putExtra(IContentManager.CONTENT_ID, ((CategoryModel) item).getTitle());
startActivity(intent);
} else if (item instanceof IEpisodeModel) {
Intent intent = new Intent(getActivity(), getDetailsActivityClass());
Expand All @@ -153,7 +153,7 @@ private void updateRows(ArrayObjectAdapter adapter) {
List<String> categories = new ArrayList<>(all.keySet());
for (int i = 0; i < newRows; i++) {
String category = categories.get(i);
List<IEpisodeModel> episodes = all.get(category);
List<IEpisodeModel> episodes = new ArrayList<>(all.get(category));
if (SHOW_CATEGORY_COUNT > 0 && episodes.size() > SHOW_CATEGORY_COUNT) {
CategoryModel collection = new CategoryModel(category);
collection.setEpisodeCount(episodes.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class EpisodeCardView extends Presenter.ViewHolder {
private final ImageCardView card;
private final Context mContext;
private final Point size;
private boolean canShowCover;

public EpisodeCardView(Context context, ImageCardView view, Point s) {
public EpisodeCardView(Context context, ImageCardView view, Point s, boolean showCover) {
super(view);
mContext = context;
card = view;
size = s;
canShowCover = showCover;
}

public void setEpisode(IEpisodeModel ep) {
Expand All @@ -45,7 +47,7 @@ public void setEpisode(IEpisodeModel ep) {
card.setBadgeImage(null);
}
String image = ep.getThumbnail();
if (ep.hasCover()) {
if (canShowCover && ep.hasCover()) {
image = ep.getCover();
}
Picasso.with(mContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public VideoPlayerView(Context context, MediaController controller, View root) {
card.setExtraVisibility(View.VISIBLE);
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 = new EpisodeCardView(context, card, size, false);
nextEpisode.getImageCardView().setCardType(BaseCardView.CARD_TYPE_INFO_OVER);

debugView.setVisibility(View.GONE);
Expand Down
1 change: 1 addition & 0 deletions iview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</activity>

<activity android:name="io.github.xwz.iview.activities.SearchActivity"/>
<activity android:name="io.github.xwz.iview.activities.CategoryActivity"/>

<activity android:name="io.github.xwz.iview.activities.DetailsActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.xwz.iview.activities;

import android.os.Bundle;

import io.github.xwz.base.activities.BaseActivity;
import io.github.xwz.iview.R;

public class CategoryActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category_activity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.xwz.iview.fragments;

import io.github.xwz.base.content.IContentManager;
import io.github.xwz.iview.activities.DetailsActivity;
import io.github.xwz.iview.activities.SearchActivity;
import io.github.xwz.iview.content.ContentManager;

public class CategoryFragment extends io.github.xwz.base.fragments.CategoryFragment {
@Override
protected IContentManager getContentManger() {
return ContentManager.getInstance();
}

@Override
protected Class<?> getSearchActivityClass() {
return SearchActivity.class;
}

@Override
protected Class<?> getDetailsActivityClass() {
return DetailsActivity.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.View;

import io.github.xwz.iview.R;
import io.github.xwz.iview.activities.CategoryActivity;
import io.github.xwz.iview.activities.DetailsActivity;
import io.github.xwz.iview.activities.SearchActivity;
import io.github.xwz.iview.content.ContentManager;
Expand Down Expand Up @@ -39,6 +40,6 @@ protected Class<?> getDetailsActivityClass() {

@Override
protected Class<?> getCategoryActivityClass() {
return null;
return CategoryActivity.class;
}
}
8 changes: 8 additions & 0 deletions iview/src/main/res/layout/category_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<fragment
android:id="@+id/details_fragment"
android:name="io.github.xwz.iview.fragments.CategoryFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:deviceIds="tv"/>
1 change: 1 addition & 0 deletions sbs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</activity>

<activity android:name="io.github.xwz.sbs.activities.SearchActivity"/>
<activity android:name="io.github.xwz.sbs.activities.CategoryActivity"/>

<activity android:name="io.github.xwz.sbs.activities.DetailsActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.xwz.sbs.activities;

import android.os.Bundle;

import io.github.xwz.base.activities.BaseActivity;
import io.github.xwz.sbs.R;

public class CategoryActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category_activity);
}
}
2 changes: 1 addition & 1 deletion sbs/src/main/java/io/github/xwz/sbs/api/SBSRelatedApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.Map;

import io.github.xwz.base.ImmutableMap;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.base.api.IEpisodeModel;
import io.github.xwz.base.content.IContentManager;
import io.github.xwz.sbs.content.ContentManager;

public class SBSRelatedApi extends SBSApiBase {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.xwz.sbs.fragments;

import io.github.xwz.base.content.IContentManager;
import io.github.xwz.sbs.activities.DetailsActivity;
import io.github.xwz.sbs.activities.SearchActivity;
import io.github.xwz.sbs.content.ContentManager;

public class CategoryFragment extends io.github.xwz.base.fragments.CategoryFragment {
@Override
protected IContentManager getContentManger() {
return ContentManager.getInstance();
}

@Override
protected Class<?> getSearchActivityClass() {
return SearchActivity.class;
}

@Override
protected Class<?> getDetailsActivityClass() {
return DetailsActivity.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.github.xwz.base.content.IContentManager;
import io.github.xwz.sbs.R;
import io.github.xwz.sbs.activities.CategoryActivity;
import io.github.xwz.sbs.activities.DetailsActivity;
import io.github.xwz.sbs.activities.SearchActivity;
import io.github.xwz.sbs.content.ContentManager;
Expand Down Expand Up @@ -40,6 +41,6 @@ protected Class<?> getDetailsActivityClass() {

@Override
protected Class<?> getCategoryActivityClass() {
return null;
return CategoryActivity.class;
}
}
Loading

0 comments on commit 8c595da

Please sign in to comment.