organicmaps / organicmaps

🍃 Organic Maps is a free Android & iOS offline maps app for travelers, tourists, hikers, and cyclists. It uses crowd-sourced OpenStreetMap data and is developed with love by MapsWithMe (MapsMe) founders and our community. No ads, no tracking, no data collection, no crapware. Please donate to support the development!
https://organicmaps.app
Apache License 2.0
8.58k stars 837 forks source link

[android] Implements exit button in navigation notification #7953

Open kavikhalique opened 2 weeks ago

kavikhalique commented 2 weeks ago

Fixes #7492 Implements Exit button in navigation notification

Use Case - 1 - If user clicks on exit navigation in background of app it simply stops navigation and closes the notification 2 - If user clicks the button while app is in foreground it works similar to pressing the stop button in bottom navigation of navigation screen

What I changed - I added one button in notification and attached a pending intent with the button. Pending intent runs once the exit button gets clicked. It triggers cancel() method inside RoutingController.java class which basically stops the navigation which is going on. Then it triggers another method stopself() which closes the notification.

Screenshots- fix2 fix1

Sample Video -

https://github.com/organicmaps/organicmaps/assets/120750626/235c6ffb-eb4a-4c8f-b80c-43b560f65f61

RedAuburn commented 2 weeks ago

Tried it out and found an issue:

  1. start routing with vehicle mode
  2. move app to background
  3. press exit button in notification
  4. re-open app

Result: routing has stopped correctly, but the vehicle map style is still used. (it should be the default clear style)

kavikhalique commented 2 weeks ago

Tried it out and found an issue:

  1. start routing with vehicle mode

  2. move app to background

  3. press exit button in notification

  4. re-open app

Result:

routing has stopped correctly, but the vehicle map style is still used. (it should be the default clear style)

Thanks, I missed that. Will correct it soon.

Jean-BaptisteC commented 2 weeks ago

You can use same method used on stop button in navigation bottom bar

kavikhalique commented 2 weeks ago

You can use same method used on stop button in navigation bottom bar

Yes sir, but the issue is that there is a container class which contains all the methods and in background it becomes null because it has been defined inside mwmActivity.java class.

I was thinking to create a shared preference variable which will be set to true if notification will be exited from background and then whenever activity will resume in foreground it will check the value of shared preference and if it will be true it will trigger the stop button method of navigationController.

biodranik commented 2 weeks ago

Is it possible to call the same methods that are called by pressing the stop button in the nav panel?

kavikhalique commented 2 weeks ago

Is it possible to call the same methods that are called by pressing the stop button in the nav panel?

Yes sir, I am calling the same method but whenever that method is triggered from background of navigation activity it does not updates the map activity to default.

Trying to figure it out where things are actually changing.

kavikhalique commented 1 week ago

Fixed the issue of UI updation after exiting navigation from background of app.

What i did -

Used Shared preferences to check if app is in background or foreground and accordingly called methods after coming in foreground which were not available when app was in background.

Please review it - @Jean-BaptisteC @RedAuburn

kavikhalique commented 1 week ago

Please sir review my changes and if there is any changes required please inform me. @rtsisyk @biodranik

kavikhalique commented 1 week ago

Is it the only/cleanest way to fix the issue?

I have gone through OSMAnd's code base for exit button they have created a broadcast receiver and they have a separate class which determines the mode of application and then according to foreground or background mode actions are taken.

Since I didn't found any such class to determine the mode of app i used shared preference.

I feel better and cleaner ways exist.

kavikhalique commented 1 week ago

Sir please review it and if there is any suggestions please disscuss so that i can correct it @rtsisyk

rtsisyk commented 1 week ago

Sir please review it and if there is any suggestions please disscuss so that i can correct it @rtsisyk

I will take a look. Sorry for the delay!!

kavikhalique commented 3 days ago

Could you please evaluate the idea of routing STOP_NAVIGATION intent via MwmActivity to eliminate the need of using IS_CANCELLED_FROM_BACKGROUND flag in Preferences (see a comment inline)? I think it would make the code even much simpler.

I dont know why this idea didn't strike in my mind. Your idea is much better and clean will modify the code accordingly and will update you ASAP.

The only doubt i have is, if we will send intent to activity class it will open up the activity in foreground (means it will open the app)

I will check this out once and then will update you

kavikhalique commented 2 days ago

I have tried that but the issue is with UX.

If we will route STOP_NAVIGATION through mwmActivity it opens the app in foreground.

But if the navigation is cancelled from background it should not bring the app in foreground. It should just close the notification. @rtsisyk