Search in sources :

Example 1 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class TwoLevelPracticeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);
    final Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
    final TwoLevelHeader header = (TwoLevelHeader) root.findViewById(R.id.header);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    header.setOnTwoLevelListener(new OnTwoLevelListener() {

        @Override
        public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
            Toast.makeText(getContext(), "触发二楼事件", Toast.LENGTH_SHORT).show();
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    header.finishTwoLevel();
                }
            }, 5000);
            // true 将会展开二楼状态 false 关闭刷新
            return true;
        }
    });
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            Toast.makeText(getContext(), "触发刷新事件", Toast.LENGTH_SHORT).show();
            refreshLayout.finishRefresh(2000);
        }
    });
    // 状态栏透明和间距处理
    StatusBarUtil.immersive(getActivity());
    StatusBarUtil.setPaddingSmart(getActivity(), root.findViewById(R.id.toolbar));
}
Also used : TwoLevelHeader(com.scwang.smartrefresh.layout.header.TwoLevelHeader) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) OnTwoLevelListener(com.scwang.smartrefresh.layout.api.OnTwoLevelListener) View(android.view.View) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener 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 3 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project SmartRefreshLayout by scwang90.

the class BannerPracticeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_practice_banner);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    mAdapter = new QuickAdapter();
    recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(mAdapter);
    final List<Movie> movies = new Gson().fromJson(JSON_MOVIES, new TypeToken<ArrayList<Movie>>() {
    }.getType());
    mAdapter.replaceData(movies);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

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

                @Override
                public void run() {
                    if (mAdapter.getItemCount() < 2) {
                        List<Movie> movies = new Gson().fromJson(JSON_MOVIES, new TypeToken<ArrayList<Movie>>() {
                        }.getType());
                        mAdapter.replaceData(movies);
                    }
                    refreshLayout.finishRefresh();
                }
            }, 2000);
        }
    });
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
            mAdapter.addData(movies);
            refreshLayout.finishLoadMoreWithNoMoreData();
        }
    });
    // 添加Header
    View header = LayoutInflater.from(this).inflate(R.layout.listitem_movie_header, recyclerView, false);
    Banner banner = (Banner) header;
    banner.setImageLoader(new GlideImageLoader());
    banner.setImages(BANNER_ITEMS);
    banner.start();
    mAdapter.addHeaderView(banner);
    mAdapter.openLoadAnimation();
    // 状态栏透明和间距处理
    StatusBarUtil.immersive(this);
    StatusBarUtil.setPaddingSmart(this, toolbar);
    StatusBarUtil.setPaddingSmart(this, recyclerView);
    StatusBarUtil.setMargin(this, findViewById(R.id.header));
    StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) Banner(com.youth.banner.Banner) Gson(com.google.gson.Gson) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) TypeToken(com.google.gson.reflect.TypeToken) RecyclerView(android.support.v7.widget.RecyclerView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project weibo by dingdangmao123.

the class WeicoFG method CreateView.

@Override
public void CreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, View v) {
    target.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            msg.hide(false);
            Intent i = new Intent(getActivity(), Message.class);
            startActivity(i);
        }
    });
    title.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final EasyPopup mCirclePop;
            mCirclePop = new EasyPopup(getActivity()).setContentView(R.layout.popmenu).setFocusAndOutsideEnable(true).createPopup();
            TextView t1 = mCirclePop.getView(R.id.t1);
            TextView t2 = mCirclePop.getView(R.id.t2);
            TextView t3 = mCirclePop.getView(R.id.t3);
            t1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mCirclePop.dismiss();
                    type = "new";
                    if (current != 1) {
                        reset = true;
                        current = 1;
                    } else {
                        reset = false;
                    }
                    title.setText("最新微博");
                    Refresh(1);
                }
            });
            t2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mCirclePop.dismiss();
                    type = "hot";
                    if (current != 2) {
                        reset = true;
                        current = 2;
                    } else {
                        reset = false;
                    }
                    title.setText("热门微博");
                    Refresh(1);
                }
            });
            t3.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mCirclePop.dismiss();
                    type = "care";
                    if (current != 3) {
                        reset = true;
                        current = 3;
                    } else {
                        reset = false;
                    }
                    title.setText("我关注的");
                    Refresh(1);
                }
            });
            mCirclePop.showAtAnchorView(v, VerticalGravity.BELOW, HorizontalGravity.ALIGN_LEFT, 0, 0);
        }
    });
    adapter = new WeicoAdapter(data, getActivity());
    tl.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
    tl.setAdapter(adapter);
    rf.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(RefreshLayout refreshlayout) {
            Refresh(1);
        }
    });
    rf.setOnLoadmoreListener(new OnLoadmoreListener() {

        @Override
        public void onLoadmore(RefreshLayout refreshlayout) {
            Refresh(0);
        }
    });
    msg = new QBadgeView(getActivity());
    msg.bindTarget(target).setBadgeGravity(Gravity.END | Gravity.TOP);
    getMessage();
    rf.autoRefresh();
}
Also used : Message(com.gapcoder.weico.Message.Message) Intent(android.content.Intent) QBadgeView(q.rorbin.badgeview.QBadgeView) EasyPopup(com.zyyoona7.lib.EasyPopup) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) QBadgeView(q.rorbin.badgeview.QBadgeView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) OnLoadmoreListener(com.scwang.smartrefresh.layout.listener.OnLoadmoreListener) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) TextView(android.widget.TextView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) WeicoAdapter(com.gapcoder.weico.Index.Adapter.WeicoAdapter)

Example 5 with OnRefreshListener

use of com.scwang.smartrefresh.layout.listener.OnRefreshListener in project weibo by dingdangmao123.

the class UserList method init.

@Override
public void init() {
    if ((uid = getIntent().getIntExtra("uid", 0)) == 0)
        return;
    type = getIntent().getStringExtra("type");
    if (type.equals("fans"))
        title.setText("粉丝");
    else
        title.setText("关注");
    adapter = new UserListAdapter(data, this);
    tl.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    tl.setAdapter(adapter);
    rf.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(RefreshLayout refreshlayout) {
            Refresh(1);
        }
    });
    rf.setOnLoadmoreListener(new OnLoadmoreListener() {

        @Override
        public void onLoadmore(RefreshLayout refreshlayout) {
            Refresh(0);
        }
    });
    rf.autoRefresh();
}
Also used : SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) OnLoadmoreListener(com.scwang.smartrefresh.layout.listener.OnLoadmoreListener) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener)

Aggregations

RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)20 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)20 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)11 View (android.view.View)10 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)10 Toolbar (android.support.v7.widget.Toolbar)8 RecyclerView (android.support.v7.widget.RecyclerView)6 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)4 WebView (android.webkit.WebView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 WeicoAdapter (com.gapcoder.weico.Index.Adapter.WeicoAdapter)3 Intent (android.content.Intent)2 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)2 ViewGroup (android.view.ViewGroup)2 WebViewClient (android.webkit.WebViewClient)2 AdapterView (android.widget.AdapterView)2 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)2 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)2