GCX-HCI / ThirtyInch

a MVP library for Android favoring a stateful Presenter
Apache License 2.0
1.03k stars 101 forks source link

Bugfix - Lifecycleobserver and RxHandler* #61

Closed StefMa closed 7 years ago

StefMa commented 7 years ago

Given: : šŸŒ® Our sample is broken. It through a IllegalStateException: view subscriptions can't be handled when there is no view. This cames from RxTiPresenterSubscriptionHandler.manageViewSubscription which is called from the HelloWorldPresenter#onAttachView(view)

But: Why it says that there isn't any view, when onAttachView is called? šŸ¤”

Reson: āŒ After a quick reseach the reason is simple: We introduced such a exception with #58 . So this is working like expected. But: Why is is thrown on onAttachView? Because of the TiLifecycleObserver. The documentation says:

/**

  • 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 */

beforeLifecycleEvent is wrong here. If we take a look into the implementation in TiPresenter#attachView we see the following:

moveToState(State.VIEW_ATTACHED, false);
// Stuff
onAttachView(view);
// More stuff
moveToState(State.VIEW_ATTACHED, true);

The second parameter here indicates if the on* method is already called. Which is wrong according to the documentation of the TiLifecycleObserver.

The fix: šŸ’š Because we have already implementations with the TiLifecycleObserver I've just changed the documentation (and a better boolean name šŸ˜‰)

I've also fixed the implementation of the RxTiPresenter*Handler.. which have thrown the exception...