-
Notifications
You must be signed in to change notification settings - Fork 389
Replace route-row overflow with centered long-press menus #1891
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df46b00
Open route schedules from row long press
bmander e2295d1
Center and style long-press menus
bmander 8816696
Wait for centered menu dialog before asserting in long-press test
bmander 4310e63
Drive long-press test via the semantics action, not a raw gesture
bmander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...d/src/androidTest/java/org/onebusaway/android/ui/arrivals/RouteArrivalRowLongPressTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Copyright (C) 2026 Open Transit Software Foundation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.onebusaway.android.ui.arrivals | ||
|
|
||
| import androidx.compose.ui.semantics.SemanticsActions | ||
| import androidx.compose.ui.semantics.getOrNull | ||
| import androidx.compose.ui.test.SemanticsMatcher | ||
| import androidx.compose.ui.test.assertCountEquals | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onAllNodesWithContentDescription | ||
| import androidx.compose.ui.test.onAllNodesWithText | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.compose.ui.test.performSemanticsAction | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.onebusaway.android.R | ||
| import org.onebusaway.android.ui.arrivals.components.ArrivalRowCallbacks | ||
| import org.onebusaway.android.ui.arrivals.components.RouteArrivalRow | ||
| import org.onebusaway.android.ui.arrivals.components.previewArrival | ||
|
|
||
| class RouteArrivalRowLongPressTest { | ||
|
|
||
| // See EtaStripJustifyTest for why the v1 (Unconfined) rule is used here (issue #1792). | ||
| @Suppress("DEPRECATION") | ||
| @get:Rule | ||
| val composeRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun longPressOpensScheduleWithoutOverflowButton() { | ||
| val trip = previewArrival("40", "Northgate", etaMinutes = 3) | ||
| val scheduleUrl = "https://example.com/routes/40" | ||
| var openedScheduleUrl: String? = null | ||
| val callbacks = ArrivalRowCallbacks( | ||
| onRouteFavorite = {}, | ||
| onShowVehiclesOnMap = {}, | ||
| onEtaClick = {}, | ||
| onShowTripStatus = {}, | ||
| onSetReminder = {}, | ||
| onShowRouteSchedule = { openedScheduleUrl = it }, | ||
| onReportArrivalProblem = {}, | ||
| onShowAlert = {}, | ||
| ) | ||
| val actions = ArrivalActions( | ||
| tripId = trip.tripId, | ||
| routeId = trip.routeId, | ||
| routeShortName = trip.shortName.orEmpty(), | ||
| routeLongName = "Downtown Seattle", | ||
| routeColor = 0xFF0A5B3E.toInt(), | ||
| scheduleUrl = scheduleUrl, | ||
| agencyName = null, | ||
| blockId = null, | ||
| ) | ||
|
|
||
| composeRule.setContent { | ||
| RouteArrivalRow( | ||
| group = RouteRowGroup(listOf(trip)), | ||
| actionsFor = { actions }, | ||
| isFavorite = false, | ||
| callbacks = callbacks, | ||
| ) | ||
| } | ||
|
|
||
| val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
| // The route-level action moved off a dedicated overflow button and onto the row's long press, | ||
| // so the overflow affordance must be gone. | ||
| composeRule.onAllNodesWithContentDescription( | ||
| context.getString(R.string.stop_info_item_options_title) | ||
| ).assertCountEquals(0) | ||
|
|
||
| // Drive the long press through the row's OnLongClick *semantics action* rather than an injected | ||
| // longClick() gesture. combinedClickable registers the same lambda as both the gesture and the | ||
| // accessibility action, so invoking the action exercises the real wiring — but deterministically, | ||
| // without depending on the long-press timeout elapsing against the test's virtual frame clock | ||
| // (that timing was racy on the CI emulator: the hold sometimes registered as a plain tap, so the | ||
| // menu never opened). onLongClickLabel disambiguates the row's schedule action from the ETA | ||
| // pill's own trip-actions long press. | ||
| val scheduleLabel = context.getString(R.string.bus_options_menu_show_route_schedule) | ||
| composeRule.onNode( | ||
| SemanticsMatcher("has long-press action labeled \"$scheduleLabel\"") { node -> | ||
| node.config.getOrNull(SemanticsActions.OnLongClick)?.label == scheduleLabel | ||
| } | ||
| ).performSemanticsAction(SemanticsActions.OnLongClick) | ||
|
|
||
| // The centered menu opens in a Dialog (a separate window); on slower devices (e.g. the CI | ||
| // emulator) the main composition can report idle a frame before that window is laid out, so | ||
| // wait for the schedule item to appear before acting on it rather than asserting immediately. | ||
| composeRule.waitUntil(timeoutMillis = 5_000) { | ||
| composeRule.onAllNodesWithText(scheduleLabel).fetchSemanticsNodes().isNotEmpty() | ||
| } | ||
| composeRule.onNodeWithText(scheduleLabel).performClick() | ||
|
|
||
| assertEquals(scheduleUrl, openedScheduleUrl) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...droid/src/main/java/org/onebusaway/android/ui/compose/components/CenteredLongPressMenu.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (C) 2026 Open Transit Software Foundation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.onebusaway.android.ui.compose.components | ||
|
|
||
| import androidx.compose.foundation.BorderStroke | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.ColumnScope | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.widthIn | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.window.Dialog | ||
|
|
||
| /** | ||
| * A secondary-action menu opened by long press. A dialog supplies one consistent screen-centered | ||
| * position regardless of which row or horizontally scrolled ETA pill launched it; the content stays | ||
| * ordinary Material [androidx.compose.material3.DropdownMenuItem] rows. | ||
| */ | ||
| @Composable | ||
| internal fun CenteredLongPressMenu( | ||
| expanded: Boolean, | ||
| onDismissRequest: () -> Unit, | ||
| content: @Composable ColumnScope.() -> Unit, | ||
| ) { | ||
| if (!expanded) return | ||
| Dialog(onDismissRequest = onDismissRequest) { | ||
| Surface( | ||
| modifier = Modifier.widthIn(min = 196.dp, max = 320.dp), | ||
| shape = MaterialTheme.shapes.large, | ||
| color = MaterialTheme.colorScheme.surfaceContainer, | ||
| border = BorderStroke(1.dp, MaterialTheme.colorScheme.outline), | ||
| tonalElevation = 3.dp, | ||
| shadowElevation = 8.dp, | ||
| ) { | ||
| Column(Modifier.padding(vertical = 8.dp), content = content) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: OneBusAway/onebusaway-android
Length of output: 15365
🏁 Script executed:
Repository: OneBusAway/onebusaway-android
Length of output: 20852
Document this suppression or remove it.
@Suppress("DEPRECATION")needs the required one-line rationale and tracking issue link here, matching the nearby Compose tests; otherwise it violates the Kotlin warning policy.🤖 Prompt for AI Agents
Source: Coding guidelines