Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Bugfix - Lifecycleobserver and RxHandler* #61

Merged
merged 2 commits into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public RxTiPresenterSubscriptionHandler(final TiPresenter presenter) {
presenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
if (state == TiPresenter.State.VIEW_DETACHED && beforeLifecycleEvent) {
final boolean hasLifecycleMethodBeenCalled) {
if (state == TiPresenter.State.VIEW_DETACHED && !hasLifecycleMethodBeenCalled) {
// unsubscribe all UI subscriptions created in onAttachView() and added
// via manageViewSubscription(Subscription)
if (mUiSubscriptions != null) {
Expand All @@ -44,11 +44,11 @@ public void onChange(final TiPresenter.State state,
}
}

if (state == TiPresenter.State.VIEW_ATTACHED && beforeLifecycleEvent) {
if (state == TiPresenter.State.VIEW_ATTACHED && !hasLifecycleMethodBeenCalled) {
mUiSubscriptions = new CompositeSubscription();
}

if (state == TiPresenter.State.DESTROYED && beforeLifecycleEvent) {
if (state == TiPresenter.State.DESTROYED && !hasLifecycleMethodBeenCalled) {
mPresenterSubscriptions.unsubscribe();
mPresenterSubscriptions = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void call(final Subscriber<? super Boolean> subscriber) {
.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
final boolean hasLifecycleMethodBeenCalled) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(state
== TiPresenter.State.VIEW_ATTACHED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public RxTiPresenterDisposableHandler(final TiPresenter presenter) {
presenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
if (state == TiPresenter.State.VIEW_DETACHED && beforeLifecycleEvent) {
final boolean hasLifecycleMethodBeenCalled) {
if (state == TiPresenter.State.VIEW_DETACHED && !hasLifecycleMethodBeenCalled) {
// dispose all UI disposable created in onAttachView(TiView) and added
// via manageViewDisposable(Disposable...)
if (mUiDisposables != null) {
Expand All @@ -44,11 +44,11 @@ public void onChange(final TiPresenter.State state,
}
}

if (state == TiPresenter.State.VIEW_ATTACHED && beforeLifecycleEvent) {
if (state == TiPresenter.State.VIEW_ATTACHED && !hasLifecycleMethodBeenCalled) {
mUiDisposables = new CompositeDisposable();
}

if (state == TiPresenter.State.DESTROYED && beforeLifecycleEvent) {
if (state == TiPresenter.State.DESTROYED && !hasLifecycleMethodBeenCalled) {
mPresenterDisposables.dispose();
mPresenterDisposables = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void subscribe(final ObservableEmitter<Boolean> emitter)
.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
final boolean hasLifecycleMethodBeenCalled) {
if (!emitter.isDisposed()) {
emitter.onNext(state ==
TiPresenter.State.VIEW_ATTACHED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ public interface TiLifecycleObserver {
/**
* gets called when the {@link net.grandcentrix.thirtyinch.TiPresenter.State} changes
*
* @param state the new state of the {@link TiPresenter}
* @param beforeLifecycleEvent {@code true} when called before the {@code on...} lifecycle
* methods, {@code false} when called after
* @param state the new state of the {@link TiPresenter}
* @param hasLifecycleMethodBeenCalled {@code false} when called before the {@code on...}
* lifecycle methods, {@code true} when called after
* @see TiPresenter#onCreate()
* @see TiPresenter#onAttachView(TiView)
* @see TiPresenter#onDetachView()
* @see TiPresenter#onDestroy()
*/
void onChange(final TiPresenter.State state, final boolean beforeLifecycleEvent);
void onChange(final TiPresenter.State state, final boolean hasLifecycleMethodBeenCalled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void testCreate() throws Exception {
mPresenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled});
}
});

Expand All @@ -79,8 +79,8 @@ public void testDestroy() throws Exception {
mPresenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled});
}
});

Expand All @@ -104,8 +104,8 @@ public void testRemoveObserver() throws Exception {
final Removable removable = mPresenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled});
}
});

Expand Down Expand Up @@ -136,8 +136,8 @@ public void testRemoveObserverTwice() throws Exception {
final TiLifecycleObserver observer = new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled});
}
};

Expand All @@ -161,8 +161,8 @@ public void testSleep() throws Exception {
mPresenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent, mPresenter.getView()});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled, mPresenter.getView()});
}
});

Expand All @@ -187,8 +187,8 @@ public void testWakeup() throws Exception {
mPresenter.addLifecycleObserver(new TiLifecycleObserver() {
@Override
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
states.add(new Object[]{state, beforeLifecycleEvent, mPresenter.getView()});
final boolean hasLifecycleMethodBeenCalled) {
states.add(new Object[]{state, hasLifecycleMethodBeenCalled, mPresenter.getView()});
}
});

Expand Down