Search in sources :

Example 1 with OnLoadMoreListener

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

the class BottomSheetExampleFragment method onViewCreated.

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

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

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

                @Override
                public void run() {
                    mAdapter.loadMore(initData());
                    refreshLayout.finishLoadMore();
                }
            }, 2000);
        }
    });
    RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(initData(), simple_list_item_2) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
            holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
            holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    ((ViewGroup) refreshLayout.getLayout().getParent()).removeView(refreshLayout.getLayout());
    BottomSheetDialog dialog = new BottomSheetDialog(getContext());
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            getActivity().finish();
        }
    });
    dialog.setContentView(refreshLayout.getLayout());
    dialog.show();
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) DialogInterface(android.content.DialogInterface) ClassicsHeader(com.scwang.smartrefresh.layout.header.ClassicsHeader) ViewGroup(android.view.ViewGroup) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) R.id.recyclerView(com.scwang.refreshlayout.R.id.recyclerView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with OnLoadMoreListener

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

the class NestedScrollExampleFragment method onViewCreated.

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

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    final BaseRecyclerAdapter<Item> adapter;
    RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL));
    recyclerView.setAdapter(adapter = new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, NestedScrollExampleFragment.this) {

        @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.name);
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    if (mNestedPager) {
        final Runnable loadMore = new Runnable() {

            @Override
            public void run() {
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
                adapter.loadMore(Arrays.asList(Item.values()));
            }
        };
        final RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
        refreshLayout.setEnableFooterFollowWhenLoadFinished(true);
        refreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                if (adapter.getItemCount() < 20) {
                    loadMore.run();
                    refreshLayout.finishLoadMore(2000);
                } else {
                    refreshLayout.finishLoadMoreWithNoMoreData();
                }
            }
        });
        loadMore.run();
    }
    /*
         * 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画
         */
    AppBarLayout appBarLayout = (AppBarLayout) root.findViewById(R.id.appbar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        boolean misAppbarExpand = true;

        View fab = root.findViewById(R.id.fab);

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            int scrollRange = appBarLayout.getTotalScrollRange();
            float fraction = 1f * (scrollRange + verticalOffset) / scrollRange;
            if (fraction < 0.1 && misAppbarExpand) {
                misAppbarExpand = false;
                fab.animate().scaleX(0).scaleY(0);
            }
            if (fraction > 0.8 && !misAppbarExpand) {
                misAppbarExpand = true;
                fab.animate().scaleX(1).scaleY(1);
            }
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) 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) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ClassicsFooter(com.scwang.smartrefresh.layout.footer.ClassicsFooter) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with OnLoadMoreListener

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

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

use of com.scwang.smartrefresh.layout.listener.OnLoadMoreListener 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)17 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)14 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)13 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)12 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)12 RecyclerView (android.support.v7.widget.RecyclerView)6 View (android.view.View)6 Toolbar (android.support.v7.widget.Toolbar)5 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)5 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)4 AdapterView (android.widget.AdapterView)4 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)4 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 WeicoAdapter (com.gapcoder.weico.Index.Adapter.WeicoAdapter)3 Intent (android.content.Intent)2 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)2 ViewGroup (android.view.ViewGroup)2 AbsListView (android.widget.AbsListView)2 ImageView (android.widget.ImageView)2