Search in sources :

Example 6 with BaseRecyclerAdapter

use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.

the class RepastPracticeActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setEnableFooterFollowWhenLoadFinished(true);
    // 第一次进入演示刷新
    if (isFirstEnter) {
        isFirstEnter = false;
        refreshLayout.autoRefresh();
    }
    // 初始化列表和监听
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter<Model>(loadModels(), R.layout.listitem_practice_repast) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Model model, int position) {
                holder.text(R.id.name, model.name);
                holder.text(R.id.nickname, model.nickname);
                holder.image(R.id.image, model.imageId);
                holder.image(R.id.avatar, model.avatarId);
            }
        });
        refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

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

                    @Override
                    public void run() {
                        refreshLayout.finishRefresh();
                        // 恢复上拉状态
                        refreshLayout.setNoMoreData(false);
                    }
                }, 2000);
            }

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

                    @Override
                    public void run() {
                        if (mAdapter.getCount() > 12) {
                            Toast.makeText(getBaseContext(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
                            // 设置之后,将不会再触发加载事件
                            refreshLayout.finishLoadMoreWithNoMoreData();
                        } else {
                            mAdapter.loadMore(loadModels());
                            refreshLayout.finishLoadMore();
                        }
                    }
                }, 1000);
            }
        });
        refreshLayout.getLayout().postDelayed(new Runnable() {

            @Override
            public void run() {
                refreshLayout.setHeaderInsetStart(DensityUtil.px2dp(toolbar.getHeight()));
            }
        }, 500);
    }
    // 状态栏透明和间距处理
    StatusBarUtil.darkMode(this);
    StatusBarUtil.setPaddingSmart(this, view);
    StatusBarUtil.setPaddingSmart(this, toolbar);
    StatusBarUtil.setPaddingSmart(this, findViewById(R.id.blurView));
}
Also used : OnRefreshLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with BaseRecyclerAdapter

use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.

the class ClassicsStyleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    int delta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
    mClassicsHeader = (ClassicsHeader) mRefreshLayout.getRefreshHeader();
    mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis() - delta));
    mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新于 MM-dd HH:mm", Locale.CHINA));
    mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新于 %s"));
    // mDrawableProgress = mClassicsHeader.getProgressView().getDrawable();
    mDrawableProgress = ((ImageView) mClassicsHeader.findViewById(ClassicsHeader.ID_IMAGE_PROGRESS)).getDrawable();
    if (mDrawableProgress instanceof LayerDrawable) {
        mDrawableProgress = ((LayerDrawable) mDrawableProgress).getDrawable(0);
    }
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdpater = new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, 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.nameId);
                holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
            }
        });
        mRecyclerView = recyclerView;
    }
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发自动刷新
        mRefreshLayout.autoRefresh();
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) Date(java.util.Date) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Random(java.util.Random) LayerDrawable(android.graphics.drawable.LayerDrawable) RecyclerView(android.support.v7.widget.RecyclerView) SimpleDateFormat(java.text.SimpleDateFormat) DynamicTimeFormat(com.scwang.refreshlayout.util.DynamicTimeFormat)

Example 8 with BaseRecyclerAdapter

use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.

the class NestedScrollExampleFragmentIntegral 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();
        }
    });
    Banner banner = (Banner) root.findViewById(R.id.banner);
    banner.setImageLoader(new BannerImageLoader());
    banner.setImages(Arrays.asList(image_weibo_home_2, gif_header_repast));
    banner.start();
    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<Item>(buildItems(), simple_list_item_2, NestedScrollExampleFragmentIntegral.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);
        }
    });
    RefreshLayout refreshLayout = (RefreshLayout) root.findViewById(R.id.refreshLayout);
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

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

                @Override
                public void run() {
                    mAdapter.loadMore(buildItems());
                    refreshLayout.finishLoadMore();
                }
            }, 2000);
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) Banner(com.youth.banner.Banner) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) 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) Item(com.scwang.refreshlayout.fragment.example.NestedScrollExampleFragment.Item) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

View (android.view.View)8 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)8 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 RecyclerView (android.support.v7.widget.RecyclerView)7 Toolbar (android.support.v7.widget.Toolbar)7 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)7 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)6 AdapterView (android.widget.AdapterView)6 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)5 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)4 ImageView (android.widget.ImageView)3 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)2 ViewGroup (android.view.ViewGroup)2 AbsListView (android.widget.AbsListView)2 TextView (android.widget.TextView)2 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)2 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)2 DialogInterface (android.content.DialogInterface)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1