Search in sources :

Example 71 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project reark by reark.

the class AbstractViewModel method subscribeToDataStore.

public void subscribeToDataStore() {
    Log.v(TAG, "subscribeToDataStore");
    if (!isSubscribed()) {
        compositeDisposable = new CompositeDisposable();
        subscribeToDataStoreInternal(compositeDisposable);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 72 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project Android-ReactiveLocation by mcharmas.

the class PlacesResultActivity method onLocationPermissionGranted.

@Override
protected void onLocationPermissionGranted() {
    compositeSubscription = new CompositeDisposable();
    compositeSubscription.add(reactiveLocationProvider.getPlaceById(placeId).subscribe(new Consumer<PlaceBuffer>() {

        @Override
        public void accept(PlaceBuffer buffer) {
            Place place = buffer.get(0);
            if (place != null) {
                placeNameView.setText(place.getName());
                placeLocationView.setText(place.getLatLng().latitude + ", " + place.getLatLng().longitude);
                placeAddressView.setText(place.getAddress());
            }
            buffer.release();
        }
    }));
}
Also used : Consumer(io.reactivex.functions.Consumer) PlaceBuffer(com.google.android.gms.location.places.PlaceBuffer) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Place(com.google.android.gms.location.places.Place)

Example 73 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project TumCampusApp by TCA-Team.

the class SendMessageService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    TcaDb tcaDb = TcaDb.getInstance(this);
    final CompositeDisposable mDisposable = new CompositeDisposable();
    ChatMessageRemoteRepository remoteRepository = ChatMessageRemoteRepository.INSTANCE;
    remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(this));
    ChatMessageLocalRepository localRepository = ChatMessageLocalRepository.INSTANCE;
    localRepository.setDb(tcaDb);
    ChatMessageViewModel chatMessageViewModel = new ChatMessageViewModel(localRepository, remoteRepository, mDisposable);
    chatMessageViewModel.deleteOldEntries();
    // Get all unsent messages from database
    List<ChatMessage> unsentMsg = chatMessageViewModel.getUnsent();
    if (unsentMsg.isEmpty()) {
        return;
    }
    int numberOfAttempts = 0;
    AuthenticationManager am = new AuthenticationManager(this);
    // Try to send the message 5 times
    while (numberOfAttempts < MAX_SEND_TRIES) {
        try {
            for (ChatMessage message : unsentMsg) {
                // Generate signature and store it in the message
                message.setSignature(am.sign(message.getText()));
                // Send the message to the server
                chatMessageViewModel.sendMessage(message.getRoom(), message, this.getApplicationContext());
                Utils.logv("successfully sent message: " + message.getText());
            }
            // Exit the loop
            return;
        } catch (NoPrivateKey noPrivateKey) {
            // Nothing can be done, just exit
            return;
        } catch (Exception e) {
            Utils.log(e);
            numberOfAttempts++;
        }
        // Sleep for five seconds, maybe the server is currently really busy
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            Utils.log(e);
        }
    }
}
Also used : AuthenticationManager(de.tum.in.tumcampusapp.api.app.AuthenticationManager) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatMessageRemoteRepository(de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository) ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) ChatMessageViewModel(de.tum.in.tumcampusapp.component.ui.chat.ChatMessageViewModel) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ChatMessageLocalRepository(de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageLocalRepository)

Example 74 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.

the class PaginationAutoFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    Disposable d2 = _paginator.onBackpressureDrop().doOnNext(i -> {
        _requestUnderWay = true;
        _progressBar.setVisibility(View.VISIBLE);
    }).concatMap(this::_itemsFromNetworkCall).observeOn(AndroidSchedulers.mainThread()).map(items -> {
        _adapter.addItems(items);
        _adapter.notifyDataSetChanged();
        return items;
    }).doOnNext(i -> {
        _requestUnderWay = false;
        _progressBar.setVisibility(View.INVISIBLE);
    }).subscribe();
    // I'm using an RxBus purely to hear from a nested button click
    // we don't really need Rx for this part. it's just easy ¯\_(ツ)_/¯
    Disposable d1 = _bus.asFlowable().filter(o -> !_requestUnderWay).subscribe(event -> {
        if (event instanceof PaginationAutoAdapter.PageEvent) {
            // trigger the paginator for the next event
            int nextPage = _adapter.getItemCount();
            _paginator.onNext(nextPage);
        }
    });
    _disposables.add(d1);
    _disposables.add(d2);
    _paginator.onNext(0);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) ButterKnife(butterknife.ButterKnife) RxBus(com.morihacky.android.rxjava.rxbus.RxBus) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MainActivity(com.morihacky.android.rxjava.MainActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Flowable(io.reactivex.Flowable) View(android.view.View) Nullable(android.support.annotation.Nullable) PublishProcessor(io.reactivex.processors.PublishProcessor) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 75 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable in project RxJava-Android-Samples by kaushikgopal.

the class RxBusDemo_Bottom1Fragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    _disposables.add(_rxBus.asFlowable().subscribe(event -> {
        if (event instanceof RxBusDemoFragment.TapEvent) {
            _showTapText();
        }
    }));
}
Also used : Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) MainActivity(com.morihacky.android.rxjava.MainActivity) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Nullable(android.support.annotation.Nullable) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)78 Nullable (android.support.annotation.Nullable)15 Test (org.junit.Test)11 Bundle (android.os.Bundle)10 View (android.view.View)10 Consumer (io.reactivex.functions.Consumer)10 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 NonNull (android.support.annotation.NonNull)8 TextUtils (android.text.TextUtils)7 ViewGroup (android.view.ViewGroup)7 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)7 TextView (android.widget.TextView)6 BindView (butterknife.BindView)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Intent (android.content.Intent)5 LayoutInflater (android.view.LayoutInflater)5 Task (bolts.Task)5 TaskCompletionSource (bolts.TaskCompletionSource)5