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);
}
}
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();
}
}));
}
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);
}
}
}
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);
}
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();
}
}));
}
Aggregations