/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.rx;

import io.reactivex.Completable;
import java.util.concurrent.Callable;
import java8.util.function.Supplier;

/** Helpers for working with RxJava Completable classes. */
public abstract class RxCompletable {
  /** Do not instantiate. */
  private RxCompletable() {}

  public static Completable completeIf(Callable<Boolean> conditionFunction) {
    return Completable.create(
        em -> {
          if (conditionFunction.call()) {
            em.onComplete();
          }
        });
  }

  public static Completable completeOrError(
      Supplier<Boolean> supplier, Class<? extends Throwable> errorClass) {
    return Completable.create(
        em -> {
          if (supplier.get()) {
            em.onComplete();
          } else {
            em.onError(errorClass.newInstance());
          }
        });
  }
}

@@ -636,30 +636,131 @@
 ort 
-io.reactivex.Completab
+androidx.annotation.NonNull;%0Aimport androidx.annotation.Nullable;%0Aimport io.reactivex.Completable;%0Aimport io.reactivex.Sing
 le;%0A
@@ -793,24 +793,61 @@
 t.Callable;%0A
+import java8.util.function.Consumer;%0A
 import java8
@@ -1555,32 +1555,32 @@
 ));%0A          %7D%0A
-
         %7D);%0A  %7D%0A
@@ -1578,11 +1578,1022 @@
  %7D);%0A  %7D
+%0A%0A  /**%0A   * Receives a %7B@link Completable%7D and returns a %7B@link Single %3CBoolean%3E%7D that emits %3Ccode%3Etrue%0A   * %3C/code%3E if the %3Ccode%3ECompletable%3C/code%3E completes successful, %3Ccode%3Efalse%3C/code%3E otherwise. An%0A   * action to be performed in case or error can also be passed through the argument %3Ccode%3E%0A   * exceptionConsumer%3C/code%3E.%0A   *%0A   * @param completable The input %7B@link Completable%7D%0A   * @param exceptionConsumer A consumer to process the exception (eg log it) in case the %7B@link%0A   *     Completable%7D terminates with an error.%0A   * @return The %7B@link Single%3CBoolean%3E%7D, as described above.%0A   */%0A  public static Single%3CBoolean%3E toSingle(%0A      @NonNull Completable completable, @Nullable Consumer%3C? super Throwable%3E exceptionConsumer) %7B%0A    return completable%0A        .doOnError(%0A            throwable -%3E %7B%0A              if (exceptionConsumer != null) %7B%0A                exceptionConsumer.accept(throwable);%0A              %7D%0A            %7D)%0A        .toSingleDefault(true)%0A        .onErrorReturnItem(false);%0A  %7D
 %0A%7D%0A

Add helper method to convert Completable to Single<Boolean>