Search in sources :

Example 1 with AutoRefreshUtil

use of me.dkzwm.widget.srl.util.AutoRefreshUtil in project SmoothRefreshLayout by dkzwm.

the class WithWebViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_webview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.with_webView);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_webView);
    MaterialHeader header = new MaterialHeader(this);
    header.setPadding(0, PixelUtl.dp2px(this, 20), 0, PixelUtl.dp2px(this, 20));
    mRefreshLayout.setHeaderView(header);
    mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshing() {
            mWebView.loadUrl("https://github.com/dkzwm");
        }
    });
    mWebView = findViewById(R.id.webView_with_webView);
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            mRefreshLayout.refreshComplete();
        }
    });
    mRefreshLayout.autoRefresh(false);
    mAutoRefreshUtil = new AutoRefreshUtil(mWebView);
    mRefreshLayout.addLifecycleObserver(mAutoRefreshUtil);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) WebView(android.webkit.WebView) AutoRefreshUtil(me.dkzwm.widget.srl.util.AutoRefreshUtil) WebViewClient(android.webkit.WebViewClient)

Example 2 with AutoRefreshUtil

use of me.dkzwm.widget.srl.util.AutoRefreshUtil in project SmoothRefreshLayout by dkzwm.

the class TestScrollToAutoRefreshActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_scroll_to_auto_refresh);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_scroll_to_auto_refresh);
    RecyclerView recyclerView = findViewById(R.id.recyclerView_test_scroll_to_auto_refresh);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    mAdapter = new RecyclerViewAdapter(this, getLayoutInflater());
    recyclerView.setAdapter(mAdapter);
    mLottieHeader = new CustomLottieHeader(this);
    mLottieHeader.setAnimation(NAME_OF_ANIMATION_JSON[mIndex]);
    mLottieHeader.setScale(.15f);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_scroll_to_auto_refresh);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setHeaderView(mLottieHeader);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshing() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount = list.size();
                    mAdapter.updateData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }

        @Override
        public void onLoadingMore() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount += list.size();
                    mAdapter.appendData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    mRefreshLayout.addOnStatusChangedListener(new SmoothRefreshLayout.OnStatusChangedListener() {

        @Override
        public void onStatusChanged(byte old, byte now) {
            if (now == SmoothRefreshLayout.SR_STATUS_INIT && old == SmoothRefreshLayout.SR_STATUS_COMPLETE) {
                if (mIndex >= NAME_OF_ANIMATION_JSON.length - 1) {
                    mIndex = 0;
                } else {
                    mIndex++;
                }
                mLottieHeader.setAnimation(NAME_OF_ANIMATION_JSON[mIndex]);
            }
        }
    });
    mRefreshLayout.setSpringInterpolator(new OvershootInterpolator(3));
    mRefreshLayout.autoRefresh(false);
    mAutoRefreshUtil = new AutoRefreshUtil(recyclerView);
    mRefreshLayout.addLifecycleObserver(mAutoRefreshUtil);
    findViewById(R.id.button_test_scroll_to_auto_refresh_left).setOnClickListener(this);
    findViewById(R.id.button_test_scroll_to_auto_refresh_right).setOnClickListener(this);
}
Also used : RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) OvershootInterpolator(android.view.animation.OvershootInterpolator) RecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CustomLottieHeader(me.dkzwm.widget.srl.sample.header.CustomLottieHeader) MaterialSmoothRefreshLayout(me.dkzwm.widget.srl.MaterialSmoothRefreshLayout) SmoothRefreshLayout(me.dkzwm.widget.srl.SmoothRefreshLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) AutoRefreshUtil(me.dkzwm.widget.srl.util.AutoRefreshUtil)

Aggregations

RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)2 AutoRefreshUtil (me.dkzwm.widget.srl.util.AutoRefreshUtil)2 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MaterialSmoothRefreshLayout (me.dkzwm.widget.srl.MaterialSmoothRefreshLayout)1 SmoothRefreshLayout (me.dkzwm.widget.srl.SmoothRefreshLayout)1 MaterialHeader (me.dkzwm.widget.srl.extra.header.MaterialHeader)1 RecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.RecyclerViewAdapter)1 CustomLottieHeader (me.dkzwm.widget.srl.sample.header.CustomLottieHeader)1