Search in sources :

Example 1 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestQQActivityStyleActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_qq_activity_style);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_qq_activity_style);
    mRecyclerView = findViewById(R.id.recyclerView_test_qq_activity_style);
    mRadioGroup = findViewById(R.id.radioGroup_test_qq_activity_style_container);
    mRadioButtonNormal = findViewById(R.id.radioButton_test_qq_activity_style_normal);
    mRadioButtonActivity = findViewById(R.id.radioButton_test_qq_activity_style_activity);
    mRadioGroup.setOnCheckedChangeListener(this);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new RecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_qq_activity_style);
    mClassicHeader = new ClassicHeader(this);
    mClassicHeader.setLastUpdateTimeKey("header_last_update_time");
    mClassicFooter = new ClassicFooter(this);
    mClassicFooter.setLastUpdateTimeKey("footer_last_update_time");
    mRefreshLayout.setHeaderView(mClassicHeader);
    mRefreshLayout.setFooterView(mClassicFooter);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.updateData(list);
                    } else {
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.appendData(list);
                    }
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    mRefreshLayout.addOnUIPositionChangedListener(new SmoothRefreshLayout.OnUIPositionChangedListener() {

        @Override
        public void onChanged(byte status, IIndicator indicator) {
            if (mRefreshLayout.isInStartPosition()) {
                mRadioGroup.setEnabled(true);
                mRadioButtonNormal.setEnabled(true);
                mRadioButtonActivity.setEnabled(true);
            } else {
                mRadioGroup.setEnabled(false);
                mRadioButtonNormal.setEnabled(false);
                mRadioButtonActivity.setEnabled(false);
            }
        }
    });
    mRefreshLayout.autoRefresh(false);
}
Also used : ClassicHeader(me.dkzwm.widget.srl.extra.header.ClassicHeader) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ClassicFooter(me.dkzwm.widget.srl.extra.footer.ClassicFooter) RecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SmoothRefreshLayout(me.dkzwm.widget.srl.SmoothRefreshLayout) IIndicator(me.dkzwm.widget.srl.indicator.IIndicator)

Example 2 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestReleaseToRefreshActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_refresh);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.release_to_refresh);
    mTextView = findViewById(R.id.textView_test_refresh_desc);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_refresh);
    mStoreHouseHeader = new StoreHouseHeader(this);
    mStoreHouseHeader.initPathWithString("RELEASE TO REFRESH", PixelUtl.dp2px(this, 18), PixelUtl.dp2px(this, 24));
    mStoreHouseHeader.setTextColor(Color.WHITE);
    mStoreHouseHeader.setPadding(0, PixelUtl.dp2px(this, 20), 0, PixelUtl.dp2px(this, 20));
    mRefreshLayout.setHeaderView(mStoreHouseHeader);
    mRefreshLayout.setRatioToKeepHeader(1);
    mRefreshLayout.setRatioOfHeaderToRefresh(1);
    mRefreshLayout.setDisableLoadMore(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(boolean isRefresh) {
            mCount++;
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mRefreshLayout.refreshComplete();
                    String times = getString(R.string.number_of_refresh) + mCount;
                    mTextView.setText(times);
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh(false);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) StoreHouseHeader(me.dkzwm.widget.srl.sample.header.StoreHouseHeader)

Example 3 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class WithGridViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_gridview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_gridView);
    mGridView = findViewById(R.id.gridView_with_grid);
    mAdapter = new ListViewAdapter(this, getLayoutInflater());
    mGridView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_gridView);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.materialStyle();
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 15);
                        mCount += 15;
                        mAdapter.updateData(list);
                        mRefreshLayout.refreshComplete();
                    } else {
                        List<String> list = DataUtil.createList(mCount, 15);
                        mCount += 15;
                        mAdapter.appendData(list);
                        mRefreshLayout.setDurationToCloseFooter(0);
                        mGridView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                            @Override
                            public boolean onPreDraw() {
                                mGridView.getViewTreeObserver().removeOnPreDrawListener(this);
                                mRefreshLayout.refreshComplete();
                                mRefreshLayout.setDurationToCloseFooter(500);
                                return false;
                            }
                        });
                    }
                }
            }, 2000);
        }
    });
    mRefreshLayout.autoRefresh(false);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ListViewAdapter(me.dkzwm.widget.srl.sample.adapter.ListViewAdapter) ViewTreeObserver(android.view.ViewTreeObserver)

Example 4 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class WithListViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_listview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_listView);
    mListView = findViewById(R.id.listView_with_list);
    mAdapter = new ListViewAdapter(this, getLayoutInflater());
    mListView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_listView);
    mClassicHeader = findViewById(R.id.classicHeader_with_listView);
    mClassicHeader.setLastUpdateTimeKey("header_last_update_time");
    mClassicFooter = findViewById(R.id.classicFooter_with_listView);
    mClassicFooter.setLastUpdateTimeKey("footer_last_update_time");
    mClassicHeader.setTitleTextColor(Color.WHITE);
    mClassicHeader.setLastUpdateTextColor(Color.GRAY);
    mRefreshLayout.setEnableKeepRefreshView(true);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            if (!isRefresh) {
                Toast.makeText(WithListViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
            }
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.updateData(list);
                        mRefreshLayout.setEnableNoMoreData(false);
                    } else {
                        if (mCount > 50) {
                            mRefreshLayout.setEnableNoMoreData(true);
                        } else {
                            List<String> list = DataUtil.createList(mCount, 20);
                            mCount += 20;
                            mAdapter.appendData(list);
                        }
                    }
                    mRefreshLayout.refreshComplete(1200);
                }
            }, 5000);
        }

        @Override
        public void onRefreshComplete(boolean isSuccessful) {
            Toast.makeText(WithListViewActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
            if (mRefreshLayout.getState() != Constants.STATE_CONTENT)
                mRefreshLayout.setState(Constants.STATE_CONTENT, false);
        }
    });
    mRefreshLayout.setRatioToKeep(1);
    mRefreshLayout.setRatioToRefresh(1);
    mRefreshLayout.autoRefresh(false);
    findViewById(R.id.button_with_listView_change_empty_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_content_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_error_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_change_custom_state).setOnClickListener(this);
    findViewById(R.id.button_with_listView_disable_refresh).setOnClickListener(this);
    findViewById(R.id.button_with_listView_enable_refresh).setOnClickListener(this);
    findViewById(R.id.button_with_listView_disable_loadMore).setOnClickListener(this);
    findViewById(R.id.button_with_listView_enable_loadMore).setOnClickListener(this);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) ListViewAdapter(me.dkzwm.widget.srl.sample.adapter.ListViewAdapter)

Example 5 with RefreshingListenerAdapter

use of me.dkzwm.widget.srl.RefreshingListenerAdapter in project SmoothRefreshLayout by dkzwm.

the class TestHorizontalRecyclerViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_horizontal_recyclerview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_horizontal_recyclerView);
    mRecyclerView = findViewById(R.id.recyclerView_with_horizontal_recyclerView);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new HorizontalRecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_horizontal_recyclerView);
    MaterialHeader header = new MaterialHeader(this);
    header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
    mRefreshLayout.setHeaderView(header);
    MaterialFooter footer = new MaterialFooter(this);
    footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    mRefreshLayout.setFooterView(footer);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setEnablePinContentView(true);
    mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshBegin(final boolean isRefresh) {
            if (!isRefresh) {
                Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
            }
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (isRefresh) {
                        mCount = 0;
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.updateData(list);
                    } else {
                        List<String> list = DataUtil.createList(mCount, 20);
                        mCount += 20;
                        mAdapter.appendData(list);
                    }
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }

        @Override
        public void onRefreshComplete(boolean isSuccessful) {
            Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.sr_refresh_complete, Toast.LENGTH_SHORT).show();
        }
    });
    mRefreshLayout.setDurationToClose(800);
    mRefreshLayout.autoRefresh(false);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) MaterialFooter(me.dkzwm.widget.srl.extra.footer.MaterialFooter) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager) HorizontalRecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)

Aggregations

RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ClassicHeader (me.dkzwm.widget.srl.extra.header.ClassicHeader)4 MaterialHeader (me.dkzwm.widget.srl.extra.header.MaterialHeader)4 RecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter)4 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 SmoothRefreshLayout (me.dkzwm.widget.srl.SmoothRefreshLayout)3 IIndicator (me.dkzwm.widget.srl.indicator.IIndicator)3 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 ArrayList (java.util.ArrayList)2 MaterialFooter (me.dkzwm.widget.srl.extra.footer.MaterialFooter)2 ListViewAdapter (me.dkzwm.widget.srl.sample.adapter.ListViewAdapter)2 ViewPagerAdapter (me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter)2 PageFragment (me.dkzwm.widget.srl.sample.ui.fragment.PageFragment)2 Nullable (android.support.annotation.Nullable)1 ViewTreeObserver (android.view.ViewTreeObserver)1 TextView (android.widget.TextView)1 DrawerTransformer (com.ToxicBakery.viewpager.transforms.DrawerTransformer)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1