Search in sources :

Example 1 with RecyclerNormalAdapter

use of com.example.gsyvideoplayer.adapter.RecyclerNormalAdapter in project GSYVideoPlayer by CarGuo.

the class RecyclerViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // 设置一个exit transition
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        getWindow().setEnterTransition(new Explode());
        getWindow().setExitTransition(new Explode());
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    ButterKnife.bind(this);
    resolveData();
    final RecyclerNormalAdapter recyclerNormalAdapter = new RecyclerNormalAdapter(this, dataList);
    linearLayoutManager = new LinearLayoutManager(this);
    videoList.setLayoutManager(linearLayoutManager);
    videoList.setAdapter(recyclerNormalAdapter);
    videoList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        int firstVisibleItem, lastVisibleItem;

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            //大于0说明有播放
            if (GSYVideoManager.instance().getPlayPosition() >= 0) {
                //当前播放的位置
                int position = GSYVideoManager.instance().getPlayPosition();
                //对应的播放列表TAG
                if (GSYVideoManager.instance().getPlayTag().equals(ListNormalAdapter.TAG) && (position < firstVisibleItem || position > lastVisibleItem)) {
                    //如果滑出去了上面和下面就是否,和今日头条一样
                    GSYVideoPlayer.releaseAllVideos();
                    recyclerNormalAdapter.notifyDataSetChanged();
                }
            }
        }
    });
}
Also used : Explode(android.transition.Explode) RecyclerNormalAdapter(com.example.gsyvideoplayer.adapter.RecyclerNormalAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Explode (android.transition.Explode)1 RecyclerNormalAdapter (com.example.gsyvideoplayer.adapter.RecyclerNormalAdapter)1