-
Notifications
You must be signed in to change notification settings - Fork 5
MVP模式的使用
Drowning Coder edited this page Nov 14, 2018
·
1 revision
对应支持MVP模式开发,支持Presenter拆分和通信,支持ViewHolder依赖注入Presenter。
-
- 注册Presenter实体对象(可注册多个)
slotContext.registerLogic(new CommunityLogic(this))
.registerLogic(new CommonLogic(slotContext));
-
- ViewHolder获取Presenter实体
@ComponentType(value = ComponentId.TEXT_IMG)
//2.1使用ILogic注解,标识对应的Presenter
@ILogic(CommonLogic.class)
//2.2 实现IPresenterBind,实现依赖注入Presenter实体
public class TextImgLayout extends LinearLayout implements IComponentBind<CommonModel>,IPresenterBind<CommonLogic> {
private View root;
private TextView tvInfo;
private CommonLogic logic;
public TextImgLayout(Context context) {
this(context, null);
}
...
@Override
public void onBind(int pos, CommonModel item) {
tvInfo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (logic != null) {
logic.pageTransfer();
}
}
});
}
@Override
public void onUnBind() {
}
@Override
public void injectPresenter(CommonLogic commonLogic) {
this.logic = commonLogic;
}
}
欢迎Star👏~欢迎提issues和PR