Search in sources :

Example 1 with EvernoteUser

use of com.yydcdut.note.entity.user.EvernoteUser in project PhotoNoter by yydcdut.

the class RxUser method getEvernote.

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

        @Override
        public void call(Subscriber<? super IUser> subscriber) {
            if (mEvernoteUser == null) {
                String name = mSharedPreferences.getString(EVERNOTE_NAME, NAME_DEFAULT);
                if (TextUtils.isEmpty(name)) {
                    subscriber.onError(new RxException("没有登录!!!"));
                } else {
                    mEvernoteUser = new EvernoteUser(name);
                }
            }
            subscriber.onNext(mEvernoteUser);
            subscriber.onCompleted();
        }
    }).subscribeOn(Schedulers.io());
}
Also used : Subscriber(rx.Subscriber) EvernoteUser(com.yydcdut.note.entity.user.EvernoteUser) IUser(com.yydcdut.note.entity.user.IUser) RxException(com.yydcdut.note.model.rx.exception.RxException)

Example 2 with EvernoteUser

use of com.yydcdut.note.entity.user.EvernoteUser 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

EvernoteUser (com.yydcdut.note.entity.user.EvernoteUser)2 IUser (com.yydcdut.note.entity.user.IUser)2 RxException (com.yydcdut.note.model.rx.exception.RxException)2 Subscriber (rx.Subscriber)2 SharedPreferences (android.content.SharedPreferences)1 EDAMSystemException (com.evernote.edam.error.EDAMSystemException)1 EDAMUserException (com.evernote.edam.error.EDAMUserException)1 User (com.evernote.edam.type.User)1 TException (com.evernote.thrift.TException)1 QQUser (com.yydcdut.note.entity.user.QQUser)1