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);
}
Aggregations