-
Notifications
You must be signed in to change notification settings - Fork 27
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
Android: ArrivalView, supporting formatters and updated testing #134
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b8e1633
Added ArrivalView, supporting formatters and updated testing
Archdoog 0ddd581
Merged in main
Archdoog 9d1c570
corrected ktfmt
Archdoog 7c1feb1
Set upload artifacts for snapshot test result to success & failure
Archdoog bbe7d24
Set upload artifacts for snapshot test result to success & failure
Archdoog 2d28992
Added difference setting for CI
Archdoog 86c2357
Added difference setting for CI
Archdoog 90e790a
Added difference setting for CI
Archdoog 9197064
Added difference setting for CI
Archdoog 8aeb35e
Added difference setting for CI
Archdoog 2159885
Added difference setting for CI
Archdoog f0cbdbd
Added difference setting for CI
Archdoog 9bb0dc2
Debugging snapshot testing reporting artifacts on CI
Archdoog 9c77911
Debugging snapshot testing reporting artifacts on CI
Archdoog 82a603c
Debugging snapshot testing reporting artifacts on CI
Archdoog 8fed0a7
Debugging snapshot testing reporting artifacts on CI
Archdoog 6c2a17d
Debugging snapshot testing reporting artifacts on CI
Archdoog c953668
Corrected arrival view shadow shape
Archdoog 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
This file contains 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 |
---|---|---|
|
@@ -118,6 +118,15 @@ jobs: | |
run: ./gradlew test | ||
working-directory: android | ||
|
||
- name: 'Upload Artifact' | ||
uses: actions/upload-artifact@v4 | ||
if: success() || failure() | ||
with: | ||
name: test-reports | ||
path: | | ||
android/**/build/reports | ||
retention-days: 5 | ||
|
||
verify-snapshots: | ||
|
||
runs-on: macos-13 | ||
|
@@ -157,9 +166,12 @@ jobs: | |
|
||
- name: 'Upload Artifact' | ||
uses: actions/upload-artifact@v4 | ||
if: success() || failure() | ||
with: | ||
name: paparazzi-report.html | ||
path: android/composeui/build/reports/paparazzi/debug/index.html | ||
name: snapshot-reports | ||
path: | | ||
android/**/build/reports | ||
android/**/build/paparazzi | ||
retention-days: 5 | ||
|
||
connected-check: | ||
|
@@ -203,4 +215,13 @@ jobs: | |
arch: x86 | ||
target: aosp_atd | ||
script: ./gradlew connectedCheck | ||
working-directory: android | ||
working-directory: android | ||
|
||
- name: 'Upload Artifact' | ||
uses: actions/upload-artifact@v4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
if: success() || failure() | ||
with: | ||
name: connected-reports | ||
path: | | ||
android/**/build/reports | ||
retention-days: 5 |
This file contains 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 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
22 changes: 22 additions & 0 deletions
22
...omposeui/src/main/java/com/stadiamaps/ferrostar/composeui/formatting/DateTimeFormatter.kt
This file contains 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,22 @@ | ||
package com.stadiamaps.ferrostar.composeui.formatting | ||
|
||
import android.icu.util.ULocale | ||
import java.util.Locale | ||
import kotlinx.datetime.LocalDateTime | ||
import kotlinx.datetime.toJavaLocalDateTime | ||
|
||
interface DateTimeFormatter { | ||
fun format(dateTime: LocalDateTime): String | ||
} | ||
|
||
class EstimatedArrivalDateTimeFormatter( | ||
private var localeOverride: ULocale? = null, | ||
) : DateTimeFormatter { | ||
override fun format(dateTime: LocalDateTime): String { | ||
val locale = localeOverride?.let { Locale(it.language, it.country) } ?: Locale.getDefault() | ||
val formatter = | ||
java.time.format.DateTimeFormatter.ofLocalizedTime(java.time.format.FormatStyle.SHORT) | ||
.withLocale(locale) | ||
return formatter.format(dateTime.toJavaLocalDateTime()) | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...omposeui/src/main/java/com/stadiamaps/ferrostar/composeui/formatting/DurationFormatter.kt
This file contains 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,91 @@ | ||
package com.stadiamaps.ferrostar.composeui.formatting | ||
|
||
import kotlin.time.DurationUnit | ||
|
||
enum class UnitStyle { | ||
SHORT, | ||
LONG | ||
} | ||
|
||
fun interface DurationFormatter { | ||
/** Formats a duration in seconds into a human-readable string. */ | ||
fun format(durationSeconds: Double): String | ||
} | ||
|
||
class LocalizedDurationFormatter( | ||
private val units: List<DurationUnit> = listOf(DurationUnit.HOURS, DurationUnit.MINUTES), | ||
private val unitStyle: UnitStyle = UnitStyle.SHORT | ||
) : DurationFormatter { | ||
|
||
private fun calculate(durationSeconds: Double): Map<DurationUnit, Int> { | ||
var remainingDuration = durationSeconds | ||
val result: MutableMap<DurationUnit, Int> = mutableMapOf() | ||
|
||
if (units.contains(DurationUnit.NANOSECONDS) || | ||
units.contains(DurationUnit.MICROSECONDS) || | ||
units.contains(DurationUnit.MILLISECONDS)) { | ||
throw IllegalArgumentException("Unsupported duration unit") | ||
} | ||
|
||
// Extract the days from the duration | ||
if (units.contains(DurationUnit.DAYS)) { | ||
val days = (remainingDuration / (24 * 60 * 60)).toInt() | ||
remainingDuration %= (24 * 60 * 60) | ||
result += DurationUnit.DAYS to days | ||
} | ||
|
||
// Extract the hours from the duration | ||
if (units.contains(DurationUnit.HOURS)) { | ||
val hours = (remainingDuration / (60 * 60)).toInt() | ||
remainingDuration %= (60 * 60) | ||
result += DurationUnit.HOURS to hours | ||
} | ||
|
||
// Extract the minutes from the duration | ||
if (units.contains(DurationUnit.MINUTES)) { | ||
val minutes = (remainingDuration / 60).toInt() | ||
remainingDuration %= 60 | ||
result += DurationUnit.MINUTES to minutes | ||
} | ||
|
||
// Extract the seconds from the duration | ||
if (units.contains(DurationUnit.SECONDS)) { | ||
result += DurationUnit.SECONDS to remainingDuration.toInt() | ||
} | ||
|
||
// Return a map of the non-null values and their corresponding units | ||
return result | ||
} | ||
|
||
// TODO: Localize the unit strings | ||
private fun getUnitString(unit: DurationUnit, value: Int): String { | ||
val plural = if (value != 1) "s" else "" | ||
|
||
return when (unitStyle) { | ||
UnitStyle.SHORT -> | ||
when (unit) { | ||
DurationUnit.SECONDS -> "s" | ||
DurationUnit.MINUTES -> "m" | ||
DurationUnit.HOURS -> "h" | ||
DurationUnit.DAYS -> "d" | ||
else -> "" | ||
} | ||
UnitStyle.LONG -> | ||
when (unit) { | ||
DurationUnit.SECONDS -> " second$plural" | ||
DurationUnit.MINUTES -> " minute$plural" | ||
DurationUnit.HOURS -> " hour$plural" | ||
DurationUnit.DAYS -> " day$plural" | ||
else -> " " | ||
} | ||
} | ||
} | ||
|
||
override fun format(durationSeconds: Double): String { | ||
val durationMap = calculate(durationSeconds) | ||
|
||
return durationMap.entries | ||
.filter { it.value > 0 } | ||
.joinToString(separator = " ") { "${it.value}${getUnitString(it.key, it.value)}" } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...poseui/src/main/java/com/stadiamaps/ferrostar/composeui/formatting/FormatterCollection.kt
This file contains 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,20 @@ | ||
package com.stadiamaps.ferrostar.composeui.formatting | ||
|
||
interface FormatterCollection { | ||
|
||
/** The formatter for the distance to the next step. */ | ||
val distanceFormatter: DistanceFormatter | ||
|
||
/** The formatter for the estimated arrival date and time. */ | ||
val estimatedArrivalFormatter: DateTimeFormatter | ||
|
||
/** The formatter for the remaining duration. */ | ||
val durationFormatter: DurationFormatter | ||
} | ||
|
||
/** TODO: add description and consider naming for android. */ | ||
data class StandardFormatterCollection( | ||
override val distanceFormatter: DistanceFormatter = LocalizedDistanceFormatter(), | ||
override val estimatedArrivalFormatter: DateTimeFormatter = EstimatedArrivalDateTimeFormatter(), | ||
override val durationFormatter: DurationFormatter = LocalizedDurationFormatter() | ||
) : FormatterCollection |
60 changes: 60 additions & 0 deletions
60
android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/theme/ArrivalViewTheme.kt
This file contains 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,60 @@ | ||
package com.stadiamaps.ferrostar.composeui.theme | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
|
||
enum class ArrivalViewStyle { | ||
/** A simple arrival view with only values. */ | ||
SIMPLIFIED, | ||
/** An arrival view with label captions in addition to values. */ | ||
INFORMATIONAL | ||
} | ||
|
||
/** Themes for arrival view components */ | ||
interface ArrivalViewTheme { | ||
/** The text style for the step distance (or distance to step). */ | ||
@get:Composable val style: ArrivalViewStyle | ||
/** The color for the measurement/value. */ | ||
@get:Composable val measurementColor: Color | ||
/** The text style for the measurement/value. */ | ||
@get:Composable val measurementTextStyle: TextStyle | ||
/** The color for the secondary content (label caption). */ | ||
@get:Composable val secondaryColor: Color | ||
/** The text style for the secondary content (label caption). */ | ||
@get:Composable val secondaryTextStyle: TextStyle | ||
/** The exit button icon color. */ | ||
@get:Composable val exitIconColor: Color | ||
/** The exit button background color. */ | ||
@get:Composable val exitButtonBackgroundColor: Color | ||
/** The background color for the view. */ | ||
@get:Composable val backgroundColor: Color | ||
} | ||
|
||
object DefaultArrivalViewTheme : ArrivalViewTheme { | ||
override val style: ArrivalViewStyle | ||
@Composable get() = ArrivalViewStyle.SIMPLIFIED | ||
|
||
override val measurementColor: Color | ||
@Composable get() = MaterialTheme.colorScheme.onBackground | ||
|
||
override val measurementTextStyle: TextStyle | ||
@Composable get() = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.SemiBold) | ||
|
||
override val secondaryColor: Color | ||
@Composable get() = MaterialTheme.colorScheme.secondary | ||
|
||
override val secondaryTextStyle: TextStyle | ||
@Composable get() = MaterialTheme.typography.labelSmall | ||
|
||
override val exitIconColor: Color | ||
@Composable get() = MaterialTheme.colorScheme.onSecondary | ||
|
||
override val exitButtonBackgroundColor: Color | ||
@Composable get() = MaterialTheme.colorScheme.secondary | ||
|
||
override val backgroundColor: Color | ||
@Composable get() = MaterialTheme.colorScheme.background | ||
} |
Oops, something went wrong.
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.
Ooh, interesting... I think the intent here is more closely matched by "not cancelled?" If so, I'm not quite sure why the job would be running anyways ; shouldn't cancellation stop all other jobs in the workflow? Or does GH Actions work differently? ;)