Search in sources :

Example 1 with RefreshHeaderWrapper

use of com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper in project SmartRefreshLayout by scwang90.

the class RefreshStylesFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    StatusBarUtil.setPaddingSmart(getContext(), root.findViewById(R.id.toolbar));
    View view = root.findViewById(recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
        recyclerView.setAdapter(new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, this) {

            @Override
            public SmartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                SmartViewHolder holder = super.onCreateViewHolder(parent, viewType);
                if (viewType == 0) {
                    holder.itemView.setVisibility(View.GONE);
                    holder.itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
                }
                return holder;
            }

            @Override
            public int getViewTypeCount() {
                return 2;
            }

            @Override
            public int getItemViewType(int position) {
                return position == 0 ? 0 : 1;
            }

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
                holder.text(android.R.id.text1, model.name());
                holder.text(android.R.id.text2, model.nameId);
                holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
            }
        });
    }
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    if (refreshLayout != null) {
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
                refreshLayout.finishRefresh(3000);
                refreshLayout.getLayout().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        RefreshHeader refreshHeader = refreshLayout.getRefreshHeader();
                        if (refreshHeader instanceof RefreshHeaderWrapper) {
                            refreshLayout.setRefreshHeader(new PhoenixHeader(getContext()));
                        } else if (refreshHeader instanceof PhoenixHeader) {
                            refreshLayout.setRefreshHeader(new DropBoxHeader(getContext()));
                        } else if (refreshHeader instanceof DropBoxHeader) {
                            refreshLayout.setRefreshHeader(new FunGameHitBlockHeader(getContext()));
                        } else if (refreshHeader instanceof FunGameHitBlockHeader) {
                            refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()));
                        } else {
                            refreshLayout.setRefreshHeader(new RefreshHeaderWrapper(new BallPulseFooter(getContext())));
                        }
                        refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
                    }
                }, 4000);
            }
        });
    }
}
Also used : RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) ViewGroup(android.view.ViewGroup) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) DropBoxHeader(com.scwang.smartrefresh.header.DropBoxHeader) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) BallPulseFooter(com.scwang.smartrefresh.layout.footer.BallPulseFooter) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) PhoenixHeader(com.scwang.smartrefresh.header.PhoenixHeader) RecyclerView(android.support.v7.widget.RecyclerView) FunGameHitBlockHeader(com.scwang.smartrefresh.header.FunGameHitBlockHeader) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener)

Example 2 with RefreshHeaderWrapper

use of com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper in project SmartRefreshLayout by scwang90.

the class TwoLevelHeader method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mSpinnerStyle = SpinnerStyle.MatchLayout;
    if (mRefreshHeader == null) {
        mRefreshHeader = new RefreshHeaderWrapper(this);
    }
}
Also used : RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)

Example 3 with RefreshHeaderWrapper

use of com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper in project SmartRefreshLayout by scwang90.

the class SmartRefreshLayout method onFinishInflate.

// </editor-fold>
// <editor-fold desc="生命周期 life cycle">
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    final int count = super.getChildCount();
    if (count > 3) {
        throw new RuntimeException("最多只支持3个子View,Most only support three sub view");
    }
    int contentLevel = 0;
    int indexContent = -1;
    for (int i = 0; i < count; i++) {
        View view = super.getChildAt(i);
        if (isScrollableView(view) && (contentLevel < 2 || i == 1)) {
            indexContent = i;
            contentLevel = 2;
        } else if (!(view instanceof RefreshInternal) && contentLevel < 1) {
            indexContent = i;
            contentLevel = i > 0 ? 1 : 0;
        }
    }
    // int[] indexArray = {1,0,2};
    // 
    // for (int index : indexArray) {
    // if (index < count) {
    // View view = super.getChildAt(index);
    // if (!(view instanceof RefreshInternal)) {
    // indexContent = index;
    // }
    // if (isScrollableView(view)) {
    // indexContent = index;
    // break;
    // }
    // }
    // }
    int indexHeader = -1;
    int indexFooter = -1;
    if (indexContent >= 0) {
        mRefreshContent = new RefreshContentWrapper(super.getChildAt(indexContent));
        if (indexContent == 1) {
            indexHeader = 0;
            if (count == 3) {
                indexFooter = 2;
            }
        } else if (count == 2) {
            indexFooter = 1;
        }
    }
    for (int i = 0; i < count; i++) {
        View view = super.getChildAt(i);
        if (i == indexHeader || (i != indexFooter && indexHeader == -1 && mRefreshHeader == null && view instanceof RefreshHeader)) {
            mRefreshHeader = (view instanceof RefreshHeader) ? (RefreshHeader) view : new RefreshHeaderWrapper(view);
        } else if (i == indexFooter || (indexFooter == -1 && view instanceof RefreshFooter)) {
            mEnableLoadMore = (mEnableLoadMore || !mManualLoadMore);
            mRefreshFooter = (view instanceof RefreshFooter) ? (RefreshFooter) view : new RefreshFooterWrapper(view);
        // } else if (mRefreshContent == null) {
        // mRefreshContent = new RefreshContentWrapper(view);
        }
    }
}
Also used : RefreshInternal(com.scwang.smartrefresh.layout.api.RefreshInternal) RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) RefreshFooter(com.scwang.smartrefresh.layout.api.RefreshFooter) RefreshFooterWrapper(com.scwang.smartrefresh.layout.impl.RefreshFooterWrapper) RefreshContentWrapper(com.scwang.smartrefresh.layout.impl.RefreshContentWrapper) View(android.view.View) TextView(android.widget.TextView) SmartUtil.isScrollableView(com.scwang.smartrefresh.layout.util.SmartUtil.isScrollableView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 4 with RefreshHeaderWrapper

use of com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper in project SmartRefreshLayout by scwang90.

the class TwoLevelHeader method onFinishInflate.

// </editor-fold>
// <editor-fold desc="生命周期">
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    final ViewGroup thisGroup = this;
    for (int i = 0, len = thisGroup.getChildCount(); i < len; i++) {
        View childAt = thisGroup.getChildAt(i);
        if (childAt instanceof RefreshHeader) {
            mWrapperView = childAt;
            mRefreshHeader = (RefreshHeader) childAt;
            thisGroup.bringChildToFront(childAt);
            break;
        }
    }
    if (mRefreshHeader == null) {
        mRefreshHeader = new RefreshHeaderWrapper(this);
    }
}
Also used : RefreshHeaderWrapper(com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper) RefreshHeader(com.scwang.smartrefresh.layout.api.RefreshHeader) ViewGroup(android.view.ViewGroup) View(android.view.View)

Aggregations

RefreshHeaderWrapper (com.scwang.smartrefresh.layout.impl.RefreshHeaderWrapper)4 View (android.view.View)3 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)3 ViewGroup (android.view.ViewGroup)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 R.id.recyclerView (com.scwang.refreshlayout.R.id.recyclerView)1 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)1 DropBoxHeader (com.scwang.smartrefresh.header.DropBoxHeader)1 FunGameHitBlockHeader (com.scwang.smartrefresh.header.FunGameHitBlockHeader)1 PhoenixHeader (com.scwang.smartrefresh.header.PhoenixHeader)1 RefreshFooter (com.scwang.smartrefresh.layout.api.RefreshFooter)1 RefreshInternal (com.scwang.smartrefresh.layout.api.RefreshInternal)1 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)1