-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorporate feedback from #130 #138
Changes from all commits
bd22bc2
caf904a
79e6dbf
94212eb
9bf1993
53eef69
7ac1488
d564b40
cb432a8
07f0f1e
ec190c0
9606ae4
b38d03f
7705288
daad41b
500f337
e7e1b87
a0d8556
22ba683
959fe09
6a45aa4
44b362f
ba8bd87
9c3edf4
3b87876
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ final class ViewAttachEventsObservable extends Observable<ViewLifecycleEvent> { | |
} | ||
|
||
@Override protected void subscribeActual(Observer<? super ViewLifecycleEvent> observer) { | ||
Listener listener = new Listener(view, observer); | ||
observer.onSubscribe(listener); | ||
if (!isMainThread()) { | ||
observer.onError(new IllegalStateException("Views can only be bound to on the main thread!")); | ||
return; | ||
|
@@ -46,9 +48,10 @@ final class ViewAttachEventsObservable extends Observable<ViewLifecycleEvent> { | |
// Emit the last event, like a behavior subject | ||
observer.onNext(ViewLifecycleEvent.ATTACH); | ||
} | ||
Listener listener = new Listener(view, observer); | ||
observer.onSubscribe(listener); | ||
view.addOnAttachStateChangeListener(listener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too, if disposed, the listener will remain added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (listener.isDisposed()) { | ||
view.removeOnAttachStateChangeListener(listener); | ||
} | ||
} | ||
|
||
static final class Listener extends MainThreadDisposable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* 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 | ||
* | ||
* http://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.uber.autodispose; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Atomic container for Throwables including combining and having a | ||
* terminal state via ExceptionHelper. | ||
* <p> | ||
* Watch out for the leaked AtomicReference methods! | ||
*/ | ||
final class AtomicThrowable extends AtomicReference<Throwable> { | ||
|
||
private static final long serialVersionUID = 3949248817947090603L; | ||
|
||
/** | ||
* Atomically adds a Throwable to this container (combining with a previous Throwable is | ||
* necessary). | ||
* | ||
* @param t the throwable to add | ||
* @return true if successful, false if the container has been terminated | ||
*/ | ||
public boolean addThrowable(Throwable t) { | ||
return ExceptionHelper.addThrowable(this, t); | ||
} | ||
|
||
/** | ||
* Atomically terminate the container and return the contents of the last | ||
* non-terminal Throwable of it. | ||
* | ||
* @return the last Throwable | ||
*/ | ||
@Nullable | ||
public Throwable terminate() { | ||
return ExceptionHelper.terminate(this); | ||
} | ||
|
||
public boolean isTerminated() { | ||
return get() == ExceptionHelper.TERMINATED; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,9 @@ public interface ScopeHandler { | |
return new LifecycleScopeProviderHandlerImpl(scope); | ||
} | ||
|
||
private static class MaybeScopeHandlerImpl implements ScopeHandler { | ||
private static final class MaybeScopeHandlerImpl implements ScopeHandler { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Fixed in 959fe09 but planning to remove this class in the near future anyway now that |
||
|
||
private final Maybe<?> scope; | ||
final Maybe<?> scope; | ||
|
||
MaybeScopeHandlerImpl(Maybe<?> scope) { | ||
this.scope = scope; | ||
|
@@ -196,9 +196,9 @@ public <T> Function<Observable<? extends T>, ObservableSubscribeProxy<T>> forObs | |
} | ||
} | ||
|
||
private static class ScopeProviderHandlerImpl implements ScopeHandler { | ||
private static final class ScopeProviderHandlerImpl implements ScopeHandler { | ||
|
||
private final ScopeProvider scope; | ||
final ScopeProvider scope; | ||
|
||
ScopeProviderHandlerImpl(ScopeProvider scope) { | ||
this.scope = scope; | ||
|
@@ -226,9 +226,9 @@ public <T> Function<Observable<? extends T>, ObservableSubscribeProxy<T>> forObs | |
} | ||
} | ||
|
||
private static class LifecycleScopeProviderHandlerImpl implements ScopeHandler { | ||
private static final class LifecycleScopeProviderHandlerImpl implements ScopeHandler { | ||
|
||
private final LifecycleScopeProvider<?> scope; | ||
final LifecycleScopeProvider<?> scope; | ||
|
||
LifecycleScopeProviderHandlerImpl(LifecycleScopeProvider<?> scope) { | ||
this.scope = scope; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
Observer
disposes immediately, this will still add the listener and keep a reference to it. You should check forisDisposed
after this add and callremoveObserver
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a0d8556