Java 类io.reactivex.observers.DisposableCompletableObserver 实例源码

项目:JRAW-Android-Sample    文件:MainActivity.java   
private void doUserlessAuth() {
    Credentials credentials = ((MyApplication) getApplication()).getUserlessAppCredentials();
    disposables.add(RedditService.userlessAuthentication(
                AuthenticationManager.get().getRedditClient(), credentials)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    Toast.makeText(MainActivity.this, "Authentication complete!",
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(MainActivity.this, "Something went wrong",
                            Toast.LENGTH_SHORT).show();
                }
            })
    );
}
项目:JRAW-Android-Sample    文件:MainActivity.java   
private void refreshToken() {
    if (!AuthenticationManager.get().getRedditClient().hasActiveUserContext()) {
        Toast.makeText(MainActivity.this, "No need to refresh userless auth tokens",
                Toast.LENGTH_SHORT).show();
    } else {
        Credentials credentials = ((MyApplication) getApplicationContext())
                .getInstalledAppCredentials();
        disposables.add(RedditService.refreshToken(credentials)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        Toast.makeText(MainActivity.this, "Token refreshed",
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
项目:Profiler    文件:CreateAccountPresenter.java   
private void attemptAccountCreation(Credentials cred) {
    view.showProgressIndicator(true);
    disposableSubscriptions.add(
            auth.createAccount(cred)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableCompletableObserver() {
                                @Override
                                public void onComplete() {
                                    getUser();
                                }

                                @Override
                                public void onError(Throwable e) {
                                    view.showProgressIndicator(false);
                                    view.makeToast(e.toString());
                                }
                            })
    );

}
项目:Profiler    文件:CreateAccountPresenter.java   
private void addUserProfileToDatabase(String email, String uid) {
    final Profile profile = new Profile(
            "",
            "",
            uid,
            email,
            "",
            view.getName());
    disposableSubscriptions.add(database.createProfile(profile)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(e.getMessage());
                }
            })
    );
}
项目:Profiler    文件:ProfilePagePresenter.java   
@Override
public void onLogoutConfirmed(){
    disposableSubscriptions.add(
            auth.logUserOut()
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                            view.startLoginActivity();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.makeToast(e.getMessage());
                        }
                    })
    );
}
项目:Profiler    文件:LoginPresenter.java   
public void attemptLogIn(Credentials cred) {
    view.showProgressIndicator(true);
    compositeDisposable.add(
            authSource.attemptLogin(cred)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                            view.showProgressIndicator(false);
                            view.startProfileActivity();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.showProgressIndicator(false);
                            view.makeToast(e.toString());
                        }
                    })
    );
}
项目:Profiler    文件:ProfileDetailPresenter.java   
@Override
public void onDoneButtonClick() {
    currentProfile.setBio(view.getBio());
    currentProfile.setInterests(view.getInterests());

    subscriptions.add(
            database.updateProfile(currentProfile)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }

                @Override
                public void onError(Throwable e) {
                    view.makeToast(e.getMessage());
                }
            })
    );
}
项目:Profiler    文件:ProfileSettingsPresenter.java   
@Override
public void onDeleteAccountConfirmed(final String password) {
    view.showAuthCard(false);
    view.showProgressIndicator(true);
    disposableSubscriptions.add(
            auth.reauthenticateUser(password)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {

                            deleteProfileFromDatabase();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.showProgressIndicator(false);
                            view.makeToast(R.string.error_authenticating_credentails);
                        }
                    })
    );
}
项目:Profiler    文件:ProfileSettingsPresenter.java   
private void deleteUser() {
    disposableSubscriptions.add(
            auth.deleteUser()
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                            view.showProgressIndicator(false);
                            view.startLogInActivity();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.showProgressIndicator(false);
                            view.makeToast(e.getMessage());
                        }
                    })
    );
}
项目:Profiler    文件:ProfileSettingsPresenter.java   
private void deleteProfileFromDatabase() {
    disposableSubscriptions.add(
            database.deleteProfile(uid)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                            deleteUser();
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.showProgressIndicator(false);
                            view.makeToast(e.getMessage());
                        }
                    })
    );
}
项目:Profiler    文件:PhotoDetailPresenter.java   
@Override
public void onDoneButtonPress() {
    view.showProgressIndicator(true);
    currentProfile.setPhotoURL(view.getPhotoURL());

    subscriptions.add(database.updateProfile(currentProfile)
            .subscribeOn(schedulerProvider.io())
            .observeOn(schedulerProvider.ui())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    view.startProfilePageActivity();
                }

                @Override
                public void onError(Throwable e) {
                    view.showProgressIndicator(false);
                    view.makeToast(e.getMessage());
                }

            })

    );
}
项目:trust-wallet-android    文件:CompletableErrorProxyOperator.java   
@Override
public CompletableObserver apply(CompletableObserver observer) throws Exception {
    return new DisposableCompletableObserver() {
        @Override
        public void onComplete() {
            if (!isDisposed()) {
                observer.onError(throwable);
            }
        }

        @Override
        public void onError(Throwable ex) {
            if (!isDisposed()) {
                observer.onError(ex);
            }
        }
    };
}
项目:PosTrainer    文件:AlarmDetailPresenter.java   
/**
 * Ensure that the RealmAlarm is updated in repository
 */
@Override
public void onDoneIconPress() {
    Alarm alarm = view.getViewModel();
    alarm.setAlarmId(view.getAlarmId());

    compositeDisposable.add(
            updateOrCreateAlarm.runUseCase(alarm)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableCompletableObserver() {
                                @Override
                                public void onComplete() {
                                    view.makeToast(R.string.message_database_write_successful);
                                    view.startAlarmListActivity();
                                }

                                @Override
                                public void onError(Throwable e) {
                                    view.makeToast(R.string.error_database_write_failure);
                                }
                            })
    );
}
项目:PosTrainer    文件:AlarmListPresenter.java   
private void onAlarmSet(Alarm alarm) {
    compositeDisposable.add(
            setAlarm.runUseCase(alarm)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableCompletableObserver() {
                                @Override
                                public void onError(Throwable e) {
                                    view.makeToast(R.string.error_managing_alarm);
                                }

                                @Override
                                public void onComplete() {
                                    view.makeToast(R.string.msg_alarm_activated);
                                }
                            }
                    )
    );


}
项目:PosTrainer    文件:AlarmListPresenter.java   
private void onAlarmCancelled(Alarm alarm) {
    compositeDisposable.add(
            cancelAlarm.runUseCase(alarm)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableCompletableObserver() {
                                @Override
                                public void onError(Throwable e) {
                                    view.makeToast(R.string.error_managing_alarm);
                                }

                                @Override
                                public void onComplete() {
                                    view.makeToast(R.string.msg_alarm_deactivated);
                                }
                            }
                    )
    );
}
项目:PosTrainer    文件:AlarmListPresenter.java   
@Override
public void onAlarmSwiped(final int position, final Alarm alarm) {
    alarm.setActive(false);
    temporaryAlarm = alarm;
    temporaryAlarmPosition = position;

    compositeDisposable.add(
            deleteAlarm.runUseCase(alarm)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                            view.showUndoSnackbar();
                            onAlarmCancelled(alarm);
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.makeToast(R.string.error_database_connection_failure);
                            view.insertAlarmAt(position, alarm);
                        }
                    })
    );
}
项目:PosTrainer    文件:AlarmReceiverPresenter.java   
/**
 * Checks whether the Alarm should be written as INACTIVE or left alone, based on
 * alarm.isRenewAutomatically
 *
 * @param alarm
 */
private void checkAlarmState(final Alarm alarm) {
    if (alarm.isRenewAutomatically()) {
        startAlarm(alarm);
    } else {
        alarm.setActive(false);

        compositeDisposable.add(
                updateOrCreateAlarm.runUseCase(alarm)
                        .subscribeOn(schedulerProvider.io())
                        .observeOn(schedulerProvider.ui())
                        .subscribeWith(
                                new DisposableCompletableObserver() {
                                    @Override
                                    public void onComplete() {
                                        startAlarm(alarm);
                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        view.makeToast(R.string.error_database_write_failure);
                                    }
                                })
        );
    }
}
项目:PosTrainer    文件:AlarmReceiverPresenter.java   
private void startAlarm(Alarm alarm) {
    compositeDisposable.add(
            startAlarm.runUseCase(alarm)
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(new DisposableCompletableObserver() {
                        @Override
                        public void onComplete() {
                        }

                        @Override
                        public void onError(Throwable e) {
                            view.makeToast(R.string.error_starting_alarm);
                        }
                    })
    );


}
项目:PosTrainer    文件:AlarmReceiverPresenter.java   
@Override
public void onAlarmDismissClick() {
    //first, stop the media player and vibrator
    compositeDisposable.add(
            dismissAlarm.runUseCase()
                    .subscribeOn(schedulerProvider.io())
                    .observeOn(schedulerProvider.ui())
                    .subscribeWith(
                            new DisposableCompletableObserver() {
                                @Override
                                public void onComplete() {
                                    view.finishActivity();
                                }

                                @Override
                                public void onError(Throwable e) {
                                }
                            })
    );
}
项目:ring-client-android    文件:SmartListPresenter.java   
public void deleteConversation(final CallContact callContact) {
    final String accountId = mAccountService.getCurrentAccount().getAccountID();

    mCompositeDisposable.add(mHistoryService.clearHistoryForContactAndAccount(callContact.getIds().get(0), accountId)
            .subscribeOn(Schedulers.computation())
            .observeOn(mMainScheduler)
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    loadConversations();
                }

                @Override
                public void onError(@NonNull Throwable e) {
                    Log.e(TAG, e.toString());
                }
            }));
}
项目:JRAW-Android-Sample    文件:MainActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        Credentials credentials = ((MyApplication) getApplication())
                .getInstalledAppCredentials();

        disposables.add(RedditService.userAuthentication(
                    AuthenticationManager.get().getRedditClient(),
                    credentials,
                    data.getStringExtra("RESULT_URL"))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        String username = AuthenticationManager.get().getRedditClient()
                                .getAuthenticatedUser();
                        Toast.makeText(MainActivity.this, "Logged in as " + username,
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
项目:JRAW-Android-Sample    文件:MainActivity.java   
private void logout() {
    if (!AuthenticationManager.get().getRedditClient().hasActiveUserContext()) {
        Toast.makeText(MainActivity.this, "No need to logout of userless auth",
                Toast.LENGTH_SHORT).show();
    } else {
        Credentials credentials = ((MyApplication) getApplicationContext())
                .getInstalledAppCredentials();

        disposables.add(RedditService.logout(credentials)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        Toast.makeText(MainActivity.this, "Deauthenticated!",
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
项目:rxlint    文件:SubscriberTest.java   
public void rx2CompletableWithSubscriber() {
    io.reactivex.Completable.complete().subscribeWith(new DisposableCompletableObserver() {
        @Override
        public void onComplete() {

        }

        @Override
        public void onError(Throwable e) {

        }
    });
}
项目:PosTrainer    文件:AlarmListPresenter.java   
/**
 * Compares a desired alarm to the state of the current alarm.
 * - If states matches, we shouldn't need to update the Repository (I think so anyway).
 * - If state doesn't match, animate the toggle in the view, and update the Repository to
 * desired state
 *
 * @param active user's desired state of the alarm (probably)
 * @param alarm  current state of alarm in View. Assumed to be current with Repository
 */
@Override
public void onAlarmToggled(final boolean active, final Alarm alarm) {
    if (active != alarm.isActive()) {
        alarm.setActive(active);

        compositeDisposable.add(
                updateOrCreateAlarm.runUseCase(alarm)
                        .subscribeOn(schedulerProvider.io())
                        .observeOn(schedulerProvider.ui())
                        .subscribeWith(
                                new DisposableCompletableObserver() {
                                    @Override
                                    public void onError(Throwable e) {
                                        view.makeToast(R.string.error_database_write_failure);
                                    }

                                    @Override
                                    public void onComplete() {

                                        if (active) {
                                            onAlarmSet(alarm);
                                        } else {
                                            onAlarmCancelled(alarm);
                                        }
                                    }
                                }
                        )
        );

    } else {
        view.makeToast(getAppropriateMessage(active));
    }
}
项目:PosTrainer    文件:AlarmListPresenter.java   
@Override
public void onCreateAlarmButtonClick(int currentNumberOfAlarms,
                                     Alarm alarm) {

    //only allow up to 5 Reminders at a time
    if (currentNumberOfAlarms < 5) {
        compositeDisposable.add(
                updateOrCreateAlarm.runUseCase(alarm)
                        .subscribeOn(schedulerProvider.io())
                        .observeOn(schedulerProvider.ui())
                        .subscribeWith(
                                new DisposableCompletableObserver() {
                                    @Override
                                    public void onComplete() {
                                        getReminders();
                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        view.makeToast(R.string.error_database_write_failure);
                                    }
                                })
        );

    } else {
        view.makeToast(R.string.msg_alarm_limit_reached);
    }
}
项目:PosTrainer    文件:AlarmListPresenter.java   
/**
 * Add the Alarm back in to the Database and View on Undo
 */
@Override
public void onUndoConfirmed() {
    //TODO Realm Implementation:
    /*
    My Realm Impl. isn't yet set up to insert the Alarm back into a specific position within the
    database itself. This apparently requires adding a Field for position to the Models.
     */
    if (temporaryAlarm != null) {
        //ensure View/Data consistency
        compositeDisposable.add(
                updateOrCreateAlarm.runUseCase(temporaryAlarm)
                        .subscribeOn(schedulerProvider.io())
                        .observeOn(schedulerProvider.ui())
                        .subscribeWith(
                                new DisposableCompletableObserver() {
                                    @Override
                                    public void onError(Throwable e) {
                                        view.makeToast(R.string.error_database_write_failure);
                                    }

                                    @Override
                                    public void onComplete() {

                                        view.insertAlarmAt(temporaryAlarmPosition, temporaryAlarm);
                                        temporaryAlarm = null;
                                        temporaryAlarmPosition = 0;
                                    }
                                }
                        )
        );




    } else {
        view.makeToast(R.string.error_unable_to_retrieve_alarm);
    }

}
项目:Fast-Android-Networking    文件:SubscriptionActivity.java   
private DisposableCompletableObserver getDisposableObserver() {

        return new DisposableCompletableObserver() {
            @Override
            public void onComplete() {
                Log.d(TAG, "onCompleted");
            }

            @Override
            public void onError(@NonNull Throwable throwable) {
                Log.d(TAG, "onError " + throwable.getMessage());
            }
        };

    }