Java Code Examples for io.reactivex.Observable.concat()

The following are Jave code examples for showing how to use concat() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: buckaroo   File: CacheTasks.java   View Source Code Vote up 6 votes
public static Observable<Event> cloneAndCheckoutUsingCache(
    final GitCommit gitCommit, final Path targetDirectory, final StandardCopyOption... copyOptions) {

    Preconditions.checkNotNull(gitCommit);
    Preconditions.checkNotNull(targetDirectory);

    final Path cachePath = getCacheFolder(targetDirectory.getFileSystem())
        .resolve(StringUtils.escapeStringAsFilename(gitCommit.url));

    final Observable<Event> copy = Completable.fromAction(() ->
        EvenMoreFiles.copyDirectory(cachePath, targetDirectory, copyOptions))
        .toObservable();

    return Observable.concat(
        GitTasks.ensureCloneAndCheckout(gitCommit, cachePath, true), copy);
}
 
Example 2
Project: XPermission   File: XPermission.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.M)
private Observable<Permission> requestImplementation(Context context,final String... permissions) {
    List<Observable<Permission>> list = new ArrayList<>(permissions.length);
    List<String> unrequestedPermissions = new ArrayList<>();

    // In case of multiple permissions, we create an Observable for each of them.
    // At the end, the observables are combined to have a unique response.
    for (String permission : permissions) {
        XPermissionActivity.log("Requesting permission " + permission);
        if (isGranted(context,permission)) {
            // Already granted, or not Android M
            // Return a granted Permission object.
            list.add(Observable.just(new Permission(permission, true, false)));
            continue;
        }

        if (isRevoked(context,permission)) {
            // Revoked by a policy, return a denied Permission object.
            list.add(Observable.just(new Permission(permission, false, false)));
            continue;
        }

        PublishSubject<Permission> subject = XPermissionActivity.getSubjectByPermission(permission);
        // Create a new subject if not exists
        if (subject == null) {
            unrequestedPermissions.add(permission);
            subject = PublishSubject.create();
            XPermissionActivity.setSubjectForPermission(permission, subject);
        }

        list.add(subject);
    }

    if (!unrequestedPermissions.isEmpty()) {
        String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);
        requestPermissionsFromActivity(context,unrequestedPermissionsArray);
    }
    return Observable.concat(Observable.fromIterable(list));
}
 
Example 3
Project: AesExoPlayer   File: RxPermissions.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.M)
private Observable<Permission> requestImplementation(final String... permissions) {
    List<Observable<Permission>> list = new ArrayList<>(permissions.length);
    List<String> unrequestedPermissions = new ArrayList<>();

    // In case of multiple permissions, we create an Observable for each of them.
    // At the end, the observables are combined to have a unique response.
    for (String permission : permissions) {
        Log.i("","Requesting permission " + permission);
        if (isGranted(permission)) {
            // Already granted, or not Android M
            // Return a granted Permission object.
            list.add(Observable.just(new Permission(permission, true, false)));
            continue;
        }

        if (isRevoked(permission)) {
            // Revoked by a policy, return a denied Permission object.
            list.add(Observable.just(new Permission(permission, false, false)));
            continue;
        }

        PublishSubject<Permission> subject = mRxPermissionsFragment.getSubjectByPermission(permission);
        // Create a new subject if not exists
        if (subject == null) {
            unrequestedPermissions.add(permission);
            subject = PublishSubject.create();
            mRxPermissionsFragment.setSubjectForPermission(permission, subject);
        }

        list.add(subject);
    }

    if (!unrequestedPermissions.isEmpty()) {
        String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);
        requestPermissionsFromFragment(unrequestedPermissionsArray);
    }
    return Observable.concat(Observable.fromIterable(list));
}
 
Example 4
Project: XSnow   File: RxPermissions.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.M)
private Observable<Permission> requestImplementation(final String... permissions) {
    List<Observable<Permission>> list = new ArrayList<>(permissions.length);
    List<String> unrequestedPermissions = new ArrayList<>();

    // In case of multiple permissions, we create an Observable for each of them.
    // At the end, the observables are combined to have a unique response.
    for (String permission : permissions) {
        ViseLog.i("Requesting permission " + permission);
        if (isGranted(permission)) {
            // Already granted, or not Android M
            // Return a granted Permission object.
            list.add(Observable.just(new Permission(permission, true, false)));
            continue;
        }

        if (isRevoked(permission)) {
            // Revoked by a policy, return a denied Permission object.
            list.add(Observable.just(new Permission(permission, false, false)));
            continue;
        }

        PublishSubject<Permission> subject = mRxPermissionsFragment.getSubjectByPermission(permission);
        // Create a new subject if not exists
        if (subject == null) {
            unrequestedPermissions.add(permission);
            subject = PublishSubject.create();
            mRxPermissionsFragment.setSubjectForPermission(permission, subject);
        }

        list.add(subject);
    }

    if (!unrequestedPermissions.isEmpty()) {
        String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);
        requestPermissionsFromFragment(unrequestedPermissionsArray);
    }
    return Observable.concat(Observable.fromIterable(list));
}
 
Example 5
Project: KTools   File: RxPermissions.java   View Source Code Vote up 5 votes
@TargetApi(Build.VERSION_CODES.M)
private Observable<Permission> requestImplementation(final String... permissions) {
    List<Observable<Permission>> list = new ArrayList<>(permissions.length);
    List<String> unrequestedPermissions = new ArrayList<>();

    // In case of multiple permissions, we create an Observable for each of them.
    // At the end, the observables are combined to have a unique response.
    for (String permission : permissions) {
        mRxPermissionsFragment.log("Requesting permission " + permission);
        if (isGranted(permission)) {
            // Already granted, or not Android M
            // Return a granted Permission object.
            list.add(Observable.just(new Permission(permission, true, false)));
            continue;
        }

        if (isRevoked(permission)) {
            // Revoked by a policy, return a denied Permission object.
            list.add(Observable.just(new Permission(permission, false, false)));
            continue;
        }

        PublishSubject<Permission> subject = mRxPermissionsFragment.getSubjectByPermission(permission);
        // Create a new subject if not exists
        if (subject == null) {
            unrequestedPermissions.add(permission);
            subject = PublishSubject.create();
            mRxPermissionsFragment.setSubjectForPermission(permission, subject);
        }

        list.add(subject);
    }

    if (!unrequestedPermissions.isEmpty()) {
        String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);
        requestPermissionsFromFragment(unrequestedPermissionsArray);
    }
    return Observable.concat(Observable.fromIterable(list));
}
 
Example 6
Project: RxPermissions   File: RxPermissions.java   View Source Code Vote up 5 votes
private Observable<Permission> requestImplementation(final String... permissions) {
    List<Observable<Permission>> list = new ArrayList<>(permissions.length);
    List<String> unrequestedPermissions = new ArrayList<>();

    // In case of multiple permissions, we create an Observable for each of them.
    // At the end, the observables are combined to have a unique response.
    for (String permission : permissions) {
        mRxPermissionsFragment.log("Requesting permission " + permission);
        if (isGranted(permission)) {
            // Already granted, or not Android M
            // Return a granted Permission object.
            list.add(Observable.just(new Permission(permission, true, false)));
            continue;
        }

        if (isRevoked(permission)) {
            // Revoked by a policy, return a denied Permission object.
            list.add(Observable.just(new Permission(permission, false, false)));
            continue;
        }

        PublishSubject<Permission> subject = mRxPermissionsFragment.getSubjectByPermission(permission);
        // Create a new subject if not exists
        if (subject == null) {
            unrequestedPermissions.add(permission);
            subject = PublishSubject.create();
            mRxPermissionsFragment.setSubjectForPermission(permission, subject);
        }

        list.add(subject);
    }

    if (!unrequestedPermissions.isEmpty()) {
        String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);
        requestPermissionsFromFragment(unrequestedPermissionsArray);
    }
    return Observable.concat(Observable.fromIterable(list));
}
 
Example 7
Project: RxPermission   File: RealRxPermission.java   View Source Code Vote up 5 votes
@NonNull @CheckReturnValue @TargetApi(M) Observable<Permission> requestOnM(@NonNull final String... permissions) {
  final List<Observable<Permission>> list = new ArrayList<>(permissions.length);
  final List<String> unrequestedPermissions = new ArrayList<>();

  // In case of multiple permissions, we create an observable for each of them.
  // At the end, the observables are combined to have a unique response.

  for (final String permission : permissions) {
    if (isGranted(permission)) {
      list.add(Observable.just(Permission.granted(permission)));
    } else if (isRevokedByPolicy(permission)) {
      list.add(Observable.just(Permission.revokedByPolicy(permission)));
    } else {
      PublishSubject<Permission> subject = currentPermissionRequests.get(permission);

      // Create a new subject if not exists
      if (subject == null) {
        unrequestedPermissions.add(permission);
        subject = PublishSubject.create();
        currentPermissionRequests.put(permission, subject);
      }

      list.add(subject);
    }
  }

  if (!unrequestedPermissions.isEmpty()) {
    final String[] permissionsToRequest = unrequestedPermissions.toArray(new String[0]);
    startShadowActivity(permissionsToRequest);
  }

  return Observable.concat(Observable.fromIterable(list));
}
 
Example 8
Project: buckaroo   File: UpgradeTasks.java   View Source Code Vote up 5 votes
public static Observable<Event> upgradeInWorkingDirectory(final FileSystem fs) {

        Preconditions.checkNotNull(fs);

        return Observable.concat(
            ResolveTasks.resolveDependenciesInWorkingDirectory(fs),
            InstallExistingTasks.installExistingDependenciesInWorkingDirectory(fs),
            Observable.just(Notification.of("Upgrade complete")));
    }
 
Example 9
Project: buckaroo   File: InstallExistingTasks.java   View Source Code Vote up 5 votes
private static Observable<Event> downloadResolvedDependency(final FileSystem fs, final ResolvedDependency resolvedDependency, final Path target) {

        Preconditions.checkNotNull(fs);
        Preconditions.checkNotNull(resolvedDependency);
        Preconditions.checkNotNull(target);

        final Observable<Event> downloadSourceCode = Single.fromCallable(() -> Files.exists(target))
            .flatMapObservable(exists -> {
                if (exists) {
                    return Observable.empty();
                }
                return resolvedDependency.source.join(
                    gitCommit -> CacheTasks.cloneAndCheckoutUsingCache(gitCommit, target),
                    remoteArchive -> CacheTasks.downloadUsingCache(remoteArchive, target, StandardCopyOption.REPLACE_EXISTING));
            });

        final Path buckFilePath = fs.getPath(target.toString(), "BUCK");
        final Observable<Event> downloadBuckFile = Files.exists(buckFilePath) ?
            Observable.empty() :
            resolvedDependency.buckResource
                .map(x -> CommonTasks.downloadRemoteFile(fs, x, buckFilePath))
                .orElse(Observable.empty());

        final Path buckarooDepsFilePath = fs.getPath(target.toString(), "BUCKAROO_DEPS");
        final Observable<Event> writeBuckarooDeps = Single.fromCallable(() ->
            CommonTasks.generateBuckarooDeps(resolvedDependency.dependencies))
            .flatMap(content -> CommonTasks.writeFile(
                content,
                buckarooDepsFilePath,
                true))
            .cast(Event.class)
            .toObservable();

        return Observable.concat(
            downloadSourceCode,
            downloadBuckFile,
            writeBuckarooDeps.cast(Event.class));
    }
 
Example 10
Project: buckaroo   File: InstallExistingTasks.java   View Source Code Vote up 5 votes
private static Observable<Event> installDependencyLock(final Path projectDirectory, final DependencyLock lock) {

        Preconditions.checkNotNull(projectDirectory);
        Preconditions.checkNotNull(lock);

        final Path dependencyDirectory = dependencyFolder(buckarooDirectory(projectDirectory), lock.identifier)
            .toAbsolutePath();

        return Observable.concat(

            // Download the code and BUCK file
            downloadResolvedDependency(projectDirectory.getFileSystem(), lock.origin, dependencyDirectory),

            // Touch .buckconfig
            CommonTasks.touchFile(dependencyDirectory.resolve(".buckconfig")).toObservable(),

            // Generate .buckconfig.local
            CommonTasks.writeFile(
                generateBuckConfigLocal(
                    dependencyDirectory.resolve(".buckconfig.local"),
                    projectDirectory,
                    lock.origin.dependencies.stream()
                        .map(i -> i.identifier)
                        .collect(ImmutableList.toImmutableList())),
                dependencyDirectory.resolve(".buckconfig.local"),
                true).toObservable(),

            // Mark the installation as complete
            Observable.just(DependencyInstalledEvent.of(lock))
        );
    }
 
Example 11
Project: buckaroo   File: CacheTasks.java   View Source Code Vote up 5 votes
public static Observable<Event> downloadUsingCache(final RemoteFile file, final Path target) {

        Preconditions.checkNotNull(file);
        Preconditions.checkNotNull(target);

        final FileSystem fs = target.getFileSystem();
        final Path cachePath = getCachePath(fs, file);

        return Observable.concat(
            downloadToCache(fs, file),
            CommonTasks.copy(cachePath, target, StandardCopyOption.REPLACE_EXISTING)
                .toObservable()
        );
    }
 
Example 12
Project: buckaroo   File: CacheTasks.java   View Source Code Vote up 5 votes
public static Observable<Event> downloadUsingCache(final RemoteArchive archive, final Path target, final CopyOption... copyOptions) {

        Preconditions.checkNotNull(archive);
        Preconditions.checkNotNull(target);

        final FileSystem fs = target.getFileSystem();
        final Path cachePath = getCachePath(fs, archive.asRemoteFile());

        return Observable.concat(
            downloadToCache(fs, archive.asRemoteFile()),
            CommonTasks.unzip(cachePath, target, archive.subPath, copyOptions).toObservable());
    }
 
Example 13
Project: TurboChat   File: MessageViewModel.java   View Source Code Vote up 5 votes
public Observable<List<Message>> getMessages() {
    final Observable<List<Message>> network = messageRepository.getMessages()
            .doOnNext(messageCache::writeToCache);

    final Observable<List<Message>> cache = messageCache.getMessages().filter(messages -> !messages.isEmpty());

    return Observable.concat(cache, network);
}
 
Example 14
Project: wayf-cloud   File: AuthenticationFacadeImpl.java   View Source Code Vote up 4 votes
@Override
public Observable<AuthenticationCredentials> getCredentialsForAuthenticatable(Authenticatable authenticatable) {
    return Observable.concat(
            authorizationTokenDao.getCredentialsForAuthenticatable(authenticatable),
            emailPasswordCredentialsDao.getCredentialsForAuthenticatable(authenticatable));
}
 
Example 15
Project: buckaroo   File: QuickstartTasks.java   View Source Code Vote up 4 votes
private static Observable<Event> createAppSkeleton(final Path projectDirectory, final Project project) {

        Preconditions.checkNotNull(projectDirectory);
        Preconditions.checkNotNull(project);

        final FileSystem fs = projectDirectory.getFileSystem();
        final Identifier projectIdentifier = project.name.map(StringUtils::escapeStringGitHubStyle)
            .flatMap(Identifier::parse)
            .orElseGet(() -> Identifier.of("my-project"));

        return Observable.concat(ImmutableList.of(

            // Write the project file
            CommonTasks.writeFile(
                Serializers.serialize(project),
                fs.getPath("buckaroo.json").toAbsolutePath(),
                false)
                .toObservable()
                .cast(Event.class)
                .onErrorReturnItem(Notification.of("buckaroo.json already exists!")),

            // Touch the .buckconfig
            CommonTasks.touchFile(fs.getPath(projectDirectory.toString(), ".buckconfig"))
                .toObservable(),

            // Generate an empty BUCKAROO_DEPS
            Single.fromCallable(() -> CommonTasks.generateBuckarooDeps(ImmutableList.of()))
                .flatMap(content ->
                    CommonTasks.writeFile(
                        content,
                        fs.getPath(projectDirectory.toString(), "BUCKAROO_DEPS"),
                        false))
                .toObservable()
                .cast(Event.class)
                .onErrorReturnItem(Notification.of("BUCKAROO_DEPS already exists!")),

            // Create the project directories
            CommonTasks.createDirectory(fs.getPath(projectDirectory.toString(), projectIdentifier.name))
                .toObservable(),

            CommonTasks.createDirectory(fs.getPath(projectDirectory.toString(), projectIdentifier.name, "src"))
                .toObservable(),

            CommonTasks.createDirectory(fs.getPath(projectDirectory.toString(), projectIdentifier.name, "include"))
                .toObservable(),

            CommonTasks.createDirectory(fs.getPath(projectDirectory.toString(), projectIdentifier.name, "detail"))
                .toObservable(),

            // Write the Hello World cpp file
            Single.fromCallable(QuickstartTasks::helloWorldCpp).flatMap(content -> CommonTasks.writeFile(
                content,
                fs.getPath(projectDirectory.toString(), projectIdentifier.name, "apps", "main.cpp"),
                false))
                .toObservable()
                .cast(Event.class)
                .onErrorReturnItem(Notification.of("apps/main.cpp already exists!")),

            // Generate the BUCK file
            Single.fromCallable(() -> Either.orThrow(BuckFile.generate(projectIdentifier)))
                .flatMapObservable(content -> Observable.concat(
                    CommonTasks.writeFile(
                        content,
                        fs.getPath(projectDirectory.toString(), "BUCK"),
                        false).toObservable()
                        .cast(Event.class)
                        .onErrorReturnItem(Notification.of("BUCK-file already exists!")),
                    Observable.just(Notification.of("buck run :main"))
                ))
        ));
    }
 
Example 16
Project: buckaroo   File: Process.java   View Source Code Vote up 4 votes
public static <S, T> Process<S, T> of(final Observable<S> states, final Single<T> result) {
    return new Process<>(Observable.concat(
        states.map(Either::left),
        result.toObservable().map(Either::right)
    ));
}
 
Example 17
Project: buckaroo   File: Process.java   View Source Code Vote up 4 votes
public static <S> Process<S, S> usingLastAsResult(final Observable<S> observable) {
    return new Process<>(Observable.concat(
        observable.map(Either::left),
        observable.lastOrError().map(Either::<S, S>right).toObservable()
    ));
}