Search in sources :

Example 1 with SingleTransformer

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;
        }
    };
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Bundle(android.os.Bundle) SingleSource(io.reactivex.SingleSource) Dialog(android.app.Dialog) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) DialogFragment(android.support.v4.app.DialogFragment) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Page(com.meisolsson.githubsdk.model.Page) R(com.gh4a.R) Schedulers(io.reactivex.schedulers.Schedulers) ApiRequestException(com.gh4a.ApiRequestException) Predicate(io.reactivex.functions.Predicate) List(java.util.List) SingleTransformer(io.reactivex.SingleTransformer) FragmentActivity(android.support.v4.app.FragmentActivity) Function(io.reactivex.functions.Function) Snackbar(android.support.design.widget.Snackbar) SearchPage(com.meisolsson.githubsdk.model.SearchPage) Comparator(java.util.Comparator) PublishProcessor(io.reactivex.processors.PublishProcessor) BaseActivity(com.gh4a.BaseActivity) Collections(java.util.Collections) SingleTransformer(io.reactivex.SingleTransformer) Single(io.reactivex.Single) Bundle(android.os.Bundle)

Aggregations

Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 StringRes (android.support.annotation.StringRes)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 Snackbar (android.support.design.widget.Snackbar)1 DialogFragment (android.support.v4.app.DialogFragment)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 ApiRequestException (com.gh4a.ApiRequestException)1 BaseActivity (com.gh4a.BaseActivity)1 R (com.gh4a.R)1 Page (com.meisolsson.githubsdk.model.Page)1 SearchPage (com.meisolsson.githubsdk.model.SearchPage)1 Single (io.reactivex.Single)1 SingleSource (io.reactivex.SingleSource)1 SingleTransformer (io.reactivex.SingleTransformer)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Function (io.reactivex.functions.Function)1 Predicate (io.reactivex.functions.Predicate)1 PublishProcessor (io.reactivex.processors.PublishProcessor)1 Schedulers (io.reactivex.schedulers.Schedulers)1