Skip to content

Add ability to check configuration changing #6484

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Oct 15, 2022

Description

I'm finding more and more reasons for this when I'm trying to change the NavigationOptions at runtime.

Having a way to know that the options are changing, is useful. Also, exposing the configuration boolean is useful.

Opening as draft because I didn't spend much time testing

Screenshots or Gifs

@kmadsen kmadsen force-pushed the km-add-ability-to-check-configuration-changing branch from 52a4d96 to 427154d Compare October 15, 2022 00:40
@codecov
Copy link

codecov bot commented Oct 15, 2022

Codecov Report

Merging #6484 (d8f325b) into main (6b92019) will decrease coverage by 2.45%.
The diff coverage is 66.66%.

❗ Current head d8f325b differs from pull request most recent head ee9c56b. Consider uploading reports for the commit ee9c56b to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #6484      +/-   ##
============================================
- Coverage     72.50%   70.05%   -2.46%     
+ Complexity     5550     4839     -711     
============================================
  Files           779      708      -71     
  Lines         30069    27875    -2194     
  Branches       3547     3278     -269     
============================================
- Hits          21801    19527    -2274     
- Misses         6843     7066     +223     
+ Partials       1425     1282     -143     
Impacted Files Coverage Δ
...x/navigation/core/lifecycle/MapboxNavigationApp.kt 17.14% <0.00%> (-1.04%) ⬇️
...tion/core/lifecycle/MapboxNavigationAppDelegate.kt 91.89% <100.00%> (+0.98%) ⬆️
...mapbox/navigation/navigator/internal/TripStatus.kt 0.00% <0.00%> (-100.00%) ⬇️
.../model/roadobject/restrictedarea/RestrictedArea.kt 0.00% <0.00%> (-100.00%) ⬇️
...ava/com/mapbox/navigation/dropin/NavigationView.kt 0.00% <0.00%> (-97.30%) ⬇️
...p/model/roadobject/border/CountryBorderCrossing.kt 0.00% <0.00%> (-80.00%) ⬇️
...odel/roadobject/railwaycrossing/RailwayCrossing.kt 0.00% <0.00%> (-78.95%) ⬇️
.../model/roadobject/tollcollection/TollCollection.kt 0.00% <0.00%> (-76.00%) ⬇️
...ip/model/roadobject/location/RoadObjectLocation.kt 0.00% <0.00%> (-73.34%) ⬇️
...del/roadobject/border/CountryBorderCrossingInfo.kt 0.00% <0.00%> (-73.34%) ⬇️
... and 297 more

*/
@UiThread
@JvmStatic
fun isConfigurationChanging(): Boolean = mapboxNavigationAppDelegate.isConfigurationChanging()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you envision using these methods? Do you have an example?
I can't say about options changing but regarding configuration changing I'm not sure if that's the way to go.
I'm worried that we might use this method somewhere and when it returns true we'll just ignore some actions, meanwhile the state will become inconsistent because some other components will be recreated.
I think it would be more neat and clear if the components that don't care about configuration changes just had a broader lifecycle. It's basically your first idea from #6766 (comment).

Copy link
Contributor Author

@kmadsen kmadsen Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I have the same concern. I've been debating whether the MapboxNavigationObserver implementation should ignore the detach->attach when configuration is changing. Or if MapboxNavigaitonApp should not detach observers when configuration is changing.

I think we need to support the case where, a MapboxNavigationObserver is only attached while in landscape mode. So I've been thinking it should be the MapboxNavigationObserver responsibility to create a definition and usage requirements

Copy link
Contributor Author

@kmadsen kmadsen Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are issues with putting the logic in MapboxNavigationObserver implementations. For example, if we want the observer to be usable without MapboxNavigationApp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So another option am considering, is what if you can specify what you want during registration. For example, add a new way to register an observer

MapboxNavigationApp.registerStrongObserver(observer)

the strong (there is probably a better word) observer would not detach during configuration or option changes. another option is to add parameters to the registerObserver function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the strong observer idea. And I think that a new type of observer is more explicit than passing the options as an argument. It's also less flexible but I'm not sure if we're gonna need a lot of flexibility here.
And I guess we should also support the case when we want to do A on onAttached, B on configuration/options change and C on onDetached. We'd probably need two different observers to resolve this. To make it possible we should guarantee the order in which the observers are called. For example, if we register one MapboxNavigationObserver (O1) and MapboxNavigationStrongObserver (O2), then common onAttached/onDetached should be passed first to O1, then to O2 (or whatever order is more convenient). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the strong observer idea.

👍

And I think that a new type of observer is more explicit than passing the options as an argument

Do you mean, preferring 2 over 1 like this? I can see it, but there are pros and cons 🤔

  1. MapboxNavigationApp.registerStrongObserver(object : MapboxNavigationObserver ..)
  2. MapboxNavigationApp.registerObserver(object : MapboxNavigationStrongObserver ..)
  3. Add MapboxNavigationObserver#isStrong() overridable configuration
  4. Add MapboxNavigationObserver#onConfigurationChanged() and then make all observers strong
  5. Add MapboxNavigationApp#isConfigurationChanging() so that onAttached/onDetached can figure it out

I'm not sure what I prefer yet.. it seems all of them technically work so we could list some pros/cons to decide.

And I guess we should also support the case when we want to do A on onAttached, B on configuration/options change and C on onDetached.

We can also consider, adding an overridable function to MapboxNavigationObserver (e.g., onConfigurationChanged..). The pull request as it is now, requires a condition to see if onAttached/onDetached is triggered by a configuration change.

MapboxNavigationObserver (O1) and MapboxNavigationStrongObserver (O2), then common onAttached/onDetached should be passed first to O1, then to O2 (or whatever order is more convenient). WDYT?

I'm not yet sold on MapboxNavigationStrongObserver because I bet if we listed the pros and cons, we may prefer solution 3 to add an overridable configuration to MapboxNavigationObserver, or we may decide on something else. I don't like that we would have to change the type of the observer. I would like to at least start with the flexibility to be able to make any MapboxNavigationObserver a strong observer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we would have to change the type of the observer.

Why? We are intoducing a new type of observer with behaviour that was not present before. We could do with a new interface here.

Add MapboxNavigationObserver#isStrong() overridable configuration

How are you going to implement it without breaking the API? There were some problems with introducing an interface method with default implementation. Converting it to an abstract class will break java users for sure.

Copy link
Contributor Author

@kmadsen kmadsen Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we would have to change the type of the observer.
Why? We are intoducing a new type of observer with behaviour that was not present before. We could do with a new interface here.

There is no difference with the implementation of the interface. Maybe we do this approach, just think we should consider other approaches first.

How are you going to implement it without breaking the API?

We can change the MapboxNavigationObserver implementation if we convert the interface to a java interface (an example here). Default functions are supported in java, default functions will have better support in kotlin after version 1.6.20 https://youtrack.jetbrains.com/issue/KT-54239

@kmadsen kmadsen force-pushed the km-add-ability-to-check-configuration-changing branch from d8f325b to ee9c56b Compare January 4, 2023 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants