Skip to content

feat(flow): add Kotlin Flow extensions for LocationManager and shape managers#391

Open
dkhawk wants to merge 1 commit into
mainfrom
feature/location-flow-extensions
Open

feat(flow): add Kotlin Flow extensions for LocationManager and shape managers#391
dkhawk wants to merge 1 commit into
mainfrom
feature/location-flow-extensions

Conversation

@dkhawk

@dkhawk dkhawk commented May 27, 2026

Copy link
Copy Markdown
Contributor

This PR introduces comprehensive Kotlin Flow extensions to the maps-utils-ktx library, adding modern reactive APIs for shape collections, ClusterManager, and device location tracking.

All changes are fully backward-compatible and verified with robust unit/integration tests.

1. Fused & Device Location Flow Tracking 🗺️📍

Exposed two subscriber-driven Flow APIs on LocationManager for streaming coordinates:

  • coarseLocationEvents(): Streams coarse WiFi/Cell coordinates (NETWORK_PROVIDER with fallback to PASSIVE_PROVIDER) under @RequiresPermission(Manifest.permission.ACCESS_COARSE_LOCATION).
  • fineLocationEvents(): Streams precise satellite coordinates (GPS_PROVIDER) under @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION).
  • Automatic Subscriber Lifecycle: Setup requests start only when actively collected, and cleanly unregister (removeUpdates) immediately when collectors cancel or close, eliminating memory leaks.
  • Hardware State Clean Closure: The flow channel is closed cleanly with a CancellationException if the user disables location providers (GPS/Network) mid-collection in Android Settings.
  • Backward Compatibility: Fully overrides LocationListener to ensure seamless execution on minSdkVersion 23.

2. Shape Collection & Cluster Flow Extensions 📦

Added clean Flow wrappers for all listener callbacks in managers:

  • ClusterManager: clusterClickEvents(), clusterItemClickEvents(), clusterInfoWindowClickEvents(), clusterInfoWindowLongClickEvents(), clusterItemInfoWindowClickEvents(), and clusterItemInfoWindowLongClickEvents().
  • Collection Managers: Added clickEvents() to MarkerManager.Collection (including info window click/long-click flows), PolylineManager.Collection, PolygonManager.Collection, CircleManager.Collection, and GroundOverlayManager.Collection.
  • API Compatibility Invariant: Completely preserved the legacy addPolyline and addPolygon inline helper extension functions to prevent any breaking regressions.

3. Adversarial Unit Tests 🧪

Authored a comprehensive unit test suite in maps-utils-ktx simulating concurrent edge-cases:

  • LocationManagerTest.kt: Verifies registration, flow emissions, automatic unregistration, and hardens provider disabled closure (testCoarseLocationProviderDisabled).
  • CollectionManagersTest.kt: Emulates the single-listener slot registration of the Maps SDK to verify that concurrent flow subscribers cleanly hijack and disconnect correctly (testConcurrentCollectionMarkerClick).
  • ClusterManagerTest.kt: Thoroughly tests all 6 clustering flow events.

4. Working Samples in Demo App 📱

Updated the sample app MainActivity.kt and AndroidManifest.xml to prompt for runtime location permissions and demonstrate live consumption of LocationManager flows, ClusterManager flows, and Marker collection flows using repeatOnLifecycle collection blocks.


Verification Status

  • 100% of compilation checks and unit tests pass successfully with zero failures!

🧠 Workspace Assist & Gemini Agentic Skill Package

This PR introduces an ecosystem-standard local Gemini Agentic Skill configuration under the .gemini/ directory. This establishes standard assist guidelines and style rules for the android-maps-ktx library to assist developers and autonomous coding assistants.

Skill Structure & Guides:

  • .gemini/config.yaml / styleguide.md: Safety guidelines enforcing coroutine/Flow idioms, and safeguarding against single-subscriber callback slot hijacking.
  • 📂 .gemini/skills/android-maps-ktx/: Core capability registration package:
    • SKILL.md: Scope of capabilities and triggers.
    • references/gotchas.md: Guide on multicasting flows via .shareIn() to prevent listener hijacking, and Android 15+ tuner demo mode safety.
    • references/location-flows.md: Guide on coarse/fine location flows, permissions, and adb coordinates injections.
    • references/clustering-flows.md: Guide on Views-based KTX clustering, camera glide, and badge sweeps.
    • references/collection-flows.md: Guide on custom overlay click flows, Azure marker popups, and circle color swapping visual confirmation.

@dkhawk dkhawk changed the base branch from main to feature/flow-extensions May 27, 2026 21:42
@dkhawk dkhawk force-pushed the feature/location-flow-extensions branch 2 times, most recently from b1dd995 to fe2033d Compare June 1, 2026 16:43
@dkhawk dkhawk changed the base branch from feature/flow-extensions to main June 1, 2026 16:45
@dkhawk dkhawk force-pushed the feature/location-flow-extensions branch from fe2033d to 906f3c5 Compare June 1, 2026 16:48
@dkhawk dkhawk changed the title feat(location-flow): add LocationManager and clustering Flow extensions feat(flow): add Kotlin Flow extensions for LocationManager and shape managers Jun 1, 2026
@snippet-bot

snippet-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 11 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Comment thread app/src/main/res/layout/activity_snippet_execution.xml Fixed
Comment thread app/src/main/res/layout/activity_snippet_menu.xml Fixed
Comment thread gradle/libs.versions.toml Fixed
Comment thread gradle/libs.versions.toml Fixed
Comment thread gradle/libs.versions.toml Fixed
Comment thread gradle/libs.versions.toml Fixed
Comment thread gradle/libs.versions.toml Fixed
Comment thread gradle/libs.versions.toml Fixed
@dkhawk dkhawk force-pushed the feature/location-flow-extensions branch 3 times, most recently from 8a52879 to dfda77e Compare June 1, 2026 22:37

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Android Lint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@dkhawk dkhawk force-pushed the feature/location-flow-extensions branch 2 times, most recently from 1dc0db4 to 998ee05 Compare June 1, 2026 23:29
@dkhawk dkhawk requested a review from kikoso June 1, 2026 23:40
…atalog demo app, and screen recording visual automation

- Core KTX Flow Extensions: Added cold, lifecycle-aware flows for LocationManager (fineLocationEvents/coarseLocationEvents), shape managers, and ClusterManager clicks, fully covered by unit tests.
- Snippets Catalog Demo App: Overhauled the app into a Material 3 card category list menu routing dynamically to immersive notch-safe snippet execution views.
- Advanced Telemetry HUD Previews: Added translucent telemetry HUD overlays and polyline path plotting to visually demonstrate sequential coordinate updates for Fine (London) and Coarse (Paris) location flows.
- Video Recording to GIF: Added support for capturing smooth, high-quality animation previews (like camera_animation_golden.gif) using screenrecord and host-side ffmpeg.
- Gemini AI Visual Verification: Integrated a Gemini AI-driven screenshot verification test framework against goldens to protect snippets from layout regressions.

TAG=agy
CONV=643f8ea1-f064-41ca-87cd-2fdb73ee13bf
@dkhawk dkhawk force-pushed the feature/location-flow-extensions branch from 998ee05 to 68819f3 Compare June 1, 2026 23:49
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