-
Notifications
You must be signed in to change notification settings - Fork 101
Change onWakeUp() to onAttachView(TiView) and onSleep() to onDetachView() #26
Conversation
…ew() The new naming is more convenient thoughout most android MPV libraries. Switching to Ti should now be simpler. It also reflects better than before that the it's only the view being absent. wakeup and sleep could imply the Presenter is kind of starting/stopping which is not the case. onAttachView(TiView) has the attached view as first parameter which is @nonnull. No calls to getView() are neccessary inside onAttachView(TiView). getView() is now @nullable (and always was null when not between wakeup() and sleep() state) and causes lint to hint a Nullable warning. This warning was missing and caused a lot of NPE for Ti beginners
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.
The changes looks great and I approve that.
But don't forget to update the Readme
;)
} | ||
|
||
mView = view; | ||
moveToState(State.VIEW_ATTACHED, false); | ||
mCalled = false; |
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.
mCalled isn't a good name.
I think it would be nicer if we have two booleans. mViewAttachedCalled
and mViewDetachedCalled
.
So we can't override the single boolean anymore...
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.
it's a general property for all super call checks. Implementation and naming copied from AOSP Actiivty
and Fragment
https://github.com/android/platform_frameworks_base/blob/4b1a8f46d6ec55796bf77fd8921a5a242a219278/core/java/android/app/Activity.java#L748
@@ -288,25 +323,18 @@ public String toString() { | |||
} | |||
|
|||
/** | |||
* when calling {@link #wakeUp()} the presenter can start communicating with the {@link | |||
* TiView}. | |||
* The view is now attached and ready to receive events. {@link #getView()} is not guaranteed |
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.
Better Javadoc:
getView() may be null
.
Current javadoc is very confused and have to be read more than once ;)
*/ | ||
protected void onDetachView() { | ||
if (mCalled) { | ||
throw new IllegalAccessError("don't call #onSleep() directly, call #detachView()"); |
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.
don`t call #onDetachView () directly...
right?
public void attachWithoutInitialize() throws Exception { | ||
|
||
// not calling | ||
// mPresenter.create(); |
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.
Can be removed. The method should say what happen here.
Maybe a better name is attachWithoutOnCreate
. But I'm also fine with the current name
The new naming is more convenient throughout most android MPV libraries. Switching to
Ti
should now be simpler. It reflects better that it's only about the view being absent. wakeup and sleep could imply the Presenter is kind of starting/stopping which is not the case.onAttachView(TiView)
has the attached view as first parameter which is@NonNull
. No calls togetView()
are neccessary insideonAttachView(TiView)
.getView()
is now@Nullable
(and always was null when not betweenwakeup()
andsleep()
state) and causes lint to hint a Nullable warning. This warning was missing and caused a lot of NPE forTi
beginners