本文整理汇总了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);
});
}
示例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);
});
}
示例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);
});
}
示例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);
}
});
}
示例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);
});
}
示例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));
});
}
示例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());
});
}
示例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);
});
}
示例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);
});
}
示例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);
});
}
示例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);
});
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}