Java Code Examples for io.reactivex.Observable#fromCallable()

The following examples show how to use io.reactivex.Observable#fromCallable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdamantApiBuilder.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
public Observable<AdamantApi> build(int index) {
    return Observable.fromCallable(() -> {
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        addInterceptors(httpClient);

        if (currentServerNode != null){
            currentServerNode.setStatus(ServerNode.Status.CONNECTING);
        }

        currentServerNode = nodes.get(index);
        currentServerNode.setStatus(ServerNode.Status.CONNECTED);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(currentServerNode.getUrl() + BuildConfig.API_BASE)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(httpClient.build())
                .build();

        return  retrofit.create(AdamantApi.class);
    });
}
 
Example 2
Source File: QuestionRepository.java    From android-mvp-interactor-architecture with Apache License 2.0 5 votes vote down vote up
public Observable<Boolean> saveQuestion(final Question question) {
    return Observable.fromCallable(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            mDaoSession.getQuestionDao().insert(question);
            return true;
        }
    });
}
 
Example 3
Source File: DeleteOperation.java    From HighLite with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes one or more records from a table, non-blocking operation.
 *
 * @return a {@link Observable<Integer>} where the number of records deleted is passed
 * as the parameter to {@link io.reactivex.observers.DisposableObserver#onNext(Object)}
 */
@Override
public Observable<Integer> asObservable() {
    return Observable.fromCallable(new Callable<Integer>() {
        @Override
        public Integer call() {
            return executeBlocking();
        }
    });
}
 
Example 4
Source File: OptionRepository.java    From android-mvp-interactor-architecture with Apache License 2.0 5 votes vote down vote up
public Observable<Boolean> saveOptionList(final List<Option> optionList) {
    return Observable.fromCallable(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            mDaoSession.getOptionDao().insertInTx(optionList);
            return true;
        }
    });
}
 
Example 5
Source File: AppDbHelper.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<List<User>> getAllUsers() {
    return Observable.fromCallable(new Callable<List<User>>() {
        @Override
        public List<User> call() throws Exception {
            return mDaoSession.getUserDao().loadAll();
        }
    });
}
 
Example 6
Source File: DBManager.java    From XposedSmsCode with GNU General Public License v3.0 5 votes vote down vote up
public <T> Observable<T> insertOrReplaceRx(Class<T> entityClass, T entity) {
    return Observable.fromCallable(() -> {
        AbstractDao<T, ?> abstractDao = getAbstractDao(entityClass);
        abstractDao.insertOrReplace(entity);
        return entity;
    });
}
 
Example 7
Source File: RxJavaFragment.java    From AndroidQuick with MIT License 5 votes vote down vote up
private Observable<String> getObservable() {
    return Observable.fromCallable(new Callable<String>() {
        @Override
        public String call() throws Exception {
            try {
                Thread.sleep(1000); // 假设此处是耗时操作
            } catch (Exception e) {
                e.printStackTrace();
            }

            return "3";
        }
    });
}
 
Example 8
Source File: AppDbHelper.java    From android-mvvm-architecture with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Boolean> saveQuestionList(final List<Question> questionList) {
    return Observable.fromCallable(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            mAppDatabase.questionDao().insertAll(questionList);
            return true;
        }
    });
}
 
Example 9
Source File: DashboardRepositoryImpl.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Observable<Enrollment> getEnrollment(String programUid, String teiUid) {
    String progId = programUid == null ? "" : programUid;
    String teiId = teiUid == null ? "" : teiUid;
    return Observable.fromCallable(() -> d2.enrollmentModule().enrollments().byTrackedEntityInstance().eq(teiId)
            .byProgram().eq(progId).one().blockingGet());
}
 
Example 10
Source File: EoscDataManager.java    From EosCommander with MIT License 5 votes vote down vote up
public Observable<EosPrivateKey[]> createKey( int count ) {
    return Observable.fromCallable( () -> {
        EosPrivateKey[] retKeys = new EosPrivateKey[ count ];
        for ( int i = 0; i < count; i++) {
            retKeys[i] = new EosPrivateKey();
        }

        return retKeys;
    } );
}
 
Example 11
Source File: EditPostRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<EditPostForm> loadForm(int postId) {
    return Observable.fromCallable(() -> Api.EditPost().loadForm(postId));
}
 
Example 12
Source File: NewsRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<Boolean> likeComment(int articleId, int commentId) {
    return Observable.fromCallable(() -> Api.NewsApi().likeComment(articleId, commentId));
}
 
Example 13
Source File: TokenscriptFunction.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
private Observable<TokenScriptResult.Attribute> resultFromDatabase(TransactionResult transactionResult, Attribute attr)
{
    return Observable.fromCallable(() -> parseFunctionResult(transactionResult, attr));
}
 
Example 14
Source File: ForumRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<Object> markAllRead() {
    return Observable.fromCallable(() -> Api.Forum().markAllRead());
}
 
Example 15
Source File: QmsRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<ArrayList<QmsMessage>> sendMessage(int userId, int themeId, String text) {
    return Observable.fromCallable(() -> Api.Qms().sendMessage(userId, themeId, text));
}
 
Example 16
Source File: DevDbRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<Device> getDevice(String devId) {
    return Observable.fromCallable(() -> Api.DevDb().getDevice(devId));
}
 
Example 17
Source File: RxCallAdapter.java    From httplite with Apache License 2.0 4 votes vote down vote up
@Override
public Object adapt(HttpLite lite, RequestCreator creator, Type returnType, Object... args) throws Exception {
    return Observable.fromCallable(CallOnSubscribe.newInstance(lite,creator,returnType,args));
}
 
Example 18
Source File: ForumRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<Object> markRead(int id) {
    return Observable.fromCallable(() -> Api.Forum().markRead(id));
}
 
Example 19
Source File: QmsRx.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public Observable<QmsChatModel> getChat(final int userId, final int themeId) {
    return Observable.fromCallable(() -> transform(Api.Qms().getChat(userId, themeId), false));
}
 
Example 20
Source File: QueueProviderTracksMediaStore.java    From PainlessMusicPlayer with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Observable<List<Media>> fromTracksSearch(@Nullable final String query) {
    return Observable.fromCallable(() -> queueFromTracksSearch(query));
}