Skip to content

Conversation

@Salehcodes
Copy link

Description (required)
This PR fixes an issue in Explore → Map where the turn on location services dialog was shown multiple times even after the user enabled location services from system settings.

Fixes #6597

What changes did you make and why?

Root cause

ExploreFragment was registering a ViewPager.OnPageChangeListener twice:

  • once in onCreateView()
  • and again inside onCreateOptionsMenu()

onCreateOptionsMenu() can be called multiple times during the fragment lifecycle so this resulted in multiple listeners being added over time.

Each listener calls:
mapRootFragment?.requestLocationIfNeeded()

Tests performed (required)
after I ran lint and verified the project builds successfully using the BetaDebug build variant.

  1. Disabled location services on the device
  2. Opened the app and navigated to Explore → Map
  3. Tapped Settings from the dialog and enabled location services
  4. Returned to the app and verified that the dialog no longer appears repeatedly
  5. Confirmed map loads nearby media correctly after location is enabled. (here i discovered an issue that the map do not refresh automatically after enabling location in current version I will open a new issue for that).

Tested {build variant betaDebug} on {Galaxy s23 } with android 16.

Screenshots (for UI changes only)
before :

Screen_Recording_20260101_152652_Commons.mp4

after:

Screen_Recording_20260102_211854_Commons.mp4

@github-actions
Copy link

github-actions bot commented Jan 3, 2026

✅ Generated APK variants!


// if on Map tab, show all menu options, else only show search
binding!!.viewPager.addOnPageChangeListener(object : OnPageChangeListener {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = Unit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these functions no longer needed? Is this change really required to fix the issue?

Copy link
Author

Choose a reason for hiding this comment

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

These functions are still needed, but only one instance of the OnPageChangeListener is required.
Before this change, the same ViewPager.OnPageChangeListener logic was being registered in two different lifecycle methods:
once in onCreateView()
and again in onCreateOptionsMenu()
Since onCreateOptionsMenu() can be invoked multiple times during the fragment lifecycle, this resulted in multiple listeners being added over time.
Each listener triggers:
mapRootFragment?.requestLocationIfNeeded()
when the Map tab is selected, so switching to the Map tab caused requestLocationIfNeeded() to be called multiple times, which led to the duplicate location-off dialogs.
The listener in onCreateView() already handles:
detecting when the Map tab is selected
triggering requestLocationIfNeeded() exactly once per tab selection
Therefore, the additional listener in onCreateOptionsMenu() was redundant and was the source of the repeated calls. Removing it ensures the logic runs only once, while preserving all existing behavior.

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.

[Bug]: Asking for permission message stays after going to phone settings

2 participants