Search in sources :

Example 1 with HomeArticleAdapter

use of com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter in project wanandroid by KnightAndroid.

the class HomeRecommendFragment method initView.

@Override
protected void initView(Bundle savedInstanceState) {
    mDatabind.setClick(new ProxyClick());
    EventBus.getDefault().register(this);
    mSkeletonScreen = Skeleton.bind(mDatabind.flTest).load(R.layout.activity_home_skeleton).duration(1200).angle(0).show();
    bindHeadView();
    mTopArticleAdapter = new TopArticleAdapter(new ArrayList<>());
    SetInitCustomView.initSwipeRecycleview(home_top_article_rv, new LinearLayoutManager(getActivity()), mTopArticleAdapter, false);
    mOfficialAccountAdapter = new OfficialAccountAdapter(new ArrayList<>());
    mHomeArticleAdapter = new HomeArticleAdapter(new ArrayList<>());
    SetInitCustomView.initSwipeRecycleview(mDatabind.homeRecommendArticleBody, new LinearLayoutManager(getActivity()), mHomeArticleAdapter, true);
    topArticleFootView = LayoutInflater.from(getActivity()).inflate(R.layout.home_toparticle_foot, null);
    topArticleFootView.findViewById(R.id.home_ll_seemorearticles).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            HomeArticleLogic.getInstance().setArrowAnimate(mTopArticleAdapter, topArticleFootView.findViewById(R.id.home_iv_toparticlearrow), isShowOnlythree);
            isShowOnlythree = !isShowOnlythree;
        }
    });
    mDatabind.homeIconFab.setBackgroundTintList(ColorUtils.createColorStateList(CacheUtils.getThemeColor(), CacheUtils.getThemeColor()));
    initTopAdapterClick();
    initOfficialAccountClick();
    initArticleListener();
    initTwoLevel();
    mDatabind.homeRefreshLayout.setOnMultiListener(new SimpleMultiListener() {

        @Override
        public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
        }

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            lazyLoadData();
        }

        @Override
        public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
            if (oldState == RefreshState.TwoLevel) {
                mDatabind.homeTwoLevelContent.animate().alpha(0).setDuration(0);
            } else if (oldState == RefreshState.TwoLevelReleased) {
                openTwoLevel = true;
                mDatabind.homeIconFab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.base_icon_bottom));
            } else if (oldState == RefreshState.TwoLevelFinish) {
                openTwoLevel = false;
                mDatabind.homeIconFab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.base_icon_up));
            }
        }
    });
    mDatabind.homeTwoLevelHeader.setOnTwoLevelListener(new OnTwoLevelListener() {

        @Override
        public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
            mDatabind.homeTwoLevelContent.animate().alpha(1).setDuration(1000);
            return true;
        }
    });
    mDatabind.homeTwoLevelHeader.setEnablePullToCloseTwoLevel(false);
    mDatabind.homeRefreshLayout.setEnableLoadMore(true);
    mDatabind.homeRefreshLayout.setOnLoadMoreListener(this);
}
Also used : RefreshHeader(com.scwang.smart.refresh.layout.api.RefreshHeader) ArrayList(java.util.ArrayList) HomeArticleAdapter(com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) TextView(android.widget.TextView) SetInitCustomView(com.knight.wanandroid.library_widget.SetInitCustomView) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) OfficialAccountAdapter(com.knight.wanandroid.module_home.module_adapter.OfficialAccountAdapter) SimpleMultiListener(com.scwang.smart.refresh.layout.simple.SimpleMultiListener) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) OnTwoLevelListener(com.scwang.smart.refresh.header.listener.OnTwoLevelListener) RefreshState(com.scwang.smart.refresh.layout.constant.RefreshState) TopArticleAdapter(com.knight.wanandroid.module_home.module_adapter.TopArticleAdapter)

Example 2 with HomeArticleAdapter

use of com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter in project wanandroid by KnightAndroid.

the class HomeArticlesFragment method initView.

@Override
protected void initView(Bundle savedInstanceState) {
    EventBus.getDefault().register(this);
    mHomeArticleAdapter = new HomeArticleAdapter(new ArrayList<>());
    SetInitCustomView.initSwipeRecycleview(mDatabind.homeArticleBody, new LinearLayoutManager(getActivity()), mHomeArticleAdapter, true);
    mDatabind.homeArticleBody.setAdapter(mHomeArticleAdapter);
    mDatabind.homeArticleFreshlayout.setOnLoadMoreListener(this);
    mDatabind.homeArticleFreshlayout.setOnRefreshListener(this);
    mHomeArticleAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
            ARouterUtils.startWeb(mHomeArticleAdapter.getData().get(position).getLink(), mHomeArticleAdapter.getData().get(position).getTitle(), mHomeArticleAdapter.getData().get(position).getId(), mHomeArticleAdapter.getData().get(position).isCollect(), mHomeArticleAdapter.getData().get(position).getEnvelopePic(), mHomeArticleAdapter.getData().get(position).getDesc(), mHomeArticleAdapter.getData().get(position).getChapterName(), TextUtils.isEmpty(mHomeArticleAdapter.getData().get(position).getAuthor()) ? mHomeArticleAdapter.getData().get(position).getShareUser() : mHomeArticleAdapter.getData().get(position).getAuthor());
        }
    });
    mHomeArticleAdapter.addChildClickViewIds(R.id.home_icon_collect);
    mHomeArticleAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {

        @LoginCheck
        @Override
        public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
            if (view.getId() == R.id.home_icon_collect) {
                if (mHomeArticleAdapter.getData().get(position).isCollect()) {
                    mPresenter.requestCancelCollectArticle(mHomeArticleAdapter.getData().get(position).getId(), position);
                } else {
                    mPresenter.requestCollectArticle(mHomeArticleAdapter.getData().get(position).getId(), position);
                }
            }
        }
    });
    // 反馈文章链接错误
    mHomeArticleAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
            FeedBackDialog.newInstance(mHomeArticleAdapter.getData().get(position).getId()).showAllowingStateLoss(getParentFragmentManager(), "feedbackDialog");
            return false;
        }
    });
    loadLoading(mDatabind.llHome);
}
Also used : OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) ArrayList(java.util.ArrayList) LoginCheck(com.knight.wanandroid.library_aop.loginintercept.LoginCheck) OnItemChildClickListener(com.chad.library.adapter.base.listener.OnItemChildClickListener) HomeArticleAdapter(com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SetInitCustomView(com.knight.wanandroid.library_widget.SetInitCustomView) View(android.view.View) OnItemLongClickListener(com.chad.library.adapter.base.listener.OnItemLongClickListener)

Aggregations

View (android.view.View)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 SetInitCustomView (com.knight.wanandroid.library_widget.SetInitCustomView)2 HomeArticleAdapter (com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter)2 ArrayList (java.util.ArrayList)2 TextView (android.widget.TextView)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 OnItemChildClickListener (com.chad.library.adapter.base.listener.OnItemChildClickListener)1 OnItemClickListener (com.chad.library.adapter.base.listener.OnItemClickListener)1 OnItemLongClickListener (com.chad.library.adapter.base.listener.OnItemLongClickListener)1 LoginCheck (com.knight.wanandroid.library_aop.loginintercept.LoginCheck)1 OfficialAccountAdapter (com.knight.wanandroid.module_home.module_adapter.OfficialAccountAdapter)1 TopArticleAdapter (com.knight.wanandroid.module_home.module_adapter.TopArticleAdapter)1 OnTwoLevelListener (com.scwang.smart.refresh.header.listener.OnTwoLevelListener)1 RefreshHeader (com.scwang.smart.refresh.layout.api.RefreshHeader)1 RefreshLayout (com.scwang.smart.refresh.layout.api.RefreshLayout)1 RefreshState (com.scwang.smart.refresh.layout.constant.RefreshState)1 SimpleMultiListener (com.scwang.smart.refresh.layout.simple.SimpleMultiListener)1 SwipeRecyclerView (com.yanzhenjie.recyclerview.SwipeRecyclerView)1