use of io.reactivex.SingleTransformer in project gh4a by slapperwan.
the class RxUtils method wrapWithProgressDialog.
public static <T> SingleTransformer<T, T> wrapWithProgressDialog(final FragmentActivity activity, @StringRes final int messageResId) {
return new SingleTransformer<T, T>() {
private ProgressDialogFragment mFragment;
@Override
public SingleSource<T> apply(Single<T> upstream) {
return upstream.doOnSubscribe(disposable -> showDialog()).doOnError(throwable -> hideDialog()).doOnSuccess(result -> hideDialog());
}
private void showDialog() {
Bundle args = new Bundle();
args.putInt("message_res", messageResId);
mFragment = new ProgressDialogFragment();
mFragment.setArguments(args);
mFragment.show(activity.getSupportFragmentManager(), "progressdialog");
}
private void hideDialog() {
if (mFragment.getActivity() != null) {
mFragment.dismissAllowingStateLoss();
}
mFragment = null;
}
};
}
Aggregations