Search in sources :

Example 1 with CustomLottieHeader

use of me.dkzwm.widget.srl.sample.header.CustomLottieHeader 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

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