BaseActivity 基类

public abstract class BaseActivity extends AppCompatActivity implements IBaseView {

private ProxyActivity mProxyActivity;

protected abstract void initLayout(@Nullable Bundle savedInstanceState);

protected abstract void initViews();

protected abstract void initData();


@SuppressWarnings("SameParameterValue")
protected <T extends View> T $(@IdRes int viewId) {
return findViewById(viewId);
}

@SuppressWarnings({"unchecked", "TryWithIdenticalCatches"})
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

initLayout(savedInstanceState);

mProxyActivity = createProxyActivity();
mProxyActivity.bindPresenter();

initViews();
initData();
}

@SuppressWarnings("unchecked")
private ProxyActivity createProxyActivity() {
if (mProxyActivity == null) {
return new ProxyActivity(this);
}
return mProxyActivity;
}

@Override
protected void onDestroy() {
super.onDestroy();
mProxyActivity.unbindPresenter();
}

@Override
public Context getContext() {
return this;
}
}
--------------------- 

posted on 2019-08-04 18:15  激流勇进1  阅读(709)  评论(0编辑  收藏  举报