use of io.reactivex.ObservableSource in project android-mvp-architecture by MindorksOpenSource.
the class AppDataManager method seedDatabaseQuestions.
@Override
public Observable<Boolean> seedDatabaseQuestions() {
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
return mDbHelper.isQuestionEmpty().concatMap(new Function<Boolean, ObservableSource<? extends Boolean>>() {
@Override
public ObservableSource<? extends Boolean> apply(Boolean isEmpty) throws Exception {
if (isEmpty) {
Type type = $Gson$Types.newParameterizedTypeWithOwner(null, List.class, Question.class);
List<Question> questionList = gson.fromJson(CommonUtils.loadJSONFromAsset(mContext, AppConstants.SEED_DATABASE_QUESTIONS), type);
return saveQuestionList(questionList);
}
return Observable.just(false);
}
});
}
use of io.reactivex.ObservableSource in project 91Pop by DanteAndroid.
the class SettingPresenter method moveOldDownloadVideoToNewDir.
@Override
public void moveOldDownloadVideoToNewDir(final String newDirPath, final QMUICommonListItemView qmuiCommonListItemView) {
Observable.fromCallable(new Callable<File[]>() {
@Override
public File[] call() throws Exception {
File file = new File(dataManager.getCustomDownloadVideoDirPath());
return file.listFiles();
}
}).flatMap(new Function<File[], ObservableSource<File>>() {
@Override
public ObservableSource<File> apply(File[] files) throws Exception {
return Observable.fromArray(files);
}
}).filter(new Predicate<File>() {
@Override
public boolean test(File file) throws Exception {
return file.getName().endsWith(".mp4");
}
}).map(new Function<File, String>() {
@Override
public String apply(File file) throws Exception {
FileUtils.move(file, new File(newDirPath, file.getName()));
return file.getAbsolutePath();
}
}).delay(1, TimeUnit.SECONDS).compose(RxSchedulersHelper.<String>ioMainThread()).compose(provider.<String>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<String>() {
@Override
public void onBegin(Disposable d) {
ifViewAttached(new ViewAction<SettingView>() {
@Override
public void run(@NonNull SettingView view) {
view.beginMoveOldDirDownloadVideoToNewDir();
}
});
}
@Override
public void onSuccess(final String s) {
Logger.t(TAG).d("正在移动到:" + s);
}
@Override
public void onError(String msg, int code) {
ifViewAttached(new ViewAction<SettingView>() {
@Override
public void run(@NonNull SettingView view) {
view.setNewDownloadVideoDirError("移动文件失败,无法设置新目录");
}
});
}
@Override
public void onComplete() {
super.onComplete();
ifViewAttached(new ViewAction<SettingView>() {
@Override
public void run(@NonNull SettingView view) {
dataManager.setCustomDownloadVideoDirPath(newDirPath);
qmuiCommonListItemView.setDetailText(newDirPath);
view.setNewDownloadVideoDirSuccess("移动文件完成,设置新目录成功");
}
});
}
});
}
use of io.reactivex.ObservableSource in project Store by NYTimes.
the class StoreActivity method loadPosts.
@SuppressWarnings("CheckReturnValue")
public void loadPosts() {
BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww");
/*
First call to get(awwRequest) will use the network, then save response in the in-memory
cache. Subsequent calls will retrieve the cached version of the data.
But, since the policy of this store is to expire after 10 seconds, the cache will
only be used for subsequent requests that happen within 10 seconds of the initial request.
After that, the request will use the network.
*/
this.nonPersistedStore.get(awwRequest).flatMapObservable(new Function<RedditData, ObservableSource<Post>>() {
@Override
public ObservableSource<Post> apply(@NonNull RedditData redditData) throws Exception {
return sanitizeData(redditData);
}
}).toList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showPosts, throwable -> {
Log.e(StoreActivity.class.getSimpleName(), throwable.getMessage(), throwable);
});
}
Aggregations