当前位置: 首页>>代码示例>>Java>>正文


Java Single.create方法代码示例

本文整理汇总了Java中io.reactivex.Single.create方法的典型用法代码示例。如果您正苦于以下问题:Java Single.create方法的具体用法?Java Single.create怎么用?Java Single.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Single的用法示例。


在下文中一共展示了Single.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findPhotosByCriteriaRx

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<PhotoEntity>> findPhotosByCriteriaRx(@NonNull PhotoCriteria criteria) {
    return Single.create(e -> {
        String selection = getSelectionForCriteria(criteria);

        String orderBy = criteria.getOrderBy() == null ? PhotosColumns.PHOTO_ID + " DESC" : criteria.getOrderBy();

        Uri uri = MessengerContentProvider.getPhotosContentUriFor(criteria.getAccountId());
        Cursor cursor = getContext().getContentResolver().query(uri, null, selection, null, orderBy);

        ArrayList<PhotoEntity> photos = new ArrayList<>(safeCountOf(cursor));
        if (nonNull(cursor)) {
            while (cursor.moveToNext()) {
                if(e.isDisposed()){
                    break;
                }

                photos.add(mapPhotoDbo(cursor));
            }

            cursor.close();
        }

        e.onSuccess(photos);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:27,代码来源:PhotosStore.java

示例2: findDbosByCriteria

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<PostEntity>> findDbosByCriteria(@NonNull WallCriteria criteria) {
    return Single.create(emitter -> {
        final int accountId = criteria.getAccountId();

        Cursor cursor = buildCursor(criteria);
        Cancelable cancelable = emitter::isDisposed;
        List<PostEntity> dbos = new ArrayList<>(safeCountOf(cursor));

        if (nonNull(cursor)) {
            while (cursor.moveToNext()) {
                if (emitter.isDisposed()) {
                    break;
                }

                dbos.add(mapDbo(accountId, cursor, true, false, cancelable));
            }

            cursor.close();
        }

        emitter.onSuccess(dbos);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:25,代码来源:WallStore.java

示例3: getCountries

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<CountryEntity>> getCountries(int accountId) {
    return Single.create(emitter -> {
        Uri uri = MessengerContentProvider.getCountriesContentUriFor(accountId);

        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        List<CountryEntity> dbos = new ArrayList<>(safeCountOf(cursor));

        if(Objects.nonNull(cursor)){
            while (cursor.moveToNext()){
                if(emitter.isDisposed()){
                    break;
                }

                int id = cursor.getInt(cursor.getColumnIndex(CountriesColumns._ID));
                String title = cursor.getString(cursor.getColumnIndex(CountriesColumns.NAME));
                dbos.add(new CountryEntity(id, title));
            }

            cursor.close();
        }

        emitter.onSuccess(dbos);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:26,代码来源:DatabaseStore.java

示例4: uploadDocument

import io.reactivex.Single; //导入方法依赖的package包/类
public static Single<UploadDocDto> uploadDocument(@NonNull INetworker networker, @NonNull UploadServer server, @NonNull File file){
    return Single.create(emitter -> {
        InputStream is = new FileInputStream(file);

        try {
            Call<UploadDocDto> call = networker
                    .uploads()
                    .uploadDocument(server.getUrl(), file.getName(), is, percentage -> {});

            emitter.setCancellable(call::cancel);

            UploadDocDto dto = call.execute().body();

            emitter.onSuccess(dto);
        } finally {
            IOUtils.closeStreamQuietly(is);
        }
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:20,代码来源:UploadService.java

示例5: getCommunities

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<CommunityEntity>> getCommunities(int accountId, int ownerId) {
    return Single.create(emitter -> {
        Cursor cursor = getCursorForType(accountId, ownerId, RelationshipColumns.TYPE_MEMBER);

        List<CommunityEntity> dbos = new ArrayList<>(safeCountOf(cursor));
        if (Objects.nonNull(cursor)) {
            while (cursor.moveToNext()) {
                if (emitter.isDisposed()) {
                    break;
                }

                dbos.add(mapCommunity(cursor));
            }

            cursor.close();
        }

        emitter.onSuccess(dbos);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:RelativeshipStore.java

示例6: getMissingMessages

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<Integer>> getMissingMessages(int accountId, Collection<Integer> ids) {
    return Single.create(e -> {
        Set<Integer> copy = new HashSet<>(ids);

        Uri uri = MessengerContentProvider.getMessageContentUriFor(accountId);

        String[] projection = {MessageColumns._ID};
        String where = MessageColumns.FULL_ID + " IN(" + TextUtils.join(",", copy) + ")";
        Cursor cursor = getContentResolver().query(uri, projection, where, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                int id = cursor.getInt(cursor.getColumnIndex(MessageColumns._ID));
                copy.remove(id);
            }

            cursor.close();
        }

        e.onSuccess(new ArrayList<>(copy));
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:23,代码来源:MessagesStore.java

示例7: get

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<DocumentEntity>> get(@NonNull DocsCriteria criteria) {
    return Single.create(e -> {
        long start = System.currentTimeMillis();

        Uri uri = MessengerContentProvider.getDocsContentUriFor(criteria.getAccountId());

        String where;
        String[] args;

        Integer filter = criteria.getFilter();

        if (nonNull(filter) && filter != DocFilter.Type.ALL) {
            where = DocColumns.OWNER_ID + " = ? AND " + DocColumns.TYPE + " = ?";
            args = new String[]{String.valueOf(criteria.getOwnerId()), String.valueOf(filter)};
        } else {
            where = DocColumns.OWNER_ID + " = ?";
            args = new String[]{String.valueOf(criteria.getOwnerId())};
        }

        Cursor cursor = getContentResolver().query(uri, null, where, args, null);
        List<DocumentEntity> data = new ArrayList<>(safeCountOf(cursor));

        if(nonNull(cursor)){
            while (cursor.moveToNext()){
                if(e.isDisposed()) {
                    break;
                }

                data.add(map(cursor));
            }

            cursor.close();
        }

        e.onSuccess(data);

        Exestime.log("DocsStore.get", start, "count: " + data.size());
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:41,代码来源:DocsStore.java

示例8: getByCriteria

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<MessageEntity>> getByCriteria(@NonNull MessagesCriteria criteria, boolean withAtatchments, boolean withForwardMessages) {
    return Single.create(emitter -> {
        final long start = System.currentTimeMillis();

        Cancelable cancelable = emitter::isDisposed;

        Cursor cursor = queryMessagesByCriteria(criteria);

        ArrayList<MessageEntity> dbos = new ArrayList<>(safeCountOf(cursor));
        if (nonNull(cursor)) {
            while (cursor.moveToNext()) {
                if (emitter.isDisposed()) {
                    break;
                }

                MessageEntity dbo = fullMapDbo(criteria.getAccountId(), cursor, withAtatchments, withForwardMessages, cancelable);

                int position = dbos.size() - cursor.getPosition();
                dbos.add(position, dbo);
            }

            cursor.close();
        }

        Exestime.log("MessagesStore.getByCriteria", start, "count: " + dbos.size());
        emitter.onSuccess(dbos);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:30,代码来源:MessagesStore.java

示例9: saveDraftMessageBody

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Integer> saveDraftMessageBody(int accountId, int peerId, String body) {
    return Single.create(e -> {
        long start = System.currentTimeMillis();

        Uri uri = MessengerContentProvider.getMessageContentUriFor(accountId);

        ContentValues cv = new ContentValues();
        cv.put(MessageColumns.BODY, body);
        cv.put(MessageColumns.PEER_ID, peerId);
        cv.put(MessageColumns.STATUS, MessageStatus.EDITING);

        ContentResolver cr = getContentResolver();

        Integer existDraftMessageId = findDraftMessageId(accountId, peerId);
        //.blockingGet();

        if (existDraftMessageId != null) {
            cr.update(uri, cv, MessageColumns._ID + " = ?", new String[]{String.valueOf(existDraftMessageId)});
        } else {
            Uri resultUri = cr.insert(uri, cv);
            existDraftMessageId = Integer.parseInt(resultUri.getLastPathSegment());
        }

        e.onSuccess(existDraftMessageId);

        Exestime.log("saveDraftMessageBody", start);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:30,代码来源:MessagesStore.java

示例10: loadHubPreference

import io.reactivex.Single; //导入方法依赖的package包/类
@NonNull
@Override
public Single<HubPreference> loadHubPreference(@NonNull Hub hub) {
    return Single.create(emitter -> {
        final SQLiteDatabase db = mDBHelper.getReadableDatabase();
        final Cursor cursor = db.query(PreferenceDBHelper.TABLE_NAME, null, null, null, null, null, null);
        final int indexOfHubId = cursor.getColumnIndex("hub_id");
        final int indexOfIsVisible = cursor.getColumnIndex("is_visible");
        final int indexOfOrder = cursor.getColumnIndex("_order");

        final String id = hub.getId();
        HubPreference hubPreference = null;
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            if (cursor.getString(indexOfHubId).equalsIgnoreCase(id)) {
                hubPreference = new HubPreference(
                        hub,
                        cursor.getInt(indexOfIsVisible) == 1,
                        cursor.getInt(indexOfOrder)
                );
                break;
            }
        }

        if (hubPreference == null) {
            hubPreference = new HubPreference(
                    hub,
                    true,
                    cursor.getColumnCount()
            );
        }

        cursor.close();
        db.close();

        // Save to db
        updateHubPreferences(hubPreference);

        emitter.onSuccess(hubPreference);
    });
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:41,代码来源:PreferenceManager.java

示例11: getPhotos

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<LocalPhoto>> getPhotos(long albumId) {
    return Single.create(e -> {
        Cursor cursor = getContext().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                PROJECTION, MediaStore.Images.Media.BUCKET_ID + " = ?",
                new String[]{String.valueOf(albumId)},
                MediaStore.Images.ImageColumns.DATE_ADDED + " DESC");

        ArrayList<LocalPhoto> result = new ArrayList<>(safeCountOf(cursor));
        if (cursor != null) {
            while (cursor.moveToNext()) {
                if (e.isDisposed()) break;

                long imageId = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID));
                String data = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));

                result.add(new LocalPhoto()
                        .setImageId(imageId)
                        .setFullImageUri(Uri.parse(data)));
            }

            cursor.close();
        }

        e.onSuccess(result);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:28,代码来源:LocalMediaStore.java

示例12: getFile

import io.reactivex.Single; //导入方法依赖的package包/类
/**
 * @see StorageReference#getFile(Uri)
 */
public static Single<FileDownloadTask.TaskSnapshot> getFile(@NonNull StorageReference ref,
    @NonNull Uri uri) {
  return Single.create(new GetFileToUriOnSubscribe(ref, uri));
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:RxFirebaseStorage.java

示例13: putStream

import io.reactivex.Single; //导入方法依赖的package包/类
/**
 * @see StorageReference#putStream(InputStream)
 */
public static Single<UploadTask.TaskSnapshot> putStream(@NonNull StorageReference ref,
    @NonNull InputStream inputStream) {
  return Single.create(new PutStreamOnSubscribe(ref, inputStream));
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:8,代码来源:RxFirebaseStorage.java

示例14: data

import io.reactivex.Single; //导入方法依赖的package包/类
/**
 * @see DatabaseReference#addListenerForSingleValueEvent(ValueEventListener)
 */
@NonNull @CheckResult public static Single<DataSnapshot> data(@NonNull DatabaseReference ref) {
  return Single.create(new DataOnSubscribe(ref));
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:7,代码来源:RxFirebaseDatabase.java

示例15: checkAndHandleResolutionInternal

import io.reactivex.Single; //导入方法依赖的package包/类
private Single<Boolean> checkAndHandleResolutionInternal(LocationSettingsRequest locationSettingsRequest, Long timeoutTime, TimeUnit timeoutUnit) {
    return Single.create(new SettingsCheckHandleSingleOnSubscribe(rxLocation, locationSettingsRequest, timeoutTime, timeoutUnit));
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:4,代码来源:LocationSettings.java


注:本文中的io.reactivex.Single.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。