All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.tatarka.rxloader.RxLoader Maven / Gradle / Ivy

package me.tatarka.rxloader;

import rx.Observable;

/**
 * Manages a given {@link rx.Observable}, handling activity destruction, orientation changes, and
 * posting to the UI thread. You construct one using {@link me.tatarka.rxloader.RxLoaderManager#create(String,
 * rx.Observable, RxLoaderObserver)}.
 *
 * @param  the observable's value type
 */
public class RxLoader extends BaseRxLoader {
    private Observable observable;

    RxLoader(RxLoaderBackend manager, String tag, Observable observable, RxLoaderObserver observer) {
        super(manager, tag, observer);
        this.observable = observable;
    }

    /**
     * Starts the {@link rx.Observable} by subscribing to it. If the {@code Observable} is already
     * started, then does nothing.
     *
     * @return the {@code RxLoader} for chaining
     */
    public RxLoader start() {
        start(observable);
        return this;
    }

    /**
     * Restarts the {@link rx.Observable} by subscribing to it, unsubscribing first if it has
     * already been started.
     *
     * @return the {@code RxLoader} for chaining
     */
    public RxLoader restart() {
        restart(observable);
        return this;
    }

    /**
     * Saves the last value that the {@link rx.Observable} returns in {@link
     * rx.Observer#onNext(Object)} in the Activities'ss ore Fragment's instanceState bundle. When
     * the {@code Activity} or {@code Fragment} is recreated, then the value will be redelivered.
     *
     * The value must implement {@link android.os.Parcelable}. If not, you should use {@link
     * me.tatarka.rxloader.RxLoader#save(SaveCallback)} to save and restore the value yourself.
     *
     * @return the {@code RxLoader} for chaining
     */
    public RxLoader save() {
        super.save();
        return this;
    }

    /**
     * Saves the last value that the {@link rx.Observable} returns in {@link
     * rx.Observer#onNext(Object)} in the Activities's ore Fragment's instanceState bundle. When the
     * {@code Activity} or {@code Fragment} is recreated, then the value will be redelivered.
     *
     * @param saveCallback the callback to handle saving and restoring the value
     * @return the {@code RxLoader} for chaining
     */
    public RxLoader save(SaveCallback saveCallback) {
        super.save(saveCallback);
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy