Search in sources :

Example 6 with RxException

use of com.yydcdut.note.model.rx.exception.RxException in project PhotoNoter by yydcdut.

the class RxUser method saveEvernote.

public Observable<IUser> saveEvernote() {
    return Observable.create(new Observable.OnSubscribe<IUser>() {

        @Override
        public void call(Subscriber<? super IUser> subscriber) {
            if (mEvernoteSession.isLoggedIn()) {
                try {
                    User user = mEvernoteSession.getEvernoteClientFactory().getUserStoreClient().getUser();
                    mEvernoteUser = new EvernoteUser(user.getUsername());
                    SharedPreferences.Editor editor = mSharedPreferences.edit();
                    editor.putString(EVERNOTE_NAME, mEvernoteUser.getName());
                    editor.commit();
                    subscriber.onNext(mEvernoteUser);
                } catch (EDAMUserException e) {
                    YLog.e(e);
                    subscriber.onError(e);
                } catch (EDAMSystemException e) {
                    YLog.e(e);
                    subscriber.onError(e);
                } catch (TException e) {
                    YLog.e(e);
                    subscriber.onError(e);
                }
            } else {
                subscriber.onError(new RxException("没有登录"));
            }
            subscriber.onCompleted();
        }
    }).subscribeOn(Schedulers.io());
}
Also used : TException(com.evernote.thrift.TException) User(com.evernote.edam.type.User) EvernoteUser(com.yydcdut.note.entity.user.EvernoteUser) IUser(com.yydcdut.note.entity.user.IUser) QQUser(com.yydcdut.note.entity.user.QQUser) EDAMSystemException(com.evernote.edam.error.EDAMSystemException) Subscriber(rx.Subscriber) SharedPreferences(android.content.SharedPreferences) EvernoteUser(com.yydcdut.note.entity.user.EvernoteUser) IUser(com.yydcdut.note.entity.user.IUser) RxException(com.yydcdut.note.model.rx.exception.RxException) EDAMUserException(com.evernote.edam.error.EDAMUserException)

Aggregations

RxException (com.yydcdut.note.model.rx.exception.RxException)6 Subscriber (rx.Subscriber)6 Context (android.content.Context)3 IUser (com.yydcdut.note.entity.user.IUser)3 ContextLife (com.yydcdut.note.injector.ContextLife)3 Inject (javax.inject.Inject)3 Observable (rx.Observable)3 Schedulers (rx.schedulers.Schedulers)3 Category (com.yydcdut.note.entity.Category)2 EvernoteUser (com.yydcdut.note.entity.user.EvernoteUser)2 QQUser (com.yydcdut.note.entity.user.QQUser)2 CategoryDB (com.yydcdut.note.model.dao.CategoryDB)2 List (java.util.List)2 Singleton (javax.inject.Singleton)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Handler (android.os.Handler)1 Message (android.os.Message)1 EDAMSystemException (com.evernote.edam.error.EDAMSystemException)1