Skip to content

Commit

Permalink
#perf 优化base
Browse files Browse the repository at this point in the history
  • Loading branch information
MirkoWu committed Apr 19, 2023
1 parent df35349 commit 2dd0d21
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
34 changes: 16 additions & 18 deletions app/src/main/java/com/mirkowu/mvm/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.content.res.Resources;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;

import com.mirkowu.lib_base.activity.BaseMVMActivity;
Expand All @@ -27,33 +28,30 @@ protected M initMediator() {
protected void initStatusBar() {
BarUtils.setStatusBarLightMode(this, true);
}
// @Override
// public void showStateView(StateBean bean) {
//
// }
//
// @Override
// public void hideStateView() {
//
// }
//
// @Override
// public void onFailure() {
//
// }


/**
* 也可以放在Base中
*/
//protected VB mBinding;
//
@LayoutRes
protected int getLayoutId() {
return 0;
}

@Override
protected void bindContentView() {
setContentView(getLayoutId());
}
// protected VB mBinding;

// @Override
// protected void bindContentView() {
//// super.bindContentView();
// super.bindContentView();
// this.mBinding = (VB) DataBindingUtil.setContentView(this, getLayoutId());
// setContentView(mBinding.getRoot());
//
// }


@Override
public Resources getResources() {
//这个地方慎用,可能会导致在不恰当的时间 调用
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/com/mirkowu/mvm/ui/mvvm/MVVMActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ class MVVMActivity : BaseActivity<MVVMMediator?>(), RefreshHelper.OnRefreshListe
val binding by bindingView(ActivityMVVMBinding::inflate)
private lateinit var refreshHelper: RefreshHelper
private lateinit var imageAdapter: ImageAdapter
override fun getLayoutId(): Int {
return R.layout.activity_m_v_v_m
}

override fun bindContentView() {
setContentView(binding.root)
}

var isGrayMode=false
var isGrayMode = false
override fun initialize() {
refreshHelper = RefreshHelper(binding.mRefresh, binding.mRecyclerView, this)
imageAdapter = ImageAdapter()
Expand All @@ -53,10 +50,10 @@ class MVVMActivity : BaseActivity<MVVMMediator?>(), RefreshHelper.OnRefreshListe
"TAG",
"onItemChildClick: $position"
)
isGrayMode=!isGrayMode
if (isGrayMode){
isGrayMode = !isGrayMode
if (isGrayMode) {
ColorFilterUtils.setGrayFilter(activity)
}else{
} else {
ColorFilterUtils.removeFilter(activity)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/mirkowu/mvm/ui/webview/WebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class WebActivity : CommonWebActivity() {

}

override fun getLayoutId(): Int {
return R.layout.activity_web
override fun bindContentView() {
setContentView(R.layout.activity_web)
}

override fun getWebConfig(): WebConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* 更多可配置的
* MVM base 示例
* 可自行实现接口,重写
*/
public abstract class BaseMVMActivity<M extends BaseMediator> extends AppCompatActivity implements IBaseView {

Expand All @@ -51,13 +52,9 @@ protected void onCreateDelegate(@Nullable Bundle savedInstanceState) {
initialize();
}

protected void initialize(@Nullable Bundle savedInstanceState) {
}

/*** 绑定布局 */
protected void bindContentView() {
setContentView(getLayoutId());
}
protected abstract void bindContentView();


/*** 初始化状态栏 setContentView 之前*/
protected void initStatusBar() {
Expand All @@ -67,6 +64,9 @@ protected void initStatusBar() {
// BarUtils.transparentStatusBar(this);
}

protected void initialize(@Nullable Bundle savedInstanceState) {
}

/*** 绑定中间件 */
protected void bindMediator() {
//实现方式交给子类
Expand All @@ -87,6 +87,14 @@ private void detachMediator() {
}
}


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


@Override
public void showLoadingDialog() {
showLoadingDialog(getString(R.string.widget_loading));
Expand Down Expand Up @@ -140,12 +148,6 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
PermissionsUtils.getInstance().onActivityResult(this, requestCode, resultCode, data);
}

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

@Override
public void setRequestedOrientation(int requestedOrientation) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
Expand Down Expand Up @@ -199,11 +201,8 @@ public Lifecycle.Event bindLifecycleUntil() {
return Lifecycle.Event.ON_DESTROY;
}

protected abstract int getLayoutId();

protected abstract void initialize();

protected abstract M initMediator();


}
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public static void start(Context context, String title, String url, boolean newP
protected WebConfig mWebConfig;

@Override
protected BaseMediator initMediator() {
return null;
protected void bindContentView() {
setContentView(R.layout.webview_layout_common_web_view);
}

@Override
protected int getLayoutId() {
return R.layout.webview_layout_common_web_view;
protected BaseMediator initMediator() {
return null;
}

@Override
Expand Down

0 comments on commit 2dd0d21

Please sign in to comment.