Skip to content

Commit

Permalink
docs(0.9.6): 增加注释
Browse files Browse the repository at this point in the history
Signed-off-by: free46000 <[email protected]>
  • Loading branch information
free46000 committed Apr 23, 2017
1 parent 422165d commit 0200924
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,30 @@ protected void initViews() {
recyclerView.setAdapter(adapter);
adapter.addDataItem(new TextBean("展示空白页"));
adapter.addDataItem(new TextBean("展示错误页"));

//设置点击监听,再点击Item的时候展示空白或者错误页面
setOnItemClickListener(adapter);
//初始化空白页辅助类
emptyViewHelper = newStateViewHelper("列表数据为空");
//初始化错误页辅助类
errorViewHelper = newStateViewHelper("数据加载错误");
}

initEmptyHelper();
initErrorHelper();
/**
* 创建新的状态页辅助类
*
* @param message 状态页展示的信息
* @return StateViewHelper
*/
private StateViewHelper newStateViewHelper(String message) {
BaseItemState stateItem = new ItemEmptyAndError(message);
StateViewHelper stateViewHelper = new StateViewHelper(recyclerView, stateItem);
stateItem.setOnStateClickListener(() -> errorViewHelper.hide());
return stateViewHelper;
}

/**
* 设置点击监听,再点击Item的时候展示空白或者错误页面
*/
private void setOnItemClickListener(BaseItemAdapter adapter) {
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
Expand All @@ -77,16 +94,4 @@ public void onItemClick(BaseViewHolder viewHolder) {
});
}

private void initEmptyHelper() {
BaseItemState emptyItem = new ItemEmptyAndError("列表数据为空");
emptyViewHelper = new StateViewHelper(recyclerView, emptyItem);
emptyItem.setOnStateClickListener(() -> emptyViewHelper.hide());
}

private void initErrorHelper() {
BaseItemState emptyItem = new ItemEmptyAndError("数据加载错误");
errorViewHelper = new StateViewHelper(recyclerView, emptyItem);
emptyItem.setOnStateClickListener(() -> emptyViewHelper.hide());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void initViews() {
R.layout.item_info, BR.itemData));
recyclerView.setAdapter(adapter);

//构建用户信息需要展示的ItemInfo的集合,每个ItemInfo代表页面中的一行
List<ItemInfo> list = new ArrayList<>(5);
list.add(new ItemInfo("名字", userBean.getName()));
list.add(new ItemInfo("性别", userBean.getSex()));
Expand All @@ -57,7 +58,11 @@ protected void initViews() {
adapter.setDataItems(list);
}


/**
* 获取用户信息
*
* @return UserBean
*/
private UserBean getUserBean() {
UserBean userBean = new UserBean();
userBean.setName("张三");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.freelib.multiitem.item.BaseItemState;

/**
* 空白 错误页Item
* Created by free46000 on 2017/4/23.
*/
public class ItemEmptyAndError extends BaseItemState<ItemEmptyAndError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import com.freelib.multiitem.item.BaseItemState;

/**
* 状态页(如空白错误页等)辅助类
* <p>
* 状态页展示时会作为RecyclerView的唯一的Item展示在界面中
* 注意:需要在RecyclerView设置完adapter后在初始化本实例
* Created by free46000 on 2017/4/23.
*/
public class StateViewHelper {
Expand All @@ -15,21 +19,28 @@ public class StateViewHelper {

private RecyclerView.Adapter dataAdapter;
private BaseItemAdapter stateAdapter;
private boolean isShowState;

/**
* 需要在RecyclerView设置完adapter后在初始化本实例
*
* @param recyclerView
* @param itemState
*/
public StateViewHelper(@NonNull RecyclerView recyclerView, BaseItemState itemState) {
public StateViewHelper(@NonNull RecyclerView recyclerView, @NonNull BaseItemState itemState) {
this.recyclerView = recyclerView;
//记住RecyclerView初始的Adapter
this.dataAdapter = recyclerView.getAdapter();
if (dataAdapter == null) {
throw new IllegalArgumentException("请在设置完adapter后在初始化本实例!");
}
this.itemState = itemState;
}

/**
* 展示状态页
* <p>
* 为RecyclerView设置新的stateAdapter,本adapter中保存唯一的状态页Item{@link BaseItemState}
*/
public void show() {
if (stateAdapter != null) {
return;
Expand All @@ -39,6 +50,11 @@ public void show() {
recyclerView.setAdapter(stateAdapter);
}

/**
* 隐藏状态页
* <p>
* 将RecyclerView的Adapter设置为初始化时记住的Adapter
*/
public void hide() {
if (dataAdapter == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.freelib.multiitem.listener.OnStateClickListener;

/**
* 基础的状态页Item(如:空白页 错误页...)
* Created by free46000 on 2017/4/23.
*/
public abstract class BaseItemState<T extends BaseItemState> extends BindViewHolderManager<T> implements ItemManager {
Expand All @@ -17,6 +18,11 @@ public OnStateClickListener getOnStateClickListener() {
return onStateClickListener;
}

/**
* 设置状态页面中按钮的点击监听
*
* @param onStateClickListener OnStateClickListener
*/
public void setOnStateClickListener(OnStateClickListener onStateClickListener) {
this.onStateClickListener = onStateClickListener;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.freelib.multiitem.listener;

import com.freelib.multiitem.helper.StateViewHelper;
import com.freelib.multiitem.item.BaseItemState;

/**
* 状态页中的点击Listener
* Created by free46000 on 2017/4/23.
*
* @see BaseItemState
* @see StateViewHelper
*/
@FunctionalInterface
public interface OnStateClickListener {

void onStateClick();
}

0 comments on commit 0200924

Please sign in to comment.