Search in sources :

Example 16 with Action

use of io.reactivex.functions.Action in project Conductor by bluelinelabs.

the class RxLifecycle2Controller method onAttach.

@Override
protected void onAttach(@NonNull View view) {
    super.onAttach(view);
    Log.i(TAG, "onAttach() called");
    (((ActionBarProvider) getActivity()).getSupportActionBar()).setTitle("RxLifecycle2 Demo");
    Observable.interval(1, TimeUnit.SECONDS).doOnDispose(new Action() {

        @Override
        public void run() {
            Log.i(TAG, "Disposing from onAttach()");
        }
    }).compose(this.<Long>bindUntilEvent(ControllerEvent.DETACH)).subscribe(new Consumer<Long>() {

        @Override
        public void accept(Long num) {
            Log.i(TAG, "Started in onAttach(), running until onDetach(): " + num);
        }
    });
}
Also used : Action(io.reactivex.functions.Action) ActionBarProvider(com.bluelinelabs.conductor.demo.ActionBarProvider)

Example 17 with Action

use of io.reactivex.functions.Action in project nhglib by VoidZombie.

the class SceneManager method unloadScene.

public void unloadScene(final Scene scene) {
    Observable.fromIterable(scene.sceneGraph.getEntities()).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer entity) throws Exception {
            return modelMapper.has(entity);
        }
    }).doFinally(new Action() {

        @Override
        public void run() throws Exception {
            int rootEntity = scene.sceneGraph.getRootEntity();
            NodeComponent nodeComponent = nodeMapper.get(rootEntity);
            nodeComponent.setTranslation(0, 0, 0);
            nodeComponent.setRotation(0, 0, 0);
            nodeComponent.setScale(1, 1, 1);
            nodeComponent.applyTransforms();
        }
    }).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            ModelComponent modelComponent = modelMapper.get(integer);
            assets.unloadAsset(modelComponent.asset);
        }
    });
}
Also used : Action(io.reactivex.functions.Action) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Example 18 with Action

use of io.reactivex.functions.Action in project simple-stack by Zhuinden.

the class MortarDemoActivity method handleStateChange.

@Override
public void handleStateChange(StateChange stateChange, Callback completionCallback) {
    BaseKey newScreen = stateChange.topNewState();
    String title = newScreen.title();
    ActionBarOwner.MenuAction menu = new ActionBarOwner.MenuAction("Friends", new Action() {

        @Override
        public void run() throws Exception {
            Navigator.getBackstack(MortarDemoActivity.this).goTo(FriendListScreen.create());
        }
    });
    actionBarOwner.setConfig(new ActionBarOwner.Config(false, !(newScreen instanceof ChatListScreen), title, menu));
    completionCallback.stateChangeComplete();
}
Also used : Action(io.reactivex.functions.Action) ChatListScreen(com.example.mortar.screen.ChatListScreen) BaseKey(com.example.mortar.util.BaseKey) ActionBarOwner(com.example.mortar.android.ActionBarOwner)

Example 19 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class CompletableTimeoutTest method timeoutContinueOther.

@Test
public void timeoutContinueOther() throws Exception {
    final int[] call = { 0 };
    Completable other = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            call[0]++;
        }
    });
    Completable.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
    assertEquals(1, call[0]);
}
Also used : Action(io.reactivex.functions.Action) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 20 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class CompletableFromActionTest method fromActionInvokesLazy.

@Test
public void fromActionInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            atomicInteger.incrementAndGet();
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Completable(io.reactivex.Completable) Action(io.reactivex.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Action (io.reactivex.functions.Action)28 Test (org.junit.Test)19 TestException (io.reactivex.exceptions.TestException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Consumer (io.reactivex.functions.Consumer)3 TestScheduler (io.reactivex.schedulers.TestScheduler)3 View (android.view.View)2 Disposable (io.reactivex.disposables.Disposable)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NonNull (android.support.annotation.NonNull)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 Toolbar (android.support.v7.widget.Toolbar)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ActionBarProvider (com.bluelinelabs.conductor.demo.ActionBarProvider)1 ActionBarOwner (com.example.mortar.android.ActionBarOwner)1 ChatListScreen (com.example.mortar.screen.ChatListScreen)1 BaseKey (com.example.mortar.util.BaseKey)1 LoginResult (com.facebook.login.LoginResult)1 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)1