Search in sources :

Example 1 with Article

use of me.yokeyword.sample.demo_zhihu.entity.Article 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(R.string.home);
    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正常
                extraTransaction().addSharedElement(((FirstHomeAdapter.VH) vh).img, getString(R.string.image_transition)).addSharedElement(((FirstHomeAdapter.VH) vh).tvTitle, "tv").start(fragment);
            } else {
                start(fragment);
            }
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 8; 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)

Example 2 with Article

use of me.yokeyword.sample.demo_zhihu.entity.Article in project Fragmentation by YoKeyword.

the class FirstPagerFragment method initView.

private void initView(View view) {
    mRecy = (RecyclerView) view.findViewById(R.id.recy);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
    mTitles = getResources().getStringArray(R.array.array_title);
    mContents = getResources().getStringArray(R.array.array_content);
    mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    mRefreshLayout.setOnRefreshListener(this);
    mAdapter = new HomeAdapter(_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) {
            // 这里的DetailFragment在flow包里
            // 这里是父Fragment启动,要注意 栈层级
            ((SupportFragment) getParentFragment()).start(DetailFragment.newInstance(mAdapter.getItem(position).getTitle()));
        }
    });
    // Init Datas
    List<Article> articleList = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        int index = (int) (Math.random() * 3);
        Article article = new Article(mTitles[index], mContents[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) {
                mAtTop = true;
            } else {
                mAtTop = false;
            }
        }
    });
}
Also used : OnItemClickListener(me.yokeyword.sample.demo_zhihu.listener.OnItemClickListener) Article(me.yokeyword.sample.demo_zhihu.entity.Article) ArrayList(java.util.ArrayList) HomeAdapter(me.yokeyword.sample.demo_zhihu.adapter.HomeAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 3 with Article

use of me.yokeyword.sample.demo_zhihu.entity.Article in project Fragmentation by YoKeyword.

the class FirstHomeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(VH holder, int position) {
    Article item = mItems.get(position);
    // 把每个图片视图设置不同的Transition名称, 防止在一个视图内有多个相同的名称, 在变换的时候造成混乱
    // Fragment支持多个View进行变换, 使用适配器时, 需要加以区分
    ViewCompat.setTransitionName(holder.img, String.valueOf(position) + "_image");
    ViewCompat.setTransitionName(holder.tvTitle, String.valueOf(position) + "_tv");
    holder.img.setImageResource(item.getImgRes());
    holder.tvTitle.setText(item.getTitle());
}
Also used : Article(me.yokeyword.sample.demo_zhihu.entity.Article)

Example 4 with Article

use of me.yokeyword.sample.demo_zhihu.entity.Article in project Fragmentation by YoKeyword.

the class HomeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Article item = mItems.get(position);
    holder.tvTitle.setText(item.getTitle());
    holder.tvContent.setText(item.getContent());
}
Also used : Article(me.yokeyword.sample.demo_zhihu.entity.Article)

Aggregations

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