Java Code Examples for io.reactivex.ObservableEmitter#onComplete()

The following examples show how to use io.reactivex.ObservableEmitter#onComplete() . 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: AesEncryptionObservable.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintEncryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] encryptedBytes = cipher.doFinal(ConversionUtils.toBytes(toEncrypt));
		byte[] ivBytes = cipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();

		String encryptedString = CryptoData.fromBytes(encodingProvider, encryptedBytes, ivBytes).toString();
		CryptoData.verifyCryptoDataString(encryptedString);

		emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.AUTHENTICATED, null, encryptedString));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}
}
 
Example 2
Source File: SubscriptionProxy.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
DisposableObserver<? super T> disposableWrapper(final ObservableEmitter<? super T> emitter) {
  return new DisposableObserver<T>() {
    @Override public void onNext(@NonNull T t) {
      if (!emitter.isDisposed()) {
        emitter.onNext(t);
      }
    }

    @Override public void onError(@NonNull Throwable e) {
      if (!emitter.isDisposed()) {
        emitter.onError(e);
      }
    }

    @Override public void onComplete() {
      if (!emitter.isDisposed()) {
        emitter.onComplete();
      }
    }
  };
}
 
Example 3
Source File: RsaEncryptionObservable.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(ObservableEmitter<FingerprintEncryptionResult> emitter) throws Exception {
	if (fingerprintApiWrapper.isUnavailable()) {
		emitter.onError(new FingerprintUnavailableException("Fingerprint authentication is not available on this device! Ensure that the device has a Fingerprint sensor and enrolled Fingerprints by calling RxFingerprint#isAvailable(Context) first"));
		return;
	}

	try {
		Cipher cipher = cipherProvider.getCipherForEncryption();
		byte[] encryptedBytes = cipher.doFinal(ConversionUtils.toBytes(toEncrypt));

		String encryptedString = encodingProvider.encode(encryptedBytes);
		emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.AUTHENTICATED, null, encryptedString));
		emitter.onComplete();
	} catch (Exception e) {
		Logger.error(String.format("Error writing value for key: %s", cipherProvider.keyName), e);
		emitter.onError(e);
	}
}
 
Example 4
Source File: Fetcher.java    From fetch with Apache License 2.0 6 votes vote down vote up
<ResultT> void subscribe(Converter<ResultT> converter, ObservableEmitter<? super ResultT> emitter) {
    try {
        if (isEmpty(cursor)) {
            return;
        }

        while (this.cursor.moveToNext()) {
            ResultT event = converter.convert(this.cursor);
            if (event != null) {
                emitter.onNext(event);
            }
        }
    } finally {
        close();
        emitter.onComplete();
    }
}
 
Example 5
Source File: DisposableUtil.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
public static <T> DisposableObserver<T> disposableObserverFromEmitter(final ObservableEmitter<T> emitter) {
    return new DisposableObserver<T>() {

        @Override
        public void onNext(T t) {
            emitter.onNext(t);
        }

        @Override
        public void onError(Throwable e) {
            emitter.tryOnError(e);
        }

        @Override
        public void onComplete() {
            emitter.onComplete();
        }
    };
}
 
Example 6
Source File: RxCache.java    From RxEasyHttp with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(@NonNull ObservableEmitter<T> subscriber) throws Exception {
    try {
        T data = execute();
        if (!subscriber.isDisposed()) {
            subscriber.onNext(data);
        }
    } catch (Throwable e) {
        HttpLog.e(e.getMessage());
        if (!subscriber.isDisposed()) {
            subscriber.onError(e);
        }
        Exceptions.throwIfFatal(e);
        //RxJavaPlugins.onError(e);
        return;
    }

    if (!subscriber.isDisposed()) {
        subscriber.onComplete();
    }
}
 
Example 7
Source File: NewArticleActivity.java    From YCCustomText with Apache License 2.0 5 votes vote down vote up
/**
 * 显示数据
 */
private void showEditData(ObservableEmitter<String> emitter, String html) {
    try {
        List<String> textList = HyperLibUtils.cutStringByImgTag(html);
        for (int i = 0; i < textList.size(); i++) {
            String text = textList.get(i);
            emitter.onNext(text);
        }
        emitter.onComplete();
    } catch (Exception e){
        e.printStackTrace();
        emitter.onError(e);
    }
}
 
Example 8
Source File: RsaDecryptionObservable.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] bytes = cipher.doFinal(encodingProvider.decode(encryptedString));

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, ConversionUtils.toChars(bytes)));
		emitter.onComplete();
	} catch (Exception e) {
		Logger.error("Unable to decrypt given value. RxFingerprint is only able to decrypt values previously encrypted by RxFingerprint with the same encryption mode.", e);
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 9
Source File: AesDecryptionObservable.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		CryptoData cryptoData = CryptoData.fromString(encodingProvider, encryptedString);
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] bytes = cipher.doFinal(cryptoData.getMessage());

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, ConversionUtils.toChars(bytes)));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 10
Source File: DisposableUtil.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
public static <T> DisposableSingleObserver<T> disposableSingleObserverFromEmitter(final ObservableEmitter<T> emitter) {
    return new DisposableSingleObserver<T>() {

        @Override
        public void onSuccess(T t) {
            emitter.onNext(t);
            emitter.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            emitter.tryOnError(e);
        }
    };
}
 
Example 11
Source File: RimetLocalSource.java    From xposed-rimet with Apache License 2.0 5 votes vote down vote up
private <T> void subscribe(ObservableEmitter<T> emitter, OnHandler<T> handler) {

        try {
            // 开始处理
            T value = handler.onHandler();

            if (value != null) {
                // 返回结果
                emitter.onNext(value);
            }
            emitter.onComplete();
        } catch (Throwable tr) {
            emitter.onError(tr);
        }
    }
 
Example 12
Source File: ListDirObservable.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
private static void emitFile(FSRecord f, ObservableEmitter<CachedPathInfo> observableEmitter) throws IOException
{
    CachedPathInfo cpi = new CachedPathInfoBase();
    cpi.init(f.getPath());
    observableEmitter.onNext(cpi);
    observableEmitter.onComplete();
}
 
Example 13
Source File: DefaultContentDelegate.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void doOnChapterListFinish(List<ChapterBean> chapterList, ObservableEmitter<List<ChapterBean>> emitter) {
    if (!getBookSource().chapterListReverse()) {
        Collections.reverse(chapterList);
    }
    LinkedHashSet<ChapterBean> lh = new LinkedHashSet<>(chapterList);
    chapterList = new ArrayList<>(lh);
    Collections.reverse(chapterList);
    emitter.onNext(chapterList);
    emitter.onComplete();
}
 
Example 14
Source File: RxJavaFragment.java    From AndroidQuick with MIT License 5 votes vote down vote up
@Override
public void subscribe(ObservableEmitter<Integer> e) {
    try {
        Thread.sleep(1000); // 假设此处是耗时操作
    } catch (Exception ee) {
        ee.printStackTrace();
    }
    e.onNext(100);
    e.onComplete();
}
 
Example 15
Source File: RxJavaFragment.java    From AndroidQuick with MIT License 5 votes vote down vote up
@Override
public void subscribe(ObservableEmitter<Integer> e) throws Exception {
    Log.d(TAG, "1");
    e.onNext(1);
    SystemClock.sleep(1000);
    Log.d(TAG, "2");
    e.onNext(2);
    SystemClock.sleep(1000);
    e.onComplete();
}
 
Example 16
Source File: DataCleaner.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
/**
 * Clear application data.
 *
 * @param clearFavorites true to clear favorite movies, otherwise or not.
 * @return  RxJava Observable for the timed stages.
 */
public Observable<Timed<Stage>> clearData(final boolean clearFavorites) {
    final ObservableOnSubscribe<Stage> clearingTasks = (ObservableEmitter<Stage> emitter) -> {
        if (clearFavorites) {
            // Clear favorites
            emitter.onNext(Stage.FAVORITES);
            favoriteMovieCollection.clear();
            favoriteStore.clearData();
        }

        // Clear HTTP cache
        emitter.onNext(Stage.HTTP_CACHE);
        movieDbService.clearCache();

        // Clear image cache
        emitter.onNext(Stage.IMAGE_CACHE);
        glide.clearDiskCache();
        emitter.onNext(Stage.COMPLETE); // Emit an extra event to delay the onComplete event.
        emitter.onComplete();
    };

    return Observable.create(clearingTasks)
            .timeInterval()
            .map(delayTimeCalculator)
            .scan(delayAggregation)
            .delay(item -> Observable.timer(item.time(), TimeUnit.MILLISECONDS))
            .subscribeOn(Schedulers.io());
}
 
Example 17
Source File: RxContacts.java    From MultiContactPicker with Apache License 2.0 4 votes vote down vote up
private void fetch (LimitColumn columnLimitChoice, ObservableEmitter emitter) {
    LongSparseArray<Contact> contacts = new LongSparseArray<>();
    Cursor cursor = createCursor(getFilter(columnLimitChoice));
    cursor.moveToFirst();
    int idColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
    int inVisibleGroupColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.IN_VISIBLE_GROUP);
    int displayNamePrimaryColumnIndex = cursor.getColumnIndex(DISPLAY_NAME);
    int starredColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.STARRED);
    int photoColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_URI);
    int thumbnailColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);
    int hasPhoneNumberColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);


    while (!cursor.isAfterLast()) {
        long id = cursor.getLong(idColumnIndex);
        Contact contact = contacts.get(id, null);
        if (contact == null) {
            contact = new Contact(id);
        }
        ColumnMapper.mapInVisibleGroup(cursor, contact, inVisibleGroupColumnIndex);
        ColumnMapper.mapDisplayName(cursor, contact, displayNamePrimaryColumnIndex);
        ColumnMapper.mapStarred(cursor, contact, starredColumnIndex);
        ColumnMapper.mapPhoto(cursor, contact, photoColumnIndex);
        ColumnMapper.mapThumbnail(cursor, contact, thumbnailColumnIndex);

        switch (columnLimitChoice){
            case EMAIL:
                getEmail(id, contact);
                break;
            case PHONE:
                getPhoneNumber(id, cursor, contact, hasPhoneNumberColumnIndex);
                break;
            case NONE:
                getEmail(id, contact);
                getPhoneNumber(id, cursor, contact, hasPhoneNumberColumnIndex);
                break;
        }

        if(columnLimitChoice == LimitColumn.EMAIL){
            if(contact.getEmails().size() > 0){
                contacts.put(id, contact);
                //noinspection unchecked
                emitter.onNext(contact);
            }
        }else{
            contacts.put(id, contact);
            //noinspection unchecked
            emitter.onNext(contact);
        }
        cursor.moveToNext();
    }
    cursor.close();
    emitter.onComplete();
}
 
Example 18
Source File: DecompressionModel.java    From Dainty with Apache License 2.0 4 votes vote down vote up
private void unRar(File mInput, File mOutput, final ObservableEmitter<Long> emitter) throws IOException, RarException {
    Archive rarFile = null;
    try {
        rarFile = new Archive(mInput, new UnrarCallback() {
            @Override
            public boolean isNextVolumeReady(File file) {
                return false;
            }

            @Override
            public void volumeProgressChanged(long l, long l1) {
                emitter.onNext(l);
            }
        });
        long uncompressedSize = getOriginalSize(rarFile);
        //publishProgress(0L, uncompressedSize);
        emitter.onNext(uncompressedSize);

        for (int i = 0; i < rarFile.getFileHeaders().size(); i++) {
            if (emitter.isDisposed())
                break;
            FileHeader fh = rarFile.getFileHeaders().get(i);
            String entryPath;
            if (fh.isUnicode()) {
                entryPath = fh.getFileNameW().trim();
            } else {
                entryPath = fh.getFileNameString().trim();
            }
            entryPath = entryPath.replaceAll("\\\\", "/");
            File file = new File(mOutput, entryPath);
            if (fh.isDirectory()) {
                //noinspection ResultOfMethodCallIgnored
                file.mkdirs();
            } else {
                File parent = file.getParentFile();
                if (parent != null && !parent.exists()) {
                    //noinspection ResultOfMethodCallIgnored
                    parent.mkdirs();
                }
                FileOutputStream fileOut = new FileOutputStream(file);
                rarFile.extractFile(fh, fileOut);
                fileOut.close();
            }
        }
        emitter.onComplete();
    } finally {
        if (rarFile != null) {
            try {
                rarFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 19
Source File: FingerprintAuthenticationObservable.java    From RxFingerprint with Apache License 2.0 4 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintAuthenticationResult> emitter, AuthenticationResult result) {
    emitter.onNext(new FingerprintAuthenticationResult(FingerprintResult.AUTHENTICATED, null));
    emitter.onComplete();
}
 
Example 20
Source File: DataSetCompleteRegistrationPostCall.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void uploadInternal(D2ProgressManager progressManager,
                            ObservableEmitter<D2Progress> emitter,
                            List<DataSetCompleteRegistration> toPostDataSetCompleteRegistrations,
                            List<DataSetCompleteRegistration> toDeleteDataSetCompleteRegistrations) throws D2Error {
    DataValueImportSummary dataValueImportSummary = DataValueImportSummary.EMPTY;

    DataSetCompleteRegistrationPayload dataSetCompleteRegistrationPayload
            = new DataSetCompleteRegistrationPayload(toPostDataSetCompleteRegistrations);
    if (!toPostDataSetCompleteRegistrations.isEmpty()) {
        dataValueImportSummary = apiCallExecutor.executeObjectCall(
                dataSetCompleteRegistrationService.postDataSetCompleteRegistrations(
                        dataSetCompleteRegistrationPayload));
    }

    List<DataSetCompleteRegistration> deletedDataSetCompleteRegistrations = new ArrayList<>();
    List<DataSetCompleteRegistration> withErrorDataSetCompleteRegistrations = new ArrayList<>();
    if (!toDeleteDataSetCompleteRegistrations.isEmpty()) {
        for (DataSetCompleteRegistration dataSetCompleteRegistration
                : toDeleteDataSetCompleteRegistrations) {
            try {
                CategoryOptionCombo coc = categoryOptionComboCollectionRepository
                        .withCategoryOptions()
                        .uid(dataSetCompleteRegistration.attributeOptionCombo())
                        .blockingGet();
                apiCallExecutor.executeObjectCallWithEmptyResponse(
                        dataSetCompleteRegistrationService.deleteDataSetCompleteRegistration(
                                dataSetCompleteRegistration.dataSet(),
                                dataSetCompleteRegistration.period(),
                                dataSetCompleteRegistration.organisationUnit(),
                                coc.categoryCombo().uid(),
                                semicolonSeparatedCollectionValues(UidsHelper.getUids(coc.categoryOptions())),
                                false));
                deletedDataSetCompleteRegistrations.add(dataSetCompleteRegistration);
            } catch (D2Error d2Error) {
                withErrorDataSetCompleteRegistrations.add(dataSetCompleteRegistration);
            }
        }
    }

    dataSetCompleteRegistrationImportHandler.handleImportSummary(
            dataSetCompleteRegistrationPayload, dataValueImportSummary, deletedDataSetCompleteRegistrations,
            withErrorDataSetCompleteRegistrations);

    emitter.onNext(progressManager.increaseProgress(DataSetCompleteRegistration.class, true));
    emitter.onComplete();
}