Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ dependencies {
implementation(libs.kotlin.stdlib)

testImplementation(libs.junit)
testImplementation(libs.androidx.car.app.testing)

androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
androidTestImplementation(libs.androidx.car.app.testing)
debugImplementation(platform(libs.androidx.compose.bom))
debugImplementation(libs.androidx.compose.ui.test.manifest)

Expand All @@ -54,6 +56,7 @@ dependencies {
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material.icons)
implementation(libs.androidx.car.app)
implementation('com.google.android.gms:play-services-oss-licenses:17.5.1')
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package `in`.izyum.bart.presentation

import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import `in`.izyum.bart.model.Departure
import `in`.izyum.bart.model.Line
import `in`.izyum.bart.model.Station
import `in`.izyum.bart.model.TripLeg
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class DepartureTextFormatterTest {

@Test
fun countdownFormatsMinutesAndSecondsUnderOneHour() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val now = 1_000_000L
val minEstimate = now + (15 * 60 + 30) * 1000L
val maxEstimate = minEstimate

val departure = createDeparture(minEstimate, maxEstimate)
val result = DepartureTextFormatter.countdown(context, departure, now)

assertEquals("15m 30s", result)
}

@Test
fun countdownFormatsHoursMinutesAndSecondsOverOneHour() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val now = 1_000_000L
// 1 hour 52 minutes 0 seconds = 6720 seconds = 6,720,000 ms
val minEstimate = now + (1 * 3600 + 52 * 60 + 0) * 1000L
val maxEstimate = minEstimate

val departure = createDeparture(minEstimate, maxEstimate)
val result = DepartureTextFormatter.countdown(context, departure, now)

assertEquals("1h 52m 0s", result)
}

@Test
fun countdownFormatsExactlyOneHour() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val now = 1_000_000L
// 1 hour = 3600 seconds = 3,600,000 ms
val minEstimate = now + 3600 * 1000L
val maxEstimate = minEstimate

val departure = createDeparture(minEstimate, maxEstimate)
val result = DepartureTextFormatter.countdown(context, departure, now)

assertEquals("1h 0m 0s", result)
}

private fun createDeparture(minEstimate: Long, maxEstimate: Long): Departure =
Departure.builder()
.setOrigin(Station.CAST)
.setTrainDestination(Station.MLPT)
.setPassengerDestination(Station.MLPT)
.setLine(Line.ORANGE)
.setDirection("north")
.setPlatform("1")
.setListedInETDs(true)
.setMinEstimate(minEstimate)
.setMaxEstimate(maxEstimate)
.setTripLegs(listOf(TripLeg(
Line.ORANGE, Station.CAST, Station.MLPT, Station.MLPT,
"trip-1", minEstimate, maxEstimate, emptyList(),
))).build()
}
83 changes: 83 additions & 0 deletions app/src/androidTest/kotlin/in/izyum/bart/ui/BartRunnerUiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,89 @@ class BartRunnerUiTest {
composeRule.onNodeWithText("Set departure alarm").assertIsDisplayed()
}

@Test
fun followedTripCardOnHomeScreenOpensFullScreenView() {
val departure = testDeparture()
setTestContent {
BartRunnerTheme {
HomeScreen(
state = RoutesUiState(isLoading = false),
followedTrip = departure,
timeSource = timeSource,
onRouteSelected = {},
onAddFavorite = {},
onRemoveFavorite = {},
onMoveFavorite = { _, _ -> },
onInsertFavorite = { _, _ -> },
onViewTrip = {},
onViewMap = {},
)
}
}

composeRule.onNodeWithContentDescription("Full screen").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Full screen").performClick()
composeRule.onNodeWithContentDescription("Exit full screen").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Keep screen active").assertIsDisplayed()
composeRule.onAllNodesWithText("Castro Valley → Milpitas").onFirst().assertIsDisplayed()
}

@Test
fun homeScreenSettingsIncludesHomeStationOption() {
setTestContent {
BartRunnerTheme {
HomeScreen(
state = RoutesUiState(isLoading = false),
followedTrip = null,
timeSource = timeSource,
onRouteSelected = {},
onAddFavorite = {},
onRemoveFavorite = {},
onMoveFavorite = { _, _ -> },
onInsertFavorite = { _, _ -> },
onViewTrip = {},
onViewMap = {},
)
}
}

composeRule.onNodeWithContentDescription("More options").performClick()
composeRule.onNodeWithText("Settings").performClick()
composeRule.onNodeWithText("Home station").assertIsDisplayed()
composeRule.onNodeWithText("Keep screen active").assertIsDisplayed()
}

@Test
fun tripScreenHeroShowsFullScreenButtonWhenFollowing() {
val departure = testDeparture()
setTestContent {
BartRunnerTheme {
TripScreen(
departure = departure,
route = `in`.izyum.bart.model.StationPair(Station.CAST, Station.MLPT),
isFollowingInitially = true,
alarmVisible = false,
timeSource = timeSource,
alarmPending = false,
alarmLeadTimeMinutes = 0,
onBack = {},
onFollow = {},
onSetAlarm = {},
onCancelAlarm = {},
onClear = {},
onShare = {},
onSilenceAlarm = {},
)
}
}

composeRule.onNodeWithContentDescription("Full screen").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Full screen").performClick()
composeRule.onNodeWithContentDescription("Exit full screen").assertIsDisplayed()
composeRule.onNodeWithContentDescription("Exit full screen").performClick()
composeRule.onNodeWithContentDescription("Exit full screen").assertDoesNotExist()
}

@Test
fun systemMapExposesZoomControls() {
setTestContent {
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-feature
android:name="android.hardware.type.automotive"
android:required="false" />
<uses-feature
android:name="android.software.car.expressive_app"
android:required="false" />

<application
android:name=".BartRunnerApplication"
Expand Down Expand Up @@ -56,6 +64,28 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<!-- Android Auto / Cars App Library Configuration -->
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<meta-data
android:name="androidx.car.app.minCarApiLevel"
android:value="1" />
<meta-data
android:name="androidx.car.app.category"
android:value="poi" />

<service
android:name=".car.BartCarAppService"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
<category android:name="androidx.car.app.category.POI" />
</intent-filter>
</service>
</application>

</manifest>
4 changes: 2 additions & 2 deletions app/src/main/kotlin/in/izyum/bart/BartRunnerApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class BartRunnerApplication : Application() {

override fun onActivityStarted(activity: Activity) {
startedActivityCount++
transitRepository.setAppInForeground(true)
transitRepository.setAppInForeground(inForeground = true)
}

override fun onActivityStopped(activity: Activity) {
startedActivityCount = (startedActivityCount - 1).coerceAtLeast(0)
if (startedActivityCount == 0) {
transitRepository.setAppInForeground(false)
transitRepository.setAppInForeground(inForeground = false)
}
}

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/kotlin/in/izyum/bart/activities/AboutActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package `in`.izyum.bart.activities

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Build
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.net.toUri
import `in`.izyum.bart.BuildConfig
import `in`.izyum.bart.R
import `in`.izyum.bart.ui.AboutScreen
Expand All @@ -25,16 +25,16 @@ class AboutActivity : ComponentActivity() {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(getString(R.string.github_url)),
)
getString(R.string.github_url).toUri(),
),
)
},
onOpenApacheLicense = {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(getString(R.string.apache_license_url)),
)
getString(R.string.apache_license_url).toUri(),
),
)
},
onOpenLicenses = {
Expand Down
Loading