Skip to content

Commit

Permalink
Rename to AndroidLifecycleScopeProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Aug 31, 2017
1 parent 657ed5a commit 2d5bfc2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

import static com.google.common.truth.Truth.assertThat;

@RunWith(AndroidJUnit4.class) public final class ViewScopeProviderTest {
@RunWith(AndroidJUnit4.class) public final class AndroidLifecycleScopeProviderTest {

private static final RecordingObserver.Logger LOGGER = new RecordingObserver.Logger() {
@Override public void log(String message) {
Log.d(ViewScopeProviderTest.class.getSimpleName(), message);
Log.d(AndroidLifecycleScopeProviderTest.class.getSimpleName(), message);
}
};

Expand All @@ -50,11 +50,11 @@
final PublishSubject<Integer> subject = PublishSubject.create();

// Spin it up
TestLifecycleOwnerScopeProvider lifecycle = new TestLifecycleOwnerScopeProvider();
TestAndroidLifecycleScopeProvider lifecycle = new TestAndroidLifecycleScopeProvider();
lifecycle.emit(Lifecycle.Event.ON_CREATE);
lifecycle.emit(Lifecycle.Event.ON_START);
lifecycle.emit(Lifecycle.Event.ON_RESUME);
subject.to(new ObservableScoper<Integer>(LifecycleOwnerScopeProvider.from(lifecycle)))
subject.to(new ObservableScoper<Integer>(AndroidLifecycleScopeProvider.from(lifecycle)))
.subscribe(o);

Disposable d = o.takeSubscribe();
Expand All @@ -81,11 +81,11 @@
PublishSubject<Integer> subject = PublishSubject.create();

// Spin it up
TestLifecycleOwnerScopeProvider lifecycle = new TestLifecycleOwnerScopeProvider();
TestAndroidLifecycleScopeProvider lifecycle = new TestAndroidLifecycleScopeProvider();
lifecycle.emit(Lifecycle.Event.ON_CREATE);
lifecycle.emit(Lifecycle.Event.ON_START);
lifecycle.emit(Lifecycle.Event.ON_RESUME);
subject.to(new ObservableScoper<Integer>(LifecycleOwnerScopeProvider.from(lifecycle)))
subject.to(new ObservableScoper<Integer>(AndroidLifecycleScopeProvider.from(lifecycle)))
.subscribe(o);

Disposable d = o.takeSubscribe();
Expand All @@ -101,7 +101,7 @@
final PublishSubject<Integer> subject = PublishSubject.create();

UninitializedLifecycleOwner owner = new UninitializedLifecycleOwner();
subject.to(new ObservableScoper<Integer>(LifecycleOwnerScopeProvider.from(owner)))
subject.to(new ObservableScoper<Integer>(AndroidLifecycleScopeProvider.from(owner)))
.subscribe(o);

Disposable d = o.takeSubscribe();
Expand All @@ -115,14 +115,14 @@
final RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
final PublishSubject<Integer> subject = PublishSubject.create();

TestLifecycleOwnerScopeProvider lifecycle = new TestLifecycleOwnerScopeProvider();
TestAndroidLifecycleScopeProvider lifecycle = new TestAndroidLifecycleScopeProvider();
lifecycle.emit(Lifecycle.Event.ON_CREATE);
lifecycle.emit(Lifecycle.Event.ON_START);
lifecycle.emit(Lifecycle.Event.ON_RESUME);
lifecycle.emit(Lifecycle.Event.ON_PAUSE);
lifecycle.emit(Lifecycle.Event.ON_STOP);
lifecycle.emit(Lifecycle.Event.ON_DESTROY);
subject.to(new ObservableScoper<Integer>(LifecycleOwnerScopeProvider.from(lifecycle)))
subject.to(new ObservableScoper<Integer>(AndroidLifecycleScopeProvider.from(lifecycle)))
.subscribe(o);

Disposable d = o.takeSubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
import io.reactivex.functions.Function;

/**
* A {@link LifecycleScopeProvider} that can provide scoping for Android {@link LifecycleOwner}
* classes.
* A {@link LifecycleScopeProvider} that can provide scoping for Android {@link Lifecycle} and
* {@link LifecycleOwner} classes.
* <p>
* <pre><code>
* myFooObservable
* .to(new ObservableScoper<Foo>(LifecycleOwnerScopeProvider.from(lifecycleOwner)))
* .to(new ObservableScoper<Foo>(AndroidLifecycleScopeProvider.from(lifecycleOwner)))
* .subscribe();
* </code></pre>
*/
public final class LifecycleOwnerScopeProvider implements LifecycleScopeProvider<Lifecycle.Event> {
public final class AndroidLifecycleScopeProvider
implements LifecycleScopeProvider<Lifecycle.Event> {

private static final Function<Lifecycle.Event, Lifecycle.Event> CORRESPONDING_EVENTS =
new Function<Lifecycle.Event, Lifecycle.Event>() {
Expand All @@ -57,28 +58,28 @@ public final class LifecycleOwnerScopeProvider implements LifecycleScopeProvider
};

/**
* Creates a {@link LifecycleOwnerScopeProvider} for Android LifecycleOwners.
* Creates a {@link AndroidLifecycleScopeProvider} for Android LifecycleOwners.
*
* @param owner the owner to scope for
* @return a {@link LifecycleOwnerScopeProvider} against this owner.
* @return a {@link AndroidLifecycleScopeProvider} against this owner.
*/
public static LifecycleOwnerScopeProvider from(LifecycleOwner owner) {
public static AndroidLifecycleScopeProvider from(LifecycleOwner owner) {
return from(owner.getLifecycle());
}

/**
* Creates a {@link LifecycleOwnerScopeProvider} for Android Lifecycles.
* Creates a {@link AndroidLifecycleScopeProvider} for Android Lifecycles.
*
* @param lifecycle the lifecycle to scope for
* @return a {@link LifecycleOwnerScopeProvider} against this lifecycle.
* @return a {@link AndroidLifecycleScopeProvider} against this lifecycle.
*/
public static LifecycleOwnerScopeProvider from(Lifecycle lifecycle) {
return new LifecycleOwnerScopeProvider(lifecycle);
public static AndroidLifecycleScopeProvider from(Lifecycle lifecycle) {
return new AndroidLifecycleScopeProvider(lifecycle);
}

private final LifecycleEventsObservable lifecycleObservable;

private LifecycleOwnerScopeProvider(Lifecycle lifecycle) {
private AndroidLifecycleScopeProvider(Lifecycle lifecycle) {
this.lifecycleObservable = new LifecycleEventsObservable(lifecycle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
import static android.support.annotation.RestrictTo.Scope.TESTS;

/**
* LifecycleOwnerScopeProvider implementation for testing. You can either back it with your own
* AndroidLifecycleScopeProvider implementation for testing. You can either back it with your own
* instance, or just stub it in place and use its public emit() API.
*/
@RestrictTo(TESTS) public final class TestLifecycleOwnerScopeProvider
@RestrictTo(TESTS) public final class TestAndroidLifecycleScopeProvider
implements LifecycleRegistryOwner {

private final LifecycleRegistry registry;

/**
* Default constructor, creates and maintains its own {@link LifecycleRegistry} under the hood.
*/
public TestLifecycleOwnerScopeProvider() {
public TestAndroidLifecycleScopeProvider() {
this(null);
}

/**
* @param registry an optional custom {@link LifecycleRegistry} if you want to provide one. If
* {@code null}, a default implementation will be created and maintained under the hood.
*/
public TestLifecycleOwnerScopeProvider(@Nullable LifecycleRegistry registry) {
public TestAndroidLifecycleScopeProvider(@Nullable LifecycleRegistry registry) {
this.registry = registry == null ? new LifecycleRegistry(this) : registry;
}

Expand Down

0 comments on commit 2d5bfc2

Please sign in to comment.