Search in sources :

Example 6 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder 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 7 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder 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 8 with SmartViewHolder

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

the class DeliveryStyleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_style_delivery);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setStatusBarColor(0xfff0f0f0);
    }
    if (Build.VERSION.SDK_INT >= 23) {
        Window window = getWindow();
        int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
        systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    }
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 第一次进入触发自动刷新,演示效果
        mRefreshLayout.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(new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), listitem_style_delivery, this) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
            }
        });
    }
}
Also used : Window(android.view.Window) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 9 with SmartViewHolder

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

the class FunGameHitBlockStyleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 第一次进入触发自动刷新,演示效果
        mRefreshLayout.autoRefresh();
    }
    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(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);
            }
        });
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 10 with SmartViewHolder

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

the class PhoenixStyleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 第一次进入触发自动刷新,演示效果
        mRefreshLayout.autoRefresh();
    }
    mAppBarLayout = (AppBarLayout) findViewById(R.id.appbar);
    mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbarLayout);
    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(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;
    }
    /*
         * 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画
         */
    mActionButton = (FloatingActionButton) findViewById(R.id.fab);
    mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        boolean misAppbarExpand = true;

        View fab = 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 : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout)

Aggregations

View (android.view.View)29 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)29 RecyclerView (android.support.v7.widget.RecyclerView)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)26 AdapterView (android.widget.AdapterView)25 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)23 Toolbar (android.support.v7.widget.Toolbar)13 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)11 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)8 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)4 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)4 AppBarLayout (android.support.design.widget.AppBarLayout)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)2 AbsListView (android.widget.AbsListView)2 TextView (android.widget.TextView)2 R.id.recyclerView (com.scwang.refreshlayout.R.id.recyclerView)2 Item (com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item)2