Skip to content

Commit ab23767

Browse files
author
Lauri Aalto
committed
sockeqwe#290: Added null checks to prevent NPEs with ViewGroupDelegate cleanup + fixed some typos
1 parent 20c46cc commit ab23767

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

mvp/src/main/java/com/hannesdorfmann/mosby3/mvp/delegate/ViewGroupMvpDelegateImpl.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ViewGroupMvpDelegateImpl<V extends MvpView, P extends MvpPresenter<
6363

6464
private boolean checkedActivityFinishing = false;
6565
private boolean presenterDetached = false;
66-
private boolean presenterDestroeyed = false;
66+
private boolean presenterDestroyed = false;
6767

6868
public ViewGroupMvpDelegateImpl(@NonNull View view,
6969
@NonNull ViewGroupDelegateCallback<V, P> delegateCallback,
@@ -231,18 +231,18 @@ public void onRestoreInstanceState(Parcelable state) {
231231
keepPresenterDuringScreenOrientationChange, activity);
232232

233233
if (destroyPermanently) {
234-
destroyPresenterIfnotDoneYet();
234+
destroyPresenterIfNotDoneYet();
235235
} else if (!activity.isChangingConfigurations()) {
236236
// View removed manually from screen
237-
destroyPresenterIfnotDoneYet();
237+
destroyPresenterIfNotDoneYet();
238238
}
239239
} // else --> see onActivityDestroyed()
240240
}
241241

242242
@Override public void onActivityDestroyed(Activity activity) {
243243

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

247247
activity.getApplication().unregisterActivityLifecycleCallbacks(this);
248248
checkedActivityFinishing = true;
@@ -253,7 +253,7 @@ public void onRestoreInstanceState(Parcelable state) {
253253
if (destroyedPermanently) {
254254
// Whole activity will be destroyed
255255
detachPresenterIfNotDoneYet();
256-
destroyPresenterIfnotDoneYet();
256+
destroyPresenterIfNotDoneYet();
257257
}
258258
}
259259

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

280-
private void destroyPresenterIfnotDoneYet() {
281-
if (!presenterDestroeyed) {
280+
private void destroyPresenterIfNotDoneYet() {
281+
if (!presenterDestroyed) {
282282
P presenter = delegateCallback.getPresenter();
283-
presenter.destroy();
284-
presenterDestroeyed = true;
283+
if (presenter != null) {
284+
presenter.destroy();
285+
}
286+
presenterDestroyed = true;
285287
activity.getApplication().unregisterActivityLifecycleCallbacks(this);
286288
if (DEBUG) {
287289
Log.d(DEBUG_TAG, "Presenter destroyed: " + presenter);
@@ -298,7 +300,9 @@ private void destroyPresenterIfnotDoneYet() {
298300
private void detachPresenterIfNotDoneYet() {
299301
if (!presenterDetached) {
300302
P presenter = delegateCallback.getPresenter();
301-
presenter.detachView();
303+
if (presenter != null) {
304+
presenter.detachView();
305+
}
302306
presenterDetached = true;
303307
if (DEBUG) {
304308
Log.d(DEBUG_TAG,

0 commit comments

Comments
 (0)