Search in sources :

Example 81 with Disposable

use of io.reactivex.disposables.Disposable in project simple-stack by Zhuinden.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    defaultStateChanger = DefaultStateChanger.create(this, root);
    Backstack backstack = Navigator.configure().setStateChanger(new NoOpStateChanger()).setDeferredInitialization(true).install(this, root, HistoryBuilder.single(FirstKey.create()));
    disposable = RxStackObservable.create(backstack).subscribe(stateChange -> {
        if (stateChange.topNewState().equals(stateChange.topPreviousState())) {
            return;
        }
        defaultStateChanger.performViewChange(stateChange.topPreviousState(), stateChange.topNewState(), stateChange, () -> {
        });
    });
    Navigator.executeDeferredInitialization(this);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Bundle(android.os.Bundle) DefaultStateChanger(com.zhuinden.simplestack.navigator.DefaultStateChanger) Backstack(com.zhuinden.simplestack.Backstack) ButterKnife(butterknife.ButterKnife) Navigator(com.zhuinden.simplestack.navigator.Navigator) FrameLayout(android.widget.FrameLayout) HistoryBuilder(com.zhuinden.simplestack.HistoryBuilder) AppCompatActivity(android.support.v7.app.AppCompatActivity) BindView(butterknife.BindView) Backstack(com.zhuinden.simplestack.Backstack)

Example 82 with Disposable

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

the class LoginPresenter method loadSessionState.

private void loadSessionState() {
    final Disposable subscription = sessionInteractor.getSessionState().distinctUntilChanged().subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(state -> {
        switch(state) {
            case UNAVAILABLE:
                isLogging = true;
                view.showLogin(hostname);
                break;
            case INVALID:
                isLogging = false;
                view.showRetryLogin(hostname);
                break;
            case VALID:
                isLogging = false;
                view.closeView();
        }
    }, Logger::report);
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Logger(chat.rocket.android.helper.Logger)

Example 83 with Disposable

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

the class MainPresenter method onRetryLogin.

@Override
public void onRetryLogin() {
    final Disposable subscription = sessionInteractor.retryLogin().subscribe();
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable)

Example 84 with Disposable

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

the class MessageOptionsDialogFragment method setUpDialog.

private void setUpDialog(final BottomSheetDialog bottomSheetDialog, String messageId) {
    RocketChatCache cache = new RocketChatCache(bottomSheetDialog.getContext());
    String hostname = cache.getSelectedServerHostname();
    EditMessageInteractor editMessageInteractor = getEditMessageInteractor(hostname);
    MessageRepository messageRepository = new RealmMessageRepository(hostname);
    Disposable disposable = messageRepository.getById(messageId).flatMap(it -> {
        if (!it.isPresent()) {
            return Single.just(Pair.<Message, Boolean>create(null, false));
        }
        Message message = it.get();
        return Single.zip(Single.just(message), editMessageInteractor.isAllowed(message), Pair::create);
    }).subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(pair -> {
        if (pair.second) {
            bottomSheetDialog.findViewById(R.id.message_options_info).setVisibility(View.GONE);
            View editView = bottomSheetDialog.findViewById(R.id.message_options_edit_action);
            editView.setVisibility(View.VISIBLE);
            editView.setOnClickListener(view -> internalListener.onEdit(pair.first));
        } else {
            ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_permissions_info);
        }
    }, throwable -> {
        ((TextView) bottomSheetDialog.findViewById(R.id.message_options_info)).setText(R.string.message_options_no_message_info);
        Logger.report(throwable);
    });
    compositeDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) MessageRepository(chat.rocket.core.repositories.MessageRepository) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) RealmPublicSettingRepository(chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository) Bundle(android.os.Bundle) UserRepository(chat.rocket.core.repositories.UserRepository) RocketChatCache(chat.rocket.android.RocketChatCache) RoomRepository(chat.rocket.core.repositories.RoomRepository) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RealmRoomRoleRepository(chat.rocket.persistence.realm.repositories.RealmRoomRoleRepository) PermissionRepository(chat.rocket.core.repositories.PermissionRepository) PublicSettingRepository(chat.rocket.core.repositories.PublicSettingRepository) PermissionInteractor(chat.rocket.core.interactors.PermissionInteractor) View(android.view.View) RoomRoleRepository(chat.rocket.core.repositories.RoomRoleRepository) R(chat.rocket.android.R) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) BottomSheetDialogFragment(android.support.design.widget.BottomSheetDialogFragment) DialogInterface(android.content.DialogInterface) Logger(chat.rocket.android.helper.Logger) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) Message(chat.rocket.core.models.Message) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Pair(android.support.v4.util.Pair) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository) BackgroundLooper(chat.rocket.android.BackgroundLooper) RealmPermissionRepository(chat.rocket.persistence.realm.repositories.RealmPermissionRepository) Message(chat.rocket.core.models.Message) EditMessageInteractor(chat.rocket.core.interactors.EditMessageInteractor) RocketChatCache(chat.rocket.android.RocketChatCache) MessageRepository(chat.rocket.core.repositories.MessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) RealmMessageRepository(chat.rocket.persistence.realm.repositories.RealmMessageRepository) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Example 85 with Disposable

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

the class InputHostnamePresenter method connectToEnforced.

public void connectToEnforced(final String hostname) {
    final ServerPolicyApi serverPolicyApi = new DefaultServerPolicyApi(OkHttpHelper.getClientForUploadFile(), hostname);
    final ServerPolicyApiValidationHelper validationHelper = new ServerPolicyApiValidationHelper(serverPolicyApi);
    clearSubscriptions();
    final Disposable subscription = ServerPolicyHelper.isApiVersionValid(validationHelper).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnTerminate(() -> view.hideLoader()).subscribe(serverValidation -> {
        if (serverValidation.isValid()) {
            onServerValid(hostname, serverValidation.usesSecureConnection());
        } else {
            view.showInvalidServerError();
        }
    }, throwable -> view.showConnectionError());
    addSubscription(subscription);
}
Also used : Disposable(io.reactivex.disposables.Disposable) DefaultServerPolicyApi(chat.rocket.android.api.rest.DefaultServerPolicyApi) ServerPolicyApi(chat.rocket.android.api.rest.ServerPolicyApi) DefaultServerPolicyApi(chat.rocket.android.api.rest.DefaultServerPolicyApi) ServerPolicyApiValidationHelper(chat.rocket.android.helper.ServerPolicyApiValidationHelper)

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