Search in sources :

Example 1 with HomeCommonAdapter

use of com.seven.seven.home.adapter.HomeCommonAdapter in project seven_develop by seven123456.

the class HomeFragment method initRecyclerView.

/*
    * 初始化recycler并且初始化headview添加到recycler里面
    * */
private void initRecyclerView() {
    recyclerView.setLayoutManager(linearLayoutManager);
    homeCommonAdapter = new HomeCommonAdapter(R.layout.recycler_item_home_news, newsInfosList, getContext());
    initHeadView();
    homeCommonAdapter.setOnLoadMoreListener(this, recyclerView);
    homeCommonAdapter.disableLoadMoreIfNotFullPage();
    homeCommonAdapter.addHeaderView(headView);
    recyclerView.setAdapter(homeCommonAdapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        // Drawable drawable = getContext().getResources().getDrawable(R.drawable.home_toolbar_bg);
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            // if (isFirst) {
            // int toolbarHeight = appBarLayout.getMeasuredHeight();
            int toolbarHeight = getResources().getDimensionPixelSize(R.dimen.main_title_bar_height);
            int scollyHeight = recyclerView.computeVerticalScrollOffset();
            if (scollyHeight >= (toolbarHeight * 2)) {
                /*此时toolbar和状态栏完全显示红色*/
                // appBarLayout.setVisibility(View.VISIBLE);
                // drawable.setAlpha(255);
                // appBarLayout.setBackground(drawable);
                homeTitleBar.setBgAlpha(1);
            } else if (scollyHeight >= toolbarHeight) {
                /*
                        * 渐变过程
                        * */
                // appBarLayout.setVisibility(View.VISIBLE);
                // drawable.setAlpha((int) (255 * ((scollyHeight - toolbarHeight) / (toolbarHeight * 1.5F))));
                // appBarLayout.setBackground(drawable);
                homeTitleBar.setBgAlpha((scollyHeight - toolbarHeight) / (toolbarHeight * 2F));
            } else {
                /*
                        * 状态栏透明
                        * */
                // appBarLayout.setVisibility(View.GONE);
                homeTitleBar.setBgAlpha(0);
            }
            // } else {
            // isFirst = true;
            // }
            super.onScrolled(recyclerView, dx, dy);
        }
    });
    homeCommonAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {

        @Override
        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
            HomeNewsInfos.NewsInfos newsInfos = (HomeNewsInfos.NewsInfos) adapter.getItem(position);
            HomeToWebViewInfo homeToWebViewInfo = new HomeToWebViewInfo();
            homeToWebViewInfo.h5Url = newsInfos.getLink();
            homeToWebViewInfo.imgUrl = newsInfos.getEnvelopePic();
            homeToWebViewInfo.title = newsInfos.getTitle();
            homeToWebViewInfo.id = newsInfos.getId();
            homeToWebViewInfo.collect = newsInfos.isCollect();
            Intent intent = new Intent(getContext(), HomeNewsDetailActivity.class);
            intent.putExtra("newsInfo", homeToWebViewInfo);
            /*
                * item 里面的img设置一个属性,相对应页面的img里面也必须设置
                * getResources().getString(R.string.transition_news_img)
                * */
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) getContext(), view.findViewById(R.id.iv_right), getResources().getString(R.string.transition_news_img));
            ActivityCompat.startActivity(getContext(), intent, options.toBundle());
        }
    });
}
Also used : MainActivity(com.seven.seven.ui.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent) ErrorLayoutView(com.seven.seven.common.view.ErrorLayoutView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) HomeToWebViewInfo(com.seven.seven.home.model.HomeToWebViewInfo) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) HomeNewsInfos(com.seven.seven.home.model.HomeNewsInfos) HomeNewsInfos(com.seven.seven.home.model.HomeNewsInfos) RecyclerView(android.support.v7.widget.RecyclerView) HomeCommonAdapter(com.seven.seven.home.adapter.HomeCommonAdapter)

Aggregations

Activity (android.app.Activity)1 Intent (android.content.Intent)1 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 ErrorLayoutView (com.seven.seven.common.view.ErrorLayoutView)1 HomeCommonAdapter (com.seven.seven.home.adapter.HomeCommonAdapter)1 HomeNewsInfos (com.seven.seven.home.model.HomeNewsInfos)1 HomeToWebViewInfo (com.seven.seven.home.model.HomeToWebViewInfo)1 MainActivity (com.seven.seven.ui.MainActivity)1