Skip to content

Commit

Permalink
#update loading
Browse files Browse the repository at this point in the history
  • Loading branch information
meng.wu1 committed Dec 1, 2022
1 parent 96237a4 commit 91e1d94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class DataBindingFragment : BaseFragment<MVVMMediator>() {

//todo 方式2
mMediator.getPing2LiveData().observeRequest(this) {
onLoading { }
onLoading {showLoadingDialog("")}
onSuccess { }
onFailure { }
onFinish { }
onFinish { hideLoadingDialog()}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.mirkowu.lib_widget.dialog.LoadingDialog;

import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;

/**
* 更多可配置的
Expand All @@ -32,6 +33,8 @@ public abstract class BaseMVMActivity<M extends BaseMediator> extends AppCompatA
protected M mMediator;
private LoadingDialog mLoadingDialog;

private AtomicInteger mLoading = new AtomicInteger(0);


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -95,12 +98,13 @@ public void showLoadingDialog(final String msg) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mLoadingDialog != null && mLoadingDialog.isVisible()) {
if (mLoading.getAndIncrement() != 0 && mLoadingDialog != null) {
mLoadingDialog.setMessage(msg);
return;
}
mLoadingDialog = new LoadingDialog(msg);
if (!isFinishing() && !mLoadingDialog.isVisible()) {

if (!isFinishing()) {
mLoadingDialog = new LoadingDialog(msg);
mLoadingDialog.showAllowingStateLoss(getSupportFragmentManager());
}
}
Expand All @@ -112,7 +116,7 @@ public void hideLoadingDialog() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mLoadingDialog != null) {
if (mLoading.decrementAndGet() == 0 && mLoadingDialog != null) {
mLoadingDialog.dismissAllowingStateLoss();
mLoadingDialog = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public class SingleLiveData<T> extends MutableLiveData<T> {

private final AtomicBoolean mPending = new AtomicBoolean(false);

public SingleLiveData() {
super();
}

public SingleLiveData(T value) {
super(value);
}

@MainThread
public void observe(LifecycleOwner owner, final Observer<? super T> observer) {

Expand Down

0 comments on commit 91e1d94

Please sign in to comment.