Search in sources :

Example 41 with Action

use of io.reactivex.functions.Action in project MVPArms by JessYanCoding.

the class GlideImageLoaderStrategy method clear.

@Override
public void clear(@Nullable final Context ctx, @Nullable ImageConfigImpl config) {
    Preconditions.checkNotNull(ctx, "Context is required");
    Preconditions.checkNotNull(config, "ImageConfigImpl is required");
    if (config.getImageView() != null) {
        GlideArms.get(ctx).getRequestManagerRetriever().get(ctx).clear(config.getImageView());
    }
    if (config.getImageViews() != null && config.getImageViews().length > 0) {
        // 取消在执行的任务并且释放资源
        for (ImageView imageView : config.getImageViews()) {
            GlideArms.get(ctx).getRequestManagerRetriever().get(ctx).clear(imageView);
        }
    }
    if (config.isClearDiskCache()) {
        // 清除本地缓存
        Completable.fromAction(new Action() {

            @Override
            public void run() throws Exception {
                Glide.get(ctx).clearDiskCache();
            }
        }).subscribeOn(Schedulers.io()).subscribe();
    }
    if (config.isClearMemory()) {
        // 清除内存缓存
        Completable.fromAction(new Action() {

            @Override
            public void run() throws Exception {
                Glide.get(ctx).clearMemory();
            }
        }).subscribeOn(AndroidSchedulers.mainThread()).subscribe();
    }
}
Also used : Action(io.reactivex.functions.Action) ImageView(android.widget.ImageView)

Example 42 with Action

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

the class AutodisposeController method onAttach.

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

        @Override
        public void run() {
            Log.i(TAG, "Disposing from onAttach()");
        }
    }).to(new ObservableScoper<Long>(scopeProvider)).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) ObservableScoper(com.uber.autodispose.ObservableScoper)

Example 43 with Action

use of io.reactivex.functions.Action in project NewPipe by TeamNewPipe.

the class ChannelFragment method updateSubscription.

private void updateSubscription(final ChannelInfo info) {
    if (DEBUG)
        Log.d(TAG, "updateSubscription() called with: info = [" + info + "]");
    final Action onComplete = new Action() {

        @Override
        public void run() throws Exception {
            if (DEBUG)
                Log.d(TAG, "Updated subscription: " + info.getUrl());
        }
    };
    final Consumer<Throwable> onError = new Consumer<Throwable>() {

        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            onUnrecoverableError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(info.getServiceId()), "Updating Subscription for " + info.getUrl(), R.string.subscription_update_failed);
        }
    };
    disposables.add(subscriptionService.updateChannelInfo(info).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(onComplete, onError));
}
Also used : UserAction(org.schabi.newpipe.report.UserAction) Action(io.reactivex.functions.Action) Consumer(io.reactivex.functions.Consumer) NonNull(android.support.annotation.NonNull)

Example 44 with Action

use of io.reactivex.functions.Action in project requery by requery.

the class ReactiveTest method testQueryEmpty.

@Test
public void testQueryEmpty() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    data.select(Person.class).get().observable().subscribe(new Consumer<Person>() {

        @Override
        public void accept(Person person) throws Exception {
            Assert.fail();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Assert.fail();
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            latch.countDown();
        }
    });
    if (!latch.await(1, TimeUnit.SECONDS)) {
        Assert.fail();
    }
}
Also used : Action(io.reactivex.functions.Action) CountDownLatch(java.util.concurrent.CountDownLatch) Person(io.requery.test.model.Person) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 45 with Action

use of io.reactivex.functions.Action in project Android-ReactiveLocation by mcharmas.

the class BaseObservableOnSubscribe method subscribe.

@Override
public void subscribe(ObservableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(emitter);
    try {
        apiClient.connect();
    } catch (Throwable ex) {
        if (!emitter.isDisposed()) {
            emitter.onError(ex);
        }
    }
    emitter.setDisposable(Disposables.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            onDisposed(apiClient);
            apiClient.disconnect();
        }
    }));
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Action(io.reactivex.functions.Action)

Aggregations

Action (io.reactivex.functions.Action)45 Test (org.junit.Test)19 Consumer (io.reactivex.functions.Consumer)9 TestException (io.reactivex.exceptions.TestException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Disposable (io.reactivex.disposables.Disposable)5 IOException (java.io.IOException)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 NonNull (io.reactivex.annotations.NonNull)3 TestScheduler (io.reactivex.schedulers.TestScheduler)3 Uri (android.net.Uri)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 ActionBarProvider (com.bluelinelabs.conductor.demo.ActionBarProvider)2 ObservableScoper (com.uber.autodispose.ObservableScoper)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1