io.reactivex.android.plugins.RxAndroidPlugins Java Examples

The following examples show how to use io.reactivex.android.plugins.RxAndroidPlugins. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxSchedulerRule.java    From MovieGuide with MIT License 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFunctionLazy);

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(schedulerFunction);
            RxJavaPlugins.setNewThreadSchedulerHandler(schedulerFunction);
            RxJavaPlugins.setComputationSchedulerHandler(schedulerFunction);

            base.evaluate();

            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example #2
Source File: App.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setUpRxPlugin() {
    Scheduler asyncMainThreadScheduler = AndroidSchedulers.from(Looper.getMainLooper(), true);
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> asyncMainThreadScheduler);
    RxJavaPlugins.setErrorHandler(e -> {
        if (e instanceof UndeliverableException) {
            e = e.getCause();
        }
        if ((e instanceof IOException) || (e instanceof SocketException)) {
            return;
        }
        if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
            Timber.d("Error in app");
            Thread.currentThread().getUncaughtExceptionHandler()
                    .uncaughtException(Thread.currentThread(),e);
        }
        if (e instanceof IllegalStateException) {
            Timber.d("Error in RxJava");
            Thread.currentThread().getUncaughtExceptionHandler()
                    .uncaughtException(Thread.currentThread(),e);
        }
        Timber.d(e);
    });
}
 
Example #3
Source File: MoviesViewModelTest.java    From android-mvvm-sample with MIT License 6 votes vote down vote up
@BeforeClass
public static void setupClass() {
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {
        @Override
        public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception {
            return Schedulers.trampoline();
        }
    });

    RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(Scheduler scheduler) throws Exception {
            return Schedulers.trampoline();
        }
    });
}
 
Example #4
Source File: MovieDetailsViewModelTest.java    From android-mvvm-sample with MIT License 6 votes vote down vote up
@BeforeClass
public static void setupRxJavaPlugins() {
    RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(Scheduler scheduler) throws Exception {
            return Schedulers.trampoline();
        }
    });

    RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {
        @Override
        public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception {
            return Schedulers.trampoline();
        }
    });
}
 
Example #5
Source File: AndroidSchedulersRule.java    From RIBs with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description) {
  if (restoreHandlers) {
    // https://github.com/ReactiveX/RxAndroid/pull/358
    //            originalInitMainThreadInitHandler =
    // RxAndroidPlugins.getInitMainThreadScheduler();
    //            originalMainThreadHandler = RxAndroidPlugins.getMainThreadScheduler();
  }
  RxAndroidPlugins.reset();
  RxAndroidPlugins.setInitMainThreadSchedulerHandler(
      new Function<Callable<Scheduler>, Scheduler>() {
        @Override
        public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception {
          return delegatingMainThreadScheduler;
        }
      });
  RxAndroidPlugins.setMainThreadSchedulerHandler(
      new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(Scheduler scheduler) throws Exception {
          return delegatingMainThreadScheduler;
        }
      });
}
 
Example #6
Source File: RxSchedulersRule.java    From quill with MIT License 6 votes vote down vote up
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            Scheduler scheduler = TrampolineScheduler.instance();
            Function<Callable<Scheduler>, Scheduler> schedulerFn = __ -> scheduler;
            RxJavaPlugins.reset();
            RxJavaPlugins.setInitIoSchedulerHandler(schedulerFn);
            RxJavaPlugins.setInitNewThreadSchedulerHandler(schedulerFn);
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFn);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example #7
Source File: RxSchedulersOverrideRule.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline());

            base.evaluate();

            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example #8
Source File: ImmediateSchedulersRule.java    From RxCommand with MIT License 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {

            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler ->  Schedulers.trampoline());
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable ->  Schedulers.trampoline());

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example #9
Source File: TestComponentRule.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerMapperLazy);

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(schedulerMapper);
            RxJavaPlugins.setNewThreadSchedulerHandler(schedulerMapper);
            RxJavaPlugins.setComputationSchedulerHandler(schedulerMapper);

            TavernaApplication application = TavernaApplication.get(mContext);
            application.setComponent(mTestComponent);

            base.evaluate();
            application.setComponent(null);
            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example #10
Source File: RxSchedulersOverrideRule.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(mRxAndroidSchedulersHook);

            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(mRxJavaImmediateScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(mRxJavaImmediateScheduler);

            base.evaluate();

            RxAndroidPlugins.reset();
            RxJavaPlugins.reset();
        }
    };
}
 
Example #11
Source File: RxJavaTestSchedulerRule.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> mTestScheduler);
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> mTestScheduler);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example #12
Source File: AbstractObjectBoxTest.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpRxSchedulers() {
    Scheduler immediate = new Scheduler() {
        @Override
        public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) {
            // this prevents StackOverflowErrors when scheduling with a delay
            return super.scheduleDirect(run, 0, unit);
        }

        @Override
        public Scheduler.Worker createWorker() {
            return new ExecutorScheduler.ExecutorWorker(Runnable::run, false);
        }
    };

    RxJavaPlugins.setInitIoSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitComputationSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitNewThreadSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitSingleSchedulerHandler(scheduler -> immediate);
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(scheduler -> immediate);
}
 
Example #13
Source File: RxJavaTestSchedulerRule.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> mTestScheduler);
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> mTestScheduler);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example #14
Source File: HomePresenterTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@BeforeClass public static void init() throws Exception {
  // Tell RxAndroid to not use android main ui thread scheduler
  RxAndroidPlugins.setInitMainThreadSchedulerHandler(
      new Function<Callable<Scheduler>, Scheduler>() {
        @Override public Scheduler apply(@NonNull Callable<Scheduler> schedulerCallable)
            throws Exception {
          return Schedulers.trampoline();
        }
      });
}
 
Example #15
Source File: NetworkAPITest.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    Scheduler immediate = new Scheduler() {
        @Override
        public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) {
            return super.scheduleDirect(run, 0, unit);
        }

        @Override
        public Worker createWorker() {
            return new ExecutorScheduler.ExecutorWorker(Runnable::run, false);
        }
    };

    RxJavaPlugins.setInitIoSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitComputationSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitNewThreadSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitSingleSchedulerHandler(scheduler -> immediate);
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(scheduler -> immediate);

    OkHttpClient httpClient = TLSCompactHelper.getOKHttpClient();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create();
    RxJava2CallAdapterFactory rxJava2CallAdapterFactory = RxJava2CallAdapterFactory.create();
    CompositeDisposable disposable = new CompositeDisposable();

    photoService = new PhotoService(
            httpClient,
            gsonConverterFactory,
            rxJava2CallAdapterFactory,
            disposable
    );
}
 
Example #16
Source File: RxJavaRule.java    From My-MVP with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());

            base.evaluate();
        }
    };
}
 
Example #17
Source File: RecyclerViewAdapterTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
            return Schedulers.trampoline();
        }
    });
}
 
Example #18
Source File: LoginPresenterTest.java    From flowless with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    loginPresenter = new LoginPresenter();
    // BoltsConfig.configureMocks();
    BundleFactoryConfig.setProvider(() -> Mockito.mock(Bundle.class));
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
}
 
Example #19
Source File: ViewPagerAdapterTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
        @Override
        public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
            return Schedulers.trampoline();
        }
    });
}
 
Example #20
Source File: AndroidSchedulersRule.java    From RIBs with Apache License 2.0 5 votes vote down vote up
@Override
protected void finished(Description description) {
  RxAndroidPlugins.reset();
  if (restoreHandlers) {
    // https://github.com/ReactiveX/RxAndroid/pull/358
    //
    // RxAndroidPlugins.setInitMainThreadSchedulerHandler(originalInitMainThreadInitHandler);
    //            RxAndroidPlugins.setMainThreadSchedulerHandler(originalMainThreadHandler);
  }
}
 
Example #21
Source File: WorkflowTest.java    From RIBs with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  RxAndroidPlugins.setInitMainThreadSchedulerHandler(
        new Function<Callable<Scheduler>, Scheduler>() {
            @Override
            public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception {
                return Schedulers.trampoline();
            }
        });
}
 
Example #22
Source File: NewsSourcePresenterTest.java    From InstantAppStarter with MIT License 5 votes vote down vote up
@BeforeClass
public static void onlyOnce() throws Exception {
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(
            new Function<Callable<Scheduler>, Scheduler>() {
                @Override
                public Scheduler apply(Callable<Scheduler> schedulerCallable)
                        throws Exception {
                    return Schedulers.trampoline();
                }
            });
}
 
Example #23
Source File: RxJavaRuler.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
            base.evaluate();
        }
    };
}
 
Example #24
Source File: RxJavaRule.java    From JReadHub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
            base.evaluate();
        }
    };
}
 
Example #25
Source File: ViewPagerAdapterTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() {
    RxAndroidPlugins.reset();
}
 
Example #26
Source File: RecyclerViewAdapterTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDown() {
    RxAndroidPlugins.reset();
}
 
Example #27
Source File: RepositoriesPresenterTest.java    From flowless with Apache License 2.0 4 votes vote down vote up
@Before
public void init() {
    repositoriesPresenter = new RepositoriesPresenter();
    // BoltsConfig.configureMocks();
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
}
 
Example #28
Source File: WorkflowTest.java    From RIBs with Apache License 2.0 4 votes vote down vote up
@After
public void cleanup() {
    RxAndroidPlugins.reset();
}
 
Example #29
Source File: HomePresenterTest.java    From mosby with Apache License 2.0 4 votes vote down vote up
@AfterClass public static void tearDown() throws Exception {
  RxAndroidPlugins.reset();
}
 
Example #30
Source File: RxJavaRules.java    From Varis-Android with Apache License 2.0 4 votes vote down vote up
private void resetSchedulers() {
    RxAndroidPlugins.reset();
    RxJavaPlugins.reset();
}