Search in sources :

Example 86 with Disposable

use of io.reactivex.disposables.Disposable in project Rocket.Chat.Android by RocketChat.

the class RoomFragment method setupMessageComposer.

private void setupMessageComposer() {
    final MessageFormLayout messageFormLayout = (MessageFormLayout) rootView.findViewById(R.id.message_composer);
    messageFormManager = new MessageFormManager(messageFormLayout, this::showExtraActionSelectionDialog);
    messageFormManager.setSendMessageCallback(this::sendMessage);
    messageFormLayout.setEditTextCommitContentListener(this::onCommitContent);
    autocompleteManager = new AutocompleteManager((ViewGroup) rootView.findViewById(R.id.message_list_root));
    autocompleteManager.registerSource(new ChannelSource(new AutocompleteChannelInteractor(roomRepository, new RealmSpotlightRoomRepository(hostname), new DeafultTempSpotlightRoomCaller(methodCallHelper)), AndroidSchedulers.from(BackgroundLooper.get()), AndroidSchedulers.mainThread()));
    Disposable disposable = Single.zip(absoluteUrlHelper.getRocketChatAbsoluteUrl(), roomRepository.getById(roomId).first(Optional.absent()), Pair::create).subscribe(pair -> {
        if (pair.first.isPresent() && pair.second.isPresent()) {
            autocompleteManager.registerSource(new UserSource(new AutocompleteUserInteractor(pair.second.get(), userRepository, new RealmMessageRepository(hostname), new RealmSpotlightUserRepository(hostname), new DefaultTempSpotlightUserCaller(methodCallHelper)), pair.first.get(), RocketChatUserStatusProvider.getInstance(), AndroidSchedulers.from(BackgroundLooper.get()), AndroidSchedulers.mainThread()));
        }
    }, throwable -> {
    });
    compositeDisposable.add(disposable);
    autocompleteManager.bindTo(messageFormLayout.getEditText(), messageFormLayout);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RealmSpotlightRoomRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository) AutocompleteChannelInteractor(chat.rocket.core.interactors.AutocompleteChannelInteractor) ViewGroup(android.view.ViewGroup) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) MessageFormLayout(chat.rocket.android.widget.message.MessageFormLayout) AutocompleteUserInteractor(chat.rocket.core.interactors.AutocompleteUserInteractor) RealmSpotlightUserRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository) DefaultTempSpotlightUserCaller(chat.rocket.android.service.temp.DefaultTempSpotlightUserCaller) MessageFormManager(chat.rocket.android.layouthelper.chatroom.MessageFormManager) UserSource(chat.rocket.android.widget.message.autocomplete.user.UserSource) DeafultTempSpotlightRoomCaller(chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller) AutocompleteManager(chat.rocket.android.widget.message.autocomplete.AutocompleteManager) ChannelSource(chat.rocket.android.widget.message.autocomplete.channel.ChannelSource)

Example 87 with Disposable

use of io.reactivex.disposables.Disposable in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method onUnreadCount.

@Override
public void onUnreadCount() {
    final Disposable subscription = getRoomUserPair().flatMap(roomUserPair -> messageInteractor.unreadCountFor(roomUserPair.first, roomUserPair.second)).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(count -> view.showUnreadCount(count), Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) User(chat.rocket.core.models.User) Settings(chat.rocket.core.models.Settings) Optional(com.fernandocejas.arrow.optional.Optional) UserRepository(chat.rocket.core.repositories.UserRepository) RoomRepository(chat.rocket.core.repositories.RoomRepository) Logger(chat.rocket.android.helper.Logger) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) LogIfError(chat.rocket.android.helper.LogIfError) MessageInteractor(chat.rocket.core.interactors.MessageInteractor) Message(chat.rocket.core.models.Message) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) Disposable(io.reactivex.disposables.Disposable) ConnectivityManagerApi(chat.rocket.android.service.ConnectivityManagerApi) Pair(android.support.v4.util.Pair) Room(chat.rocket.core.models.Room) SyncState(chat.rocket.core.SyncState) Nullable(android.support.annotation.Nullable) BackgroundLooper(chat.rocket.android.BackgroundLooper) BasePresenter(chat.rocket.android.shared.BasePresenter) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) Logger(chat.rocket.android.helper.Logger)

Example 88 with Disposable

use of io.reactivex.disposables.Disposable in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getMessages.

private void getMessages() {
    final Disposable subscription = roomRepository.getById(roomId).filter(Optional::isPresent).map(Optional::get).flatMap(messageInteractor::getAllFrom).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(messages -> view.showMessages(messages), Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger)

Example 89 with Disposable

use of io.reactivex.disposables.Disposable in project Rocket.Chat.Android by RocketChat.

the class RoomPresenter method getUserPreferences.

private void getUserPreferences() {
    final Disposable subscription = userRepository.getCurrent().filter(Optional::isPresent).map(Optional::get).filter(user -> user.getSettings() != null).map(User::getSettings).filter(settings -> settings.getPreferences() != null).map(Settings::getPreferences).distinctUntilChanged().subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(preferences -> {
        if (preferences.isAutoImageLoad()) {
            view.autoloadImages();
        } else {
            view.manualLoadImages();
        }
    }, Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) User(chat.rocket.core.models.User) Settings(chat.rocket.core.models.Settings) Optional(com.fernandocejas.arrow.optional.Optional) UserRepository(chat.rocket.core.repositories.UserRepository) RoomRepository(chat.rocket.core.repositories.RoomRepository) Logger(chat.rocket.android.helper.Logger) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) LogIfError(chat.rocket.android.helper.LogIfError) MessageInteractor(chat.rocket.core.interactors.MessageInteractor) Message(chat.rocket.core.models.Message) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) Disposable(io.reactivex.disposables.Disposable) ConnectivityManagerApi(chat.rocket.android.service.ConnectivityManagerApi) Pair(android.support.v4.util.Pair) Room(chat.rocket.core.models.Room) SyncState(chat.rocket.core.SyncState) Nullable(android.support.annotation.Nullable) BackgroundLooper(chat.rocket.android.BackgroundLooper) BasePresenter(chat.rocket.android.shared.BasePresenter) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) User(chat.rocket.core.models.User) Optional(com.fernandocejas.arrow.optional.Optional) Logger(chat.rocket.android.helper.Logger) Settings(chat.rocket.core.models.Settings)

Example 90 with Disposable

use of io.reactivex.disposables.Disposable in project RxRelay by JakeWharton.

the class ReplayRelayTest method testSubscriptionLeak.

@Test
public void testSubscriptionLeak() {
    ReplayRelay<Object> subject = ReplayRelay.create();
    Disposable s = subject.subscribe();
    assertEquals(1, subject.observerCount());
    s.dispose();
    assertEquals(0, subject.observerCount());
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)224 Test (org.junit.Test)95 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)31 Logger (chat.rocket.android.helper.Logger)19 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 Worker (io.reactivex.Scheduler.Worker)15 List (java.util.List)14 Single (io.reactivex.Single)13 Function (io.reactivex.functions.Function)13 NonNull (io.reactivex.annotations.NonNull)12 Nullable (android.support.annotation.Nullable)11 Bundle (android.os.Bundle)10 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Schedulers (io.reactivex.schedulers.Schedulers)9 TimeUnit (java.util.concurrent.TimeUnit)8 NonNull (android.support.annotation.NonNull)7