-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NavigationViewEventDispatcher remove navigation listeners in onDestroy #1013
Conversation
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.
Should we maybe remove all listeners in onStop
?
@devotaaabel none of the other listeners are added to |
fa4ad77
to
e7e4b25
Compare
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.
Some minor comments.
@@ -42,6 +46,13 @@ void initializeListeners(NavigationViewOptions navigationViewOptions, MapboxNavi | |||
assignInstructionListListener(navigationViewOptions.instructionListListener()); | |||
} | |||
|
|||
void onStop(MapboxNavigation navigation) { |
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.
Could you add the @Nullable
annotation?
navigation.addProgressChangeListener(navigationViewOptions.progressChangeListener()); | ||
ProgressChangeListener progressChangeListener = navigationViewOptions.progressChangeListener(); | ||
if (progressChangeListener != null) { | ||
this.progressChangeListener = progressChangeListener; |
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.
We can move this assignment to L#69 like
this.progressChangeListener = navigationViewOptions.progressChangeListener();
and remove this line. It's safe because then we're checking if the listener is null
in removeProgressChangeListener
👇
navigation.addMilestoneEventListener(navigationViewOptions.milestoneEventListener()); | ||
MilestoneEventListener milestoneEventListener = navigationViewOptions.milestoneEventListener(); | ||
if (milestoneEventListener != null) { | ||
this.milestoneEventListener = milestoneEventListener; |
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.
Same here ☝️
@@ -290,4 +294,69 @@ public void onInstructionListShown() { | |||
|
|||
verify(instructionListListener, times(1)).onInstructionListVisibilityChanged(true); | |||
} | |||
|
|||
@Test | |||
public void onInstructionListHidden_listenerReturnsFalse() { |
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.
We can extract shared code between these new tests.
b5c9df4
to
c059603
Compare
c059603
to
bc204dc
Compare
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.
Minor comment not blocking the PR 🚀
@Test | ||
public void onProgressChangeListenerAddedInOptions_isAddedToNavigation() { | ||
NavigationViewEventDispatcher eventDispatcher = new NavigationViewEventDispatcher(); | ||
ProgressChangeListener progressChangeListener = mock(ProgressChangeListener.class); |
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.
Minor comment - what about 👇?
private ProgressChangeListener setupProgressChangeListener(NavigationViewOptions options) {
ProgressChangeListener progressChangeListener = mock(ProgressChangeListener.class);
when(options.progressChangeListener()).thenReturn(progressChangeListener);
return progressChangeListener;
}
bc204dc
to
b670619
Compare
Closes #981
Because
MapboxNavigation
survives rotation, any listeners from the view must be removed before rotation or shutdown. This was not the case for theMilestoneEventListener
andProgressChangeListener
being added throughNavigationViewOptions
. A memory leak would then result from the old listener instances.