Last active
May 26, 2017 13:40
-
-
Save andych008/8d9086c4527a70927660e02f318fe1b7 to your computer and use it in GitHub Desktop.
显示并隐藏loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 显示并隐藏loading | |
*/ | |
@SuppressWarnings("unchecked") | |
public static <T> Observable.Transformer<T, T> showLoading(final ILoading loading) { | |
return new Observable.Transformer<T, T>() { | |
@Override | |
public Observable<T> call(Observable<T> observable) { | |
return observable | |
.doOnSubscribe(new Action0() { | |
@Override | |
public void call() { | |
loading.showLoading(); | |
} | |
}).subscribeOn(AndroidSchedulers.mainThread()) | |
.doOnTerminate(new Action0() { | |
@Override | |
public void call() { | |
loading.hideLoading(); | |
} | |
}).observeOn(AndroidSchedulers.mainThread()); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Andy on 4/7/2016. | |
*/ | |
public interface ILoading { | |
void showLoading(); | |
void hideLoading(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void showLoading() { | |
showLoading(getString(R.string.loading)); | |
} | |
@Override | |
public void hideLoading() { | |
Observable.empty() | |
.observeOn(AndroidSchedulers.mainThread()) | |
.doOnTerminate(new Action0() { | |
@Override | |
public void call() { | |
//todo | |
} | |
}) | |
.subscribe(); | |
} | |
public void showLoading(String tip) { | |
Observable.just(tip) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new Action1<String>() { | |
@Override | |
public void call(String s) { | |
//todo | |
} | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.update() | |
.compose(RxUtils.<XXX>showLoading(MainActivity.this)) | |
.subscribe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems you need to use it in loading.java :
because you use
.observeOn(AndroidSchedulers.mainThread())
in