[go: up one dir, main page]

Skip to content

Commit

Permalink
#290: Added null checks to prevent NPEs with ViewGroupDelegate cleanu…
Browse files Browse the repository at this point in the history
…p + fixed some typos (#297)
  • Loading branch information
laalto authored and sockeqwe committed Apr 24, 2018
1 parent 62bcd2a commit 2edf89c
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ViewGroupMvpDelegateImpl<V extends MvpView, P extends MvpPresenter<

private boolean checkedActivityFinishing = false;
private boolean presenterDetached = false;
private boolean presenterDestroeyed = false;
private boolean presenterDestroyed = false;

public ViewGroupMvpDelegateImpl(@NonNull View view,
@NonNull ViewGroupDelegateCallback<V, P> delegateCallback,
Expand Down Expand Up @@ -231,18 +231,18 @@ public void onRestoreInstanceState(Parcelable state) {
keepPresenterDuringScreenOrientationChange, activity);

if (destroyPermanently) {
destroyPresenterIfnotDoneYet();
destroyPresenterIfNotDoneYet();
} else if (!activity.isChangingConfigurations()) {
// View removed manually from screen
destroyPresenterIfnotDoneYet();
destroyPresenterIfNotDoneYet();
}
} // else --> see onActivityDestroyed()
}

@Override public void onActivityDestroyed(Activity activity) {

if (activity == this.activity) {
// The hosting activity of this view has been destroyed, so time to destoryed the presenter too?
// The hosting activity of this view has been destroyed, so time to destroy the presenter too?

activity.getApplication().unregisterActivityLifecycleCallbacks(this);
checkedActivityFinishing = true;
Expand All @@ -253,7 +253,7 @@ public void onRestoreInstanceState(Parcelable state) {
if (destroyedPermanently) {
// Whole activity will be destroyed
detachPresenterIfNotDoneYet();
destroyPresenterIfnotDoneYet();
destroyPresenterIfNotDoneYet();
}
}

Expand All @@ -277,11 +277,13 @@ public void onRestoreInstanceState(Parcelable state) {
@Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}

private void destroyPresenterIfnotDoneYet() {
if (!presenterDestroeyed) {
private void destroyPresenterIfNotDoneYet() {
if (!presenterDestroyed) {
P presenter = delegateCallback.getPresenter();
presenter.destroy();
presenterDestroeyed = true;
if (presenter != null) {
presenter.destroy();
}
presenterDestroyed = true;
activity.getApplication().unregisterActivityLifecycleCallbacks(this);
if (DEBUG) {
Log.d(DEBUG_TAG, "Presenter destroyed: " + presenter);
Expand All @@ -298,7 +300,9 @@ private void destroyPresenterIfnotDoneYet() {
private void detachPresenterIfNotDoneYet() {
if (!presenterDetached) {
P presenter = delegateCallback.getPresenter();
presenter.detachView();
if (presenter != null) {
presenter.detachView();
}
presenterDetached = true;
if (DEBUG) {
Log.d(DEBUG_TAG,
Expand Down

0 comments on commit 2edf89c

Please sign in to comment.