提交 44d8f932 编写于 作者: J jessyan

improve ActivityDelegateImpl and FragmentDelegateImpl

上级 ff54a0ec
......@@ -30,7 +30,13 @@ public class ActivityDelegateImpl implements ActivityDelegate {
public void onCreate(Bundle savedInstanceState) {
if (iActivity.useEventBus())//如果要使用eventbus请将此方法返回true
EventBus.getDefault().register(mActivity);//注册到事件主线
mActivity.setContentView(iActivity.initView());
try {
int layoutResID = iActivity.initView();
if (layoutResID != 0)//如果initView返回0,框架则不会调用setContentView()
mActivity.setContentView(layoutResID);
} catch (Exception e) {
e.printStackTrace();
}
//绑定到butterknife
mUnbinder = ButterKnife.bind(mActivity);
iActivity.setupActivityComponent(((App) mActivity.getApplication()).getAppComponent());//依赖注入
......
......@@ -35,7 +35,7 @@ public class FragmentDelegateImpl implements FragmentDelegate {
@Override
public void onAttach(Context context) {
iFragment.setupFragmentComponent(((App) mFragment.getActivity().getApplication()).getAppComponent());
}
@Override
......@@ -54,7 +54,6 @@ public class FragmentDelegateImpl implements FragmentDelegate {
public void onActivityCreate(Bundle savedInstanceState) {
if (iFragment.useEventBus())//如果要使用eventbus请将此方法返回true
EventBus.getDefault().register(mFragment);//注册到事件主线
iFragment.setupFragmentComponent(((App) mFragment.getActivity().getApplication()).getAppComponent());
iFragment.initData();
}
......
......@@ -19,6 +19,11 @@ public interface IActivity {
boolean useEventBus();
/**
* 如果initView返回0,框架则不会调用{@link android.app.Activity#setContentView(int)}
*
* @return
*/
int initView();
void initData();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册