use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter 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();
}
use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter 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);
}
}
});
}
use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.
the class NestedLayoutExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_region);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
View view = findViewById(R.id.recyclerView);
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(new BaseRecyclerAdapter<String>(Arrays.asList(provinces), android.R.layout.simple_list_item_1) {
@Override
protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
holder.text(android.R.id.text1, model);
}
}.setOnItemClickListener(this));
}
/**
* 以下代码仅仅为了演示效果而已,不是必须的
* 关键代码在 activity_example_assign_xml 中
*/
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
if (isFirstEnter && refreshLayout != null) {
isFirstEnter = false;
// 触发上拉加载
refreshLayout.autoRefresh();
}
}
use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.
the class BasicExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_basic);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
AbsListView listView = (AbsListView) findViewById(R.id.listView);
listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(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);
}
});
mAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BottomSheetDialog dialog = new BottomSheetDialog(BasicExampleActivity.this);
View dialogView = View.inflate(BasicExampleActivity.this, R.layout.activity_example_basic, null);
dialog.setContentView(dialogView);
AbsListView listView = (AbsListView) dialogView.findViewById(R.id.listView);
listView.setAdapter(mAdapter);
ViewGroup parentGroup = (ViewGroup) listView.getParent();
parentGroup.removeView(listView);
// ViewGroup parentRoot = (ViewGroup) parentGroup.getParent();
// parentRoot.removeView(parentGroup);
RecyclerView recyclerView = new RecyclerView(BasicExampleActivity.this);
recyclerView.setLayoutManager(new LinearLayoutManager(BasicExampleActivity.this));
recyclerView.setAdapter(mAdapter);
((SmartRefreshLayout) parentGroup).setEnableRefresh(false);
// ((SmartRefreshLayout) parentGroup).startNestedScroll(0);
// ((SmartRefreshLayout) parentGroup).setEnableOverScrollDrag(false);
((SmartRefreshLayout) parentGroup).setRefreshContent(recyclerView);
// parentRoot.addView(recyclerView, -1, -1);
dialog.show();
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
// 开启自动加载功能(非必须)
refreshLayout.setEnableAutoLoadMore(true);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.refresh(initData());
refreshLayout.finishRefresh();
refreshLayout.setNoMoreData(false);
}
}, 2000);
}
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
if (mAdapter.getItemCount() > 30) {
Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
// 将不会再次触发加载更多事件
refreshLayout.finishLoadMoreWithNoMoreData();
} else {
mAdapter.loadMore(initData());
refreshLayout.finishLoadMore();
}
}
}, 2000);
}
});
// 触发自动刷新
refreshLayout.autoRefresh();
}
use of com.scwang.refreshlayout.adapter.BaseRecyclerAdapter in project SmartRefreshLayout by scwang90.
the class CustomExampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_custom);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(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);
}
});
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
refreshLayout.getLayout().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.refresh(initData());
refreshLayout.finishRefresh();
}
}, 2000);
}
});
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setHeaderHeight(60);
// 触发自动刷新
if (isFirstEnter) {
isFirstEnter = false;
refreshLayout.autoRefresh();
} else {
mAdapter.refresh(initData());
}
}
Aggregations