Search in sources :

Example 1 with GridInsetDecoration

use of com.battlelancer.seriesguide.util.GridInsetDecoration in project SeriesGuide by UweTrottmann.

the class ShowsNowFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_now, container, false);
    unbinder = ButterKnife.bind(this, v);
    swipeRefreshLayout.setSwipeableChildren(R.id.scrollViewNow, R.id.recyclerViewNow);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshStream();
        }
    });
    swipeRefreshLayout.setProgressViewOffset(false, getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin), getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin));
    emptyView.setText(R.string.now_empty);
    showError(null);
    snackbarButton.setText(R.string.refresh);
    snackbarButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshStream();
        }
    });
    // recycler view layout manager
    final int spanCount = getResources().getInteger(R.integer.grid_column_count);
    final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (adapter == null) {
                return 1;
            }
            if (position >= adapter.getItemCount()) {
                return 1;
            }
            // make headers and more links span all columns
            int type = adapter.getItem(position).type;
            return (type == NowAdapter.ItemType.HEADER || type == NowAdapter.ItemType.MORE_LINK) ? spanCount : 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new GridInsetDecoration(getResources()));
    recyclerView.setHasFixedSize(true);
    return v;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) GridInsetDecoration(com.battlelancer.seriesguide.util.GridInsetDecoration) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) EmptyViewSwipeRefreshLayout(com.battlelancer.seriesguide.widgets.EmptyViewSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 2 with GridInsetDecoration

use of com.battlelancer.seriesguide.util.GridInsetDecoration in project SeriesGuide by UweTrottmann.

the class MoviesNowFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_now, container, false);
    unbinder = ButterKnife.bind(this, v);
    swipeRefreshLayout.setSwipeableChildren(R.id.scrollViewNow, R.id.recyclerViewNow);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshStream();
        }
    });
    swipeRefreshLayout.setProgressViewOffset(false, getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin), getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin));
    emptyView.setText(R.string.now_movies_empty);
    showError(null);
    snackbarButton.setText(R.string.refresh);
    snackbarButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshStream();
        }
    });
    // recycler view layout manager
    final int spanCount = getResources().getInteger(R.integer.grid_column_count);
    final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (adapter == null) {
                return 1;
            }
            if (position >= adapter.getItemCount()) {
                return 1;
            }
            // make headers and more links span all columns
            int type = adapter.getItem(position).type;
            return (type == NowAdapter.ItemType.HEADER || type == NowAdapter.ItemType.MORE_LINK) ? spanCount : 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new GridInsetDecoration(getResources()));
    recyclerView.setHasFixedSize(true);
    return v;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) GridInsetDecoration(com.battlelancer.seriesguide.util.GridInsetDecoration) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) EmptyViewSwipeRefreshLayout(com.battlelancer.seriesguide.widgets.EmptyViewSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Nullable(android.support.annotation.Nullable)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 GridInsetDecoration (com.battlelancer.seriesguide.util.GridInsetDecoration)2 EmptyViewSwipeRefreshLayout (com.battlelancer.seriesguide.widgets.EmptyViewSwipeRefreshLayout)2 Nullable (android.support.annotation.Nullable)1