Skip to content

Fix #1566 - Migrate remaining onBackPressed() overrides to OnBackPressedCallback#1571

Merged
aaronbrethorst merged 1 commit into
OneBusAway:mainfrom
bmander:fix/1566-onbackpressed-migration
Jun 13, 2026
Merged

Fix #1566 - Migrate remaining onBackPressed() overrides to OnBackPressedCallback#1571
aaronbrethorst merged 1 commit into
OneBusAway:mainfrom
bmander:fix/1566-onbackpressed-migration

Conversation

@bmander

@bmander bmander commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #1566

Background

On Android 13+ (API 33+), back presses route through WindowOnBackInvokedDispatcher → AndroidX OnBackPressedDispatcher, whose fallback calls ComponentActivity.super.onBackPressed() directly — silently bypassing subclass overrides. #1563 fixed this for HomeActivity; this PR migrates the two remaining activities the same way.

Changes

TripPlanActivity

  • Registers an OnBackPressedCallback in onCreate() that collapses the sliding itinerary panel when expanded, otherwise disables itself and re-dispatches — mirroring the Fix arrivals onBackPressed() on Android 13+ #1563 pattern.
  • onOptionsItemSelected (toolbar up button) now calls getOnBackPressedDispatcher().onBackPressed() instead of the deprecated onBackPressed(), keeping software and hardware back consistent.
  • Restored behavior on Android 13+: back with the panel expanded collapses it instead of finishing the whole activity.

InfrastructureIssueActivity

  • Registers an OnBackPressedCallback in onCreate() that temporarily disables itself, re-dispatches (so the fragment back stack pops, or the activity finishes), then re-enables itself and resets mServicesSpinner.
  • The re-enable deliberately differs from the HomeActivity/TripPlanActivity pattern: this activity survives repeated back presses while report fragments pop, and the spinner reset must run after each one — matching the original super.onBackPressed(); setSelection(0) semantics.
  • Restored behavior on Android 13+: after backing out of a report form, the category spinner resets to "Choose a problem" so it stays consistent with the visible screen (previously the spinner kept the stale selection, and re-selecting the same category wouldn't reopen the form).

SurveyViewUtils.java (BottomSheetDialog.onBackPressed()) is untouched, as scoped out by the issue. No Activity onBackPressed() overrides remain in the app.

Testing

  • Compiles cleanly (compileObaGoogleDebugJavaWithJavac).
  • Manually verified the report-a-problem flow on an API 33+ emulator: backing out of a report form pops the form and resets the spinner on each press; back at the top level exits the activity. Behavior on API < 33 is unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Back-button navigation improved in infrastructure issue reporting screen
    • Back-button behavior refined for trip planning screen navigation

…OnBackPressedCallback

On Android 13+ (API 33+), back presses route through OnBackPressedDispatcher,
whose fallback calls ComponentActivity.super.onBackPressed() directly,
silently bypassing subclass overrides of onBackPressed().

Migrate the two remaining affected activities to register an
OnBackPressedCallback in onCreate(), mirroring the HomeActivity fix from OneBusAway#1563:

- TripPlanActivity: panel-collapse logic now runs on back press again.
  Also route the toolbar home button through the dispatcher so software
  and hardware back stay consistent.
- InfrastructureIssueActivity: the services spinner reset now runs after
  each back press again. The callback temporarily disables itself to let
  the fragment back stack pop (or the activity finish), then re-enables
  for subsequent presses.
@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3f1b707-8c72-4b7c-aca5-4700292402b1

📥 Commits

Reviewing files that changed from the base of the PR and between 555cfd5 and ed2e427.

📒 Files selected for processing (2)
  • onebusaway-android/src/main/java/org/onebusaway/android/report/ui/InfrastructureIssueActivity.java
  • onebusaway-android/src/main/java/org/onebusaway/android/ui/TripPlanActivity.java

📝 Walkthrough

Walkthrough

Two Android activities migrate from deprecated onBackPressed() overrides to OnBackPressedCallback registered with OnBackPressedDispatcher. InfrastructureIssueActivity resets a spinner on back, while TripPlanActivity collapses a sliding panel. Both patterns now work correctly on Android 13+.

Changes

Back-press dispatcher migration

Layer / File(s) Summary
InfrastructureIssueActivity back-press migration
onebusaway-android/src/main/java/org/onebusaway/android/report/ui/InfrastructureIssueActivity.java
Adds OnBackPressedCallback import; registers callback in onCreate() that delegates to the dispatcher's default behavior, then resets the services spinner to index 0; removes the old onBackPressed() override.
TripPlanActivity back-press migration
onebusaway-android/src/main/java/org/onebusaway/android/ui/TripPlanActivity.java
Adds OnBackPressedCallback import; registers callback in onCreate() that collapses the sliding panel when expanded, otherwise disables itself and delegates to the dispatcher; removes the old onBackPressed() override; updates the home/up menu item handler to call getOnBackPressedDispatcher().onBackPressed() instead of the removed method.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • OneBusAway/onebusaway-android#1563: Establishes the OnBackPressedCallback migration pattern by fixing HomeActivity's back-press handling on Android 13+, which is applied to the same two activities in this PR.

Suggested reviewers

  • aaronbrethorst
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: migrating onBackPressed() overrides to OnBackPressedCallback, and references the fixed issue #1566.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #1566: both TripPlanActivity and InfrastructureIssueActivity are migrated to OnBackPressedCallback, preserving their original back-press logic for Android 13+ compatibility.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements: two Activity files are modified to migrate onBackPressed() overrides; SurveyViewUtils is intentionally left untouched as documented.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✨ looks great!

@aaronbrethorst aaronbrethorst merged commit 9cfaf20 into OneBusAway:main Jun 13, 2026
3 checks passed
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.

Migrate remaining onBackPressed() overrides to OnBackPressedCallback

2 participants