Search in sources :

Example 1 with FirstHomeAdapter

use of me.yokeyword.sample.demo_zhihu.adapter.FirstHomeAdapter in project Fragmentation by YoKeyword.

the class FirstHomeFragment method initView.

private void initView(View view) {
    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mFab = (FloatingActionButton) view.findViewById(R.id.fab);
    mToolbar.setTitle("首页");
    mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new FirstHomeAdapter(_mActivity);
    LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
    mRecy.setLayoutManager(manager);
    mRecy.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
            FirstDetailFragment fragment = FirstDetailFragment.newInstance(mAdapter.getItem(position));
            // LOLLIPOP(5.0)系统的 SharedElement支持有 系统BUG, 这里判断大于 > LOLLIPOP
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                setExitTransition(new Fade());
                fragment.setEnterTransition(new Fade());
                fragment.setSharedElementReturnTransition(new DetailTransition());
                fragment.setSharedElementEnterTransition(new DetailTransition());
                // 25.1.0以下的support包,Material过渡动画只有在进栈时有,返回时没有;
                // 25.1.0+的support包,SharedElement正常
                fragment.transaction().addSharedElement(((FirstHomeAdapter.VH) vh).img, getString(R.string.image_transition)).addSharedElement(((FirstHomeAdapter.VH) vh).tvTitle, "tv").commit();
            }
            start(fragment);
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        int index = i % 5;
        Article article = new Article(mTitles[index], mImgRes[index]);
        articleList.add(article);
    }
    mAdapter.setDatas(articleList);
    mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollTotal += dy;
            if (mScrollTotal <= 0) {
                mInAtTop = true;
            } else {
                mInAtTop = false;
            }
            if (dy > 5) {
                mFab.hide();
            } else if (dy < -5) {
                mFab.show();
            }
        }
    });
    mFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(_mActivity, "Action", Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_zhihu.entity.Article) ArrayList(java.util.ArrayList) FirstHomeAdapter(me.yokeyword.sample.demo_zhihu.adapter.FirstHomeAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) DetailTransition(me.yokeyword.sample.demo_zhihu.helper.DetailTransition) Fade(android.transition.Fade)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Fade (android.transition.Fade)1 View (android.view.View)1 ArrayList (java.util.ArrayList)1 FirstHomeAdapter (me.yokeyword.sample.demo_zhihu.adapter.FirstHomeAdapter)1 Article (me.yokeyword.sample.demo_zhihu.entity.Article)1 DetailTransition (me.yokeyword.sample.demo_zhihu.helper.DetailTransition)1 OnItemClickListener (me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener)1