

package com.stolets.rxdiffutil;

import android.app.Activity;
import android.support.annotation.NonNull;

import com.stolets.rxdiffutil.diffrequest.DiffRequestManagerHolder;
import com.stolets.rxdiffutil.diffrequest.DiffRequestManagerHolderRetriever;

import static com.stolets.rxdiffutil.internal.Preconditions.checkNotNull;

/**
 * Represents an entry point for making diff requests.
 */
@SuppressWarnings("WeakerAccess")
public final class RxDiffUtil {
    private RxDiffUtil() {
    }

    /**
     * Creates the retained fragment that is used to listen to the given activity lifecycle events.
     *
     * @param activity The {@link Activity} the diff requests lifecycle will be bound to.
     * @return The {@link DiffRequestManagerHolder} retrieved from the retained fragment.
     * @throws NullPointerException If the given activity is null.
     */
    @NonNull
    public static DiffRequestManagerHolder bindTo(@NonNull final Activity activity) {
        checkNotNull(activity, "activity must not be null!");
        return DiffRequestManagerHolderRetriever.retrieveFrom(activity);
    }
}
