diff --git a/app/build.gradle b/app/build.gradle index 80c0314..d861a1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -116,7 +116,7 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' //是否使用本地lib - def useLocalModule = false + def useLocalModule = true if (!useLocalModule) { // implementation 'com.github.mirkowu:mvm:$ext.mvm_version' //可以直接依赖总仓库,也可以依赖指定库 implementation "com.github.mirkowu.mvm:lib_base:$ext.mvm_version" diff --git a/app/src/main/java/com/mirkowu/mvm/ui/mvvm/MVVMMediator.kt b/app/src/main/java/com/mirkowu/mvm/ui/mvvm/MVVMMediator.kt index 4283e10..89336ea 100644 --- a/app/src/main/java/com/mirkowu/mvm/ui/mvvm/MVVMMediator.kt +++ b/app/src/main/java/com/mirkowu/mvm/ui/mvvm/MVVMMediator.kt @@ -1,6 +1,5 @@ package com.mirkowu.mvm.ui.mvvm -import androidx.lifecycle.MutableLiveData import com.mirkowu.lib_base.mediator.BaseMediator import com.mirkowu.lib_base.util.RxLife import com.mirkowu.lib_base.util.RxScheduler @@ -10,6 +9,7 @@ import com.mirkowu.lib_network.ErrorType import com.mirkowu.lib_network.state.ResponseData import com.mirkowu.lib_network.state.ResponseLiveData import com.mirkowu.lib_util.LogUtil +import com.mirkowu.lib_util.livedata.SingleLiveData import com.mirkowu.lib_util.utilcode.util.NetworkUtils import com.mirkowu.mvm.BizModel import com.mirkowu.mvm.bean.GankBaseBean @@ -22,14 +22,14 @@ import io.reactivex.rxjava3.core.Observable open class MVVMMediator : BaseMediator() { @JvmField val mImageData = ResponseLiveData>() - var mLiveData = MutableLiveData() - var mError = MutableLiveData() + var mLiveData = SingleLiveData() + var mError = SingleLiveData() @JvmField - var mRequestImageListData = MutableLiveData>>() + var mRequestImageListData = SingleLiveData>>() @JvmField - var mImageError = MutableLiveData() + var mImageError = SingleLiveData() var mPingResult = ResponseLiveData() diff --git a/lib_base/src/main/java/com/mirkowu/lib_base/event/StateBean.java b/lib_base/src/main/java/com/mirkowu/lib_base/event/StateBean.java index 8a291ce..ed60ffb 100644 --- a/lib_base/src/main/java/com/mirkowu/lib_base/event/StateBean.java +++ b/lib_base/src/main/java/com/mirkowu/lib_base/event/StateBean.java @@ -1,19 +1,19 @@ -package com.mirkowu.lib_base.event; - -import java.io.Serializable; - -public class StateBean implements Serializable { - private static final long serialVersionUID = 330324159087062791L; - public int state; - public int code; - public String msg; - - public StateBean() { - } - - public StateBean(int state, int code, String msg) { - this.state = state; - this.code = code; - this.msg = msg; - } -} +//package com.mirkowu.lib_base.event; +// +//import java.io.Serializable; +// +//public class StateBean implements Serializable { +// private static final long serialVersionUID = 330324159087062791L; +// public int state; +// public int code; +// public String msg; +// +// public StateBean() { +// } +// +// public StateBean(int state, int code, String msg) { +// this.state = state; +// this.code = code; +// this.msg = msg; +// } +//} diff --git a/lib_base/src/main/java/com/mirkowu/lib_base/event/UiChangeEvent.java b/lib_base/src/main/java/com/mirkowu/lib_base/event/UiChangeEvent.java index 64efccc..9eb6198 100644 --- a/lib_base/src/main/java/com/mirkowu/lib_base/event/UiChangeEvent.java +++ b/lib_base/src/main/java/com/mirkowu/lib_base/event/UiChangeEvent.java @@ -1,127 +1,127 @@ -package com.mirkowu.lib_base.event; - -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.Observer; - -import com.mirkowu.lib_base.view.IBaseView; - -public class UiChangeEvent { - private SingleLiveEvent mIsShowLoadingDialogEvent; - private SingleLiveEvent mIsEmptyViewEvent; - private SingleLiveEvent mIsDismissViewEvent; - private SingleLiveEvent mIsReloadViewEvent; - private SingleLiveEvent mJumpPathEvent; - private SingleLiveEvent mJumpPathParamsEvent; - private SingleLiveEvent mStateViewEvent; - //显示 、隐藏 -// private SingleLiveEvent mErrorEvent;//加载中、网络错误、服务器异常、(点击刷新)、空数据 - - public UiChangeEvent() { - } - - public MutableLiveData getShowLoadingDialogEvent() { - return this.mIsShowLoadingDialogEvent = this.getLiveData(this.mIsShowLoadingDialogEvent); - } - - public MutableLiveData getStateViewEvent() { - return this.mStateViewEvent = this.getLiveData(this.mStateViewEvent); - } - - public MutableLiveData getEmptyViewEvent() { - return this.mIsEmptyViewEvent = this.getLiveData(this.mIsEmptyViewEvent); - } - - public MutableLiveData getDismissViewEvent() { - return this.mIsDismissViewEvent = this.getLiveData(this.mIsDismissViewEvent); - } - - public MutableLiveData getReloadViewEvent() { - return this.mIsReloadViewEvent = this.getLiveData(this.mIsReloadViewEvent); - } - - public MutableLiveData getJumpPagePathEvent() { - return this.mJumpPathEvent = this.getLiveData(this.mJumpPathEvent); - } - - public MutableLiveData getJumpPageParamsEvent() { - return this.mJumpPathParamsEvent = this.getLiveData(this.mJumpPathParamsEvent); - } - - private SingleLiveEvent getLiveData(SingleLiveEvent mutableLiveData) { - if (mutableLiveData == null) { - mutableLiveData = new SingleLiveEvent<>(); - } - - return mutableLiveData; - } - - public void unregisterEvent(@NonNull LifecycleOwner owner) { - getShowLoadingDialogEvent().removeObservers(owner); - getStateViewEvent().removeObservers(owner); - } - - public void registerEvent(@NonNull LifecycleOwner owner, final IBaseView iBaseView) { - getShowLoadingDialogEvent().observe(owner, new Observer() { - public void onChanged(Boolean aBoolean) { - if (aBoolean) { - iBaseView.showLoadingDialog(); - } else { - iBaseView.hideLoadingDialog(); - } - } - }); - - - getStateViewEvent().observe(owner, new Observer() { - public void onChanged(StateBean stateBean) { - - //stateBean.state== - // iBaseView.showStateView(); - - - } - }); -// getEmptyViewEvent().observe(owner, new Observer() { -// public void onChanged(Boolean aBoolean) { -// if (aBoolean) { -// iBaseView.showEmptyView(); -// } +//package com.mirkowu.lib_base.event; // -// } -// }); +//import android.os.Bundle; +// +//import androidx.annotation.NonNull; +//import androidx.lifecycle.LifecycleOwner; +//import androidx.lifecycle.MutableLiveData; +//import androidx.lifecycle.Observer; +// +//import com.mirkowu.lib_base.view.IBaseView; +// +//public class UiChangeEvent { +// private SingleLiveEvent mIsShowLoadingDialogEvent; +// private SingleLiveEvent mIsEmptyViewEvent; +// private SingleLiveEvent mIsDismissViewEvent; +// private SingleLiveEvent mIsReloadViewEvent; +// private SingleLiveEvent mJumpPathEvent; +// private SingleLiveEvent mJumpPathParamsEvent; +// private SingleLiveEvent mStateViewEvent; +// //显示 、隐藏 +//// private SingleLiveEvent mErrorEvent;//加载中、网络错误、服务器异常、(点击刷新)、空数据 +// +// public UiChangeEvent() { +// } +// +// public MutableLiveData getShowLoadingDialogEvent() { +// return this.mIsShowLoadingDialogEvent = this.getLiveData(this.mIsShowLoadingDialogEvent); +// } +// +// public MutableLiveData getStateViewEvent() { +// return this.mStateViewEvent = this.getLiveData(this.mStateViewEvent); +// } +// +// public MutableLiveData getEmptyViewEvent() { +// return this.mIsEmptyViewEvent = this.getLiveData(this.mIsEmptyViewEvent); +// } // +// public MutableLiveData getDismissViewEvent() { +// return this.mIsDismissViewEvent = this.getLiveData(this.mIsDismissViewEvent); +// } // -// getReloadViewEvent().observe(owner, new Observer() { +// public MutableLiveData getReloadViewEvent() { +// return this.mIsReloadViewEvent = this.getLiveData(this.mIsReloadViewEvent); +// } +// +// public MutableLiveData getJumpPagePathEvent() { +// return this.mJumpPathEvent = this.getLiveData(this.mJumpPathEvent); +// } +// +// public MutableLiveData getJumpPageParamsEvent() { +// return this.mJumpPathParamsEvent = this.getLiveData(this.mJumpPathParamsEvent); +// } +// +// private SingleLiveEvent getLiveData(SingleLiveEvent mutableLiveData) { +// if (mutableLiveData == null) { +// mutableLiveData = new SingleLiveEvent<>(); +// } +// +// return mutableLiveData; +// } +// +// public void unregisterEvent(@NonNull LifecycleOwner owner) { +// getShowLoadingDialogEvent().removeObservers(owner); +// getStateViewEvent().removeObservers(owner); +// } +// +// public void registerEvent(@NonNull LifecycleOwner owner, final IBaseView iBaseView) { +// getShowLoadingDialogEvent().observe(owner, new Observer() { // public void onChanged(Boolean aBoolean) { // if (aBoolean) { -// iBaseView.showReloadView(); +// iBaseView.showLoadingDialog(); +// } else { +// iBaseView.hideLoadingDialog(); // } -// // } // }); // -// getJumpPagePathEvent().observe(owner, new Observer() { -// public void onChanged(String path) { -// iBaseView.jumpPage(path); -// } -// }); // +// getStateViewEvent().observe(owner, new Observer() { +// public void onChanged(StateBean stateBean) { +// +// //stateBean.state== +// // iBaseView.showStateView(); // -// getJumpPageParamsEvent().observe(owner, new Observer() { -// public void onChanged(Bundle paramsMap) { -// if (paramsMap.containsKey("JUMP_PAGE_PATH_KEY")) { -// String path = paramsMap.getString("JUMP_PAGE_PATH_KEY"); -// if (!TextUtils.isEmpty(path)) { -// paramsMap.remove("JUMP_PAGE_PATH_KEY"); -// iBaseView.jumpPage(path, paramsMap); -// } -// } // // } // }); - } -} +//// getEmptyViewEvent().observe(owner, new Observer() { +//// public void onChanged(Boolean aBoolean) { +//// if (aBoolean) { +//// iBaseView.showEmptyView(); +//// } +//// +//// } +//// }); +//// +//// +//// getReloadViewEvent().observe(owner, new Observer() { +//// public void onChanged(Boolean aBoolean) { +//// if (aBoolean) { +//// iBaseView.showReloadView(); +//// } +//// +//// } +//// }); +//// +//// getJumpPagePathEvent().observe(owner, new Observer() { +//// public void onChanged(String path) { +//// iBaseView.jumpPage(path); +//// } +//// }); +//// +//// +//// getJumpPageParamsEvent().observe(owner, new Observer() { +//// public void onChanged(Bundle paramsMap) { +//// if (paramsMap.containsKey("JUMP_PAGE_PATH_KEY")) { +//// String path = paramsMap.getString("JUMP_PAGE_PATH_KEY"); +//// if (!TextUtils.isEmpty(path)) { +//// paramsMap.remove("JUMP_PAGE_PATH_KEY"); +//// iBaseView.jumpPage(path, paramsMap); +//// } +//// } +//// +//// } +//// }); +// } +//} diff --git a/lib_network/src/main/java/com/mirkowu/lib_network/state/LiveDataUtil.kt b/lib_network/src/main/java/com/mirkowu/lib_network/state/LiveDataUtil.kt index 9dba496..d81e6f1 100644 --- a/lib_network/src/main/java/com/mirkowu/lib_network/state/LiveDataUtil.kt +++ b/lib_network/src/main/java/com/mirkowu/lib_network/state/LiveDataUtil.kt @@ -2,8 +2,8 @@ package com.mirkowu.lib_network.state import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import com.mirkowu.lib_network.ErrorBean +import com.mirkowu.lib_util.livedata.SingleLiveData /** @@ -29,4 +29,4 @@ inline fun LiveData>.observerRequest(owner: LifecycleOwner, /** * 提供类型别名,减少泛型嵌套 */ -typealias ResponseLiveData = MutableLiveData> \ No newline at end of file +typealias ResponseLiveData = SingleLiveData> \ No newline at end of file diff --git a/lib_qrcode/src/main/java/com/king/zxing/DefaultCameraScan.java b/lib_qrcode/src/main/java/com/king/zxing/DefaultCameraScan.java index 2eecbfb..c990473 100644 --- a/lib_qrcode/src/main/java/com/king/zxing/DefaultCameraScan.java +++ b/lib_qrcode/src/main/java/com/king/zxing/DefaultCameraScan.java @@ -25,7 +25,6 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LifecycleOwner; -import androidx.lifecycle.MutableLiveData; import com.google.common.util.concurrent.ListenableFuture; import com.google.zxing.BarcodeFormat; @@ -38,6 +37,7 @@ import com.king.zxing.manager.AmbientLightManager; import com.king.zxing.manager.BeepManager; import com.king.zxing.util.QrLogUtils; +import com.mirkowu.lib_util.livedata.SingleLiveData; import java.util.concurrent.Executors; @@ -83,7 +83,7 @@ public class DefaultCameraScan extends CameraScan { private View flashlightView; - private MutableLiveData mResultLiveData; + private SingleLiveData mResultLiveData; private OnScanResultCallback mOnScanResultCallback; @@ -129,7 +129,7 @@ public boolean onScale(ScaleGestureDetector detector) { }; private void initData(){ - mResultLiveData = new MutableLiveData<>(); + mResultLiveData = new SingleLiveData<>(); mResultLiveData.observe(mLifecycleOwner, result -> { if(result != null){ handleAnalyzeResult(result); diff --git a/lib_base/src/main/java/com/mirkowu/lib_base/event/SingleLiveEvent.java b/lib_util/src/main/java/com/mirkowu/lib_util/livedata/SingleLiveData.java similarity index 94% rename from lib_base/src/main/java/com/mirkowu/lib_base/event/SingleLiveEvent.java rename to lib_util/src/main/java/com/mirkowu/lib_util/livedata/SingleLiveData.java index 1367788..79effc6 100644 --- a/lib_base/src/main/java/com/mirkowu/lib_base/event/SingleLiveEvent.java +++ b/lib_util/src/main/java/com/mirkowu/lib_util/livedata/SingleLiveData.java @@ -1,4 +1,4 @@ -package com.mirkowu.lib_base.event; +package com.mirkowu.lib_util.livedata; import android.util.Log; @@ -11,7 +11,7 @@ import java.util.concurrent.atomic.AtomicBoolean; -public class SingleLiveEvent extends MutableLiveData { +public class SingleLiveData extends MutableLiveData { private static final String TAG = "SingleLiveEvent";