fix(android): compact sort & filter sheet and a clean date-range dialog

Sort & filter scrolled: four machine radio rows (a rare choice) led the
sheet, every status and sort option was its own 56dp radio row, and Done
sat in a footer. The activity-date dialog was a full-width custom Dialog
that clipped the picker title, and its range band was Material's baseline
purple next to green endpoints.

- The sheet is now single rows under Filter / Sort: Machines, Show and
  Sort by show their value and open an anchored menu (checkmark for the
  selection, machine session counts trailing); Activity dates opens the
  picker; Unread only and Active first stay switches. Reset and Done move
  into the header, so the whole sheet fits without scrolling (as on iOS,
  where machines moved into a submenu).
- The date range picker sits in Material's DatePickerDialog (standard
  width and margins), drops the title row, aligns the range headline with
  the 24dp content edge instead of M3's 64dp full-screen indent, keeps the
  recent-activity legend under the calendar, and omits the current year
  from legend days.
- The static light/dark schemes now define every accent role (primary,
  secondary, tertiary containers and their on-colors) from the green
  seed; unset roles were falling back to Material's purple.
- A window-level specimen covers the sheet, the machine menu and the
  picker; instrumentation tests open the Machines / Show menus first.
This commit is contained in:
weishu
2026-11-13 18:00:58 +08:00
parent 35e4578245
commit a7fe2cdaf2
10 changed files with 381 additions and 160 deletions
@@ -81,7 +81,8 @@ class HomeFilterWindowTest {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val viewModel = SessionListViewModel(HomeSessions(), HomeMachines(), LastSeenStore(scope), scope)
val today = LocalDate.now().toEpochDay()
val laptop = "${context.getString(R.string.sessions_machine_fallback, "laptop")} · 2"
// The machine row's value; choices live in its menu (count is a trailing label).
val laptop = context.getString(R.string.sessions_machine_fallback, "laptop")
val scenario = ActivityScenario.launch(ComponentActivity::class.java)
try {
scenario.onActivity { activity ->
@@ -99,6 +100,7 @@ class HomeFilterWindowTest {
}
await("initial sessions") { viewModel.uiState.value.rows.size == 3 }
click(R.string.sessions_filters)
click(R.string.sessions_filter_machines)
click(laptop)
await("machine filter") { viewModel.uiState.value.activeMachineFilter == "laptop" }
await("sheet remains open") { visible(laptop) }
@@ -216,7 +216,8 @@ class HomeScreenTest {
sessions.sessions.value = sessions.sessions.value.map { if (it.id == "research") it.copy(active = false) else it }
mount()
openFilters()
compose.onNodeWithTag("session-filters").performScrollToNode(hasText(label(R.string.sessions_view_status_archived)))
// "Show" is one row whose value opens a menu of statuses.
compose.onNodeWithTag("session-status-filter").performClick()
compose.onNodeWithText(label(R.string.sessions_view_status_archived)).performClick()
compose.waitUntil(10_000) { viewModel.uiState.value.rows.map { it.id } == listOf("research") }
compose.onNodeWithTag("session-filters").performScrollToNode(hasTestTag("session-active-first"))
@@ -4,27 +4,27 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.DatePickerDefaults
import androidx.compose.material3.DatePickerDialog
import androidx.compose.material3.DateRangePicker
import androidx.compose.material3.DateRangePickerDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberDateRangePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import app.hapi.companion.R
import java.time.LocalDate
import java.time.ZoneId
@@ -73,64 +73,66 @@ internal fun SessionDateRangePickerDialog(
initialDisplayedMonthMillis = initialMonthEpochDay * MILLIS_PER_DAY,
)
val hasSelection = pickerState.selectedStartDateMillis != null
val dateFormatter = remember { DatePickerDefaults.dateFormatter() }
Dialog(onDismissRequest = onDismiss, properties = DialogProperties(usePlatformDefaultWidth = false)) {
Surface(
shape = MaterialTheme.shapes.extraLarge,
tonalElevation = 6.dp,
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 640.dp),
) {
Column {
DateRangePicker(
state = pickerState,
title = {
Text(
text = stringResource(R.string.sessions_time_filter_label),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
// The M3 dialog container: standard width, margins and corner radius; a
// full-width custom Dialog clipped the picker title.
DatePickerDialog(
onDismissRequest = onDismiss,
confirmButton = {
TextButton(
onClick = {
val start = pickerState.selectedStartDateMillis ?: return@TextButton
val end = pickerState.selectedEndDateMillis ?: return@TextButton
onApply(start / MILLIS_PER_DAY, end / MILLIS_PER_DAY)
},
enabled = pickerState.selectedStartDateMillis != null &&
pickerState.selectedEndDateMillis != null,
) {
Text(stringResource(R.string.sessions_time_filter_apply))
}
},
dismissButton = {
Row {
// Web footer `Clear`: resets the in-progress selection and the
// active filter without closing the picker.
TextButton(
onClick = {
pickerState.setSelection(null, null)
onClear()
},
showModeToggle = false,
modifier = Modifier.weight(1f),
)
ActivityDayLegend(activityEpochDays)
HorizontalDivider()
Row(
modifier = Modifier
.fillMaxWidth()
.padding(end = 8.dp),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
enabled = hasSelection || current != null,
) {
// Web footer `Clear`: resets the in-progress selection and the
// active filter without closing the picker.
TextButton(
onClick = {
pickerState.setSelection(null, null)
onClear()
},
enabled = hasSelection || current != null,
) {
Text(stringResource(R.string.sessions_time_filter_clear))
}
TextButton(onClick = onDismiss) {
Text(stringResource(R.string.home_cancel))
}
TextButton(
onClick = {
val start = pickerState.selectedStartDateMillis ?: return@TextButton
val end = pickerState.selectedEndDateMillis ?: return@TextButton
onApply(start / MILLIS_PER_DAY, end / MILLIS_PER_DAY)
},
enabled = pickerState.selectedStartDateMillis != null &&
pickerState.selectedEndDateMillis != null,
) {
Text(stringResource(R.string.sessions_time_filter_apply))
}
Text(stringResource(R.string.sessions_time_filter_clear))
}
TextButton(onClick = onDismiss) {
Text(stringResource(R.string.home_cancel))
}
}
},
) {
// DatePickerDialog stacks its content in a Box; give the picker and the
// legend their own column so the legend sits under the calendar.
Column(Modifier.weight(1f)) {
DateRangePicker(
state = pickerState,
// No title row: the selected range is the headline, aligned with
// the dialog's 24dp content edge (the M3 default indents it 64dp
// for the full-screen close button this dialog does not have).
title = null,
headline = {
DateRangePickerDefaults.DateRangePickerHeadline(
selectedStartDateMillis = pickerState.selectedStartDateMillis,
selectedEndDateMillis = pickerState.selectedEndDateMillis,
displayMode = pickerState.displayMode,
dateFormatter = dateFormatter,
modifier = Modifier.padding(start = 24.dp, end = 12.dp, top = 24.dp, bottom = 12.dp),
)
},
showModeToggle = false,
modifier = Modifier.weight(1f),
)
ActivityDayLegend(activityEpochDays)
}
}
}
@@ -146,7 +148,6 @@ internal fun SessionDateRangePickerDialog(
private fun ActivityDayLegend(activityEpochDays: Set<Long>) {
if (activityEpochDays.isEmpty()) return
val recentDays = activityEpochDays.sortedDescending().take(LEGEND_DAY_CAP)
val formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(JavaLocale.getDefault())
Row(
modifier = Modifier
.fillMaxWidth()
@@ -171,7 +172,7 @@ private fun ActivityDayLegend(activityEpochDays: Set<Long>) {
shape = RoundedCornerShape(6.dp),
) {
Text(
text = LocalDate.ofEpochDay(epochDay).format(formatter),
text = formatLegendDay(epochDay),
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp),
@@ -182,6 +183,15 @@ private fun ActivityDayLegend(activityEpochDays: Set<Long>) {
}
}
/** Recent days rarely span years: drop the year when it is the current one. */
private fun formatLegendDay(epochDay: Long): String {
val date = LocalDate.ofEpochDay(epochDay)
val locale = JavaLocale.getDefault()
if (date.year != LocalDate.now(ZoneId.systemDefault()).year) return formatEpochDayLocalized(epochDay)
val pattern = android.text.format.DateFormat.getBestDateTimePattern(locale, "MMMd")
return date.format(DateTimeFormatter.ofPattern(pattern, locale))
}
/** Locale-aware day label for the filter sheet (machine `YYYY-MM-DD` stays in [SessionDateRangeFilter]). */
internal fun formatEpochDayLocalized(epochDay: Long): String =
LocalDate.ofEpochDay(epochDay)
@@ -3,23 +3,29 @@ package app.hapi.companion.feature.sessions
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material3.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import app.hapi.companion.R
import app.hapi.companion.ui.theme.hapi
import app.hapi.protocol.wire.SessionListSort
import kotlinx.coroutines.launch
@@ -31,9 +37,11 @@ internal fun machineFilterLabel(filter: MachineFilterUi): String = when {
}
/**
* One sheet for every list view choice (web "Sort and filter"): the machine /
* date / status / unread filters (transient), then sort key and Active first
* (persisted). Choices apply immediately; Reset clears filters only.
* One compact sheet for every list view choice (web "Sort and filter", iOS
* filter menu): each multi-way choice is a single "label … value ▾" row that
* opens a menu, booleans are switches, so the whole sheet fits without
* scrolling. Filters (machine, dates, status, unread) are transient; sort and
* Active first persist. Choices apply immediately; Reset clears filters only.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -56,7 +64,7 @@ internal fun SessionFilterSheet(
sheetState = sheetState,
) {
Row(
Modifier.fillMaxWidth().padding(start = 16.dp, end = 8.dp),
Modifier.fillMaxWidth().padding(start = 24.dp, end = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
@@ -67,91 +75,87 @@ internal fun SessionFilterSheet(
TextButton(onClick = onReset, enabled = state.hasActiveFilters) {
Text(stringResource(R.string.sessions_filters_reset))
}
TextButton(onClick = { scope.launch { sheetState.hide(); onDismiss() } }) {
Text(stringResource(R.string.sessions_filters_done))
}
}
LazyColumn(
Modifier.fillMaxWidth().weight(1f, fill = false).heightIn(max = 480.dp)
.testTag("session-filters"),
Modifier.fillMaxWidth().padding(top = 4.dp, bottom = 16.dp).testTag("session-filters"),
) {
item("filter-title") { SectionTitle(stringResource(R.string.sessions_filter_section)) }
if (state.hasMachineFilters) {
item("machines-title") {
Text(
stringResource(R.string.sessions_filter_machines),
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
item("machines") {
Column(Modifier.selectableGroup()) {
FilterOption(stringResource(R.string.sessions_filter_all), state.activeMachineFilter == null) { onSelectMachine(null) }
val selected = state.machineFilters.firstOrNull { it.id == state.activeMachineFilter }
ChoiceRow(
label = stringResource(R.string.sessions_filter_machines),
value = selected?.let { machineFilterLabel(it) } ?: stringResource(R.string.sessions_filter_all),
tag = "session-machine-filter",
) { close ->
MenuChoice(stringResource(R.string.sessions_filter_all), selected == null) {
close(); onSelectMachine(null)
}
HorizontalDivider()
state.machineFilters.forEach { filter ->
FilterOption("${machineFilterLabel(filter)} · ${filter.sessionCount}", state.activeMachineFilter == filter.id) {
onSelectMachine(filter.id)
}
MenuChoice(
machineFilterLabel(filter), filter.id == state.activeMachineFilter,
trailing = filter.sessionCount.toString(),
) { close(); onSelectMachine(filter.id) }
}
}
}
item("divider") { HorizontalDivider(Modifier.padding(vertical = 8.dp)) }
}
item("dates") {
val range = state.dateRange
ListItem(
headlineContent = { Text(stringResource(R.string.sessions_filter_dates)) },
supportingContent = {
Text(
if (range == null) stringResource(R.string.sessions_filter_any_date)
else stringResource(
R.string.sessions_time_filter_summary,
formatEpochDayLocalized(range.startEpochDay),
formatEpochDayLocalized(range.endEpochDay),
),
)
},
leadingContent = { Icon(painterResource(R.drawable.ic_calendar), contentDescription = null) },
trailingContent = {
if (range != null) {
IconButton(onClick = onClearDates, modifier = Modifier.size(48.dp)) {
Icon(Icons.Default.Close, stringResource(R.string.sessions_filter_clear_dates))
}
}
},
modifier = Modifier.clickable {
SettingRow(
label = stringResource(R.string.sessions_filter_dates),
onClick = {
// Finish the sheet transition before opening another window.
scope.launch {
sheetState.hide()
onOpenDates()
}
}.testTag("session-date-filter"),
)
},
tag = "session-date-filter",
) {
ValueText(
if (range == null) stringResource(R.string.sessions_filter_any_date)
else stringResource(
R.string.sessions_time_filter_summary,
formatEpochDayLocalized(range.startEpochDay),
formatEpochDayLocalized(range.endEpochDay),
),
active = range != null,
)
if (range != null) {
IconButton(onClick = onClearDates, modifier = Modifier.size(40.dp)) {
Icon(
painterResource(R.drawable.ic_sym_close),
stringResource(R.string.sessions_filter_clear_dates),
modifier = Modifier.size(18.dp),
)
}
} else {
Chevron(opensDialog = true)
}
}
}
// Filters first (machines and dates keep their place), then the
// rarely changed ordering at the bottom.
item("status-divider") { HorizontalDivider(Modifier.padding(vertical = 8.dp)) }
item("status-title") { SectionTitle(stringResource(R.string.sessions_view_status)) }
item("status") {
Column(Modifier.selectableGroup()) {
FilterOption(stringResource(R.string.sessions_view_status_all), state.statusFilter == SessionListStatus.All) {
onSelectStatus(SessionListStatus.All)
}
FilterOption(stringResource(R.string.sessions_view_status_active), state.statusFilter == SessionListStatus.Active) {
onSelectStatus(SessionListStatus.Active)
}
FilterOption(stringResource(R.string.sessions_view_status_archived), state.statusFilter == SessionListStatus.Archived) {
onSelectStatus(SessionListStatus.Archived)
val statusLabel = statusLabel(state.statusFilter)
ChoiceRow(stringResource(R.string.sessions_view_status), statusLabel, "session-status-filter") { close ->
SessionListStatus.entries.forEach { status ->
MenuChoice(statusLabel(status), status == state.statusFilter) { close(); onSelectStatus(status) }
}
}
}
item("unread-only") {
SwitchOption(stringResource(R.string.sessions_view_unread_only), state.unreadOnly, onSetUnreadOnly, "session-unread-only")
}
item("sort-divider") { HorizontalDivider(Modifier.padding(vertical = 8.dp)) }
item("sort-title") { SectionTitle(stringResource(R.string.sessions_view_sort)) }
item("sort-title") { SectionTitle(stringResource(R.string.sessions_sort_section)) }
item("sort") {
Column(Modifier.selectableGroup()) {
FilterOption(stringResource(R.string.sessions_view_sort_last_message), state.order.sort == SessionListSort.LastMessage) {
onSelectSort(SessionListSort.LastMessage)
}
FilterOption(stringResource(R.string.sessions_view_sort_created), state.order.sort == SessionListSort.Created) {
onSelectSort(SessionListSort.Created)
val sortLabel = sortLabel(state.order.sort)
ChoiceRow(stringResource(R.string.sessions_view_sort), sortLabel, "session-sort") { close ->
SessionListSort.entries.forEach { sort ->
MenuChoice(sortLabel(sort), sort == state.order.sort) { close(); onSelectSort(sort) }
}
}
}
@@ -159,21 +163,119 @@ internal fun SessionFilterSheet(
SwitchOption(stringResource(R.string.sessions_view_active_first), state.order.activeFirst, onSetActiveFirst, "session-active-first")
}
}
Button(
onClick = { scope.launch { sheetState.hide(); onDismiss() } },
modifier = Modifier.fillMaxWidth().padding(16.dp),
) {
Text(stringResource(R.string.sessions_filters_done))
}
}
}
@Composable
private fun statusLabel(status: SessionListStatus): String = stringResource(
when (status) {
SessionListStatus.All -> R.string.sessions_view_status_all
SessionListStatus.Active -> R.string.sessions_view_status_active
SessionListStatus.Archived -> R.string.sessions_view_status_archived
},
)
@Composable
private fun sortLabel(sort: SessionListSort): String = stringResource(
when (sort) {
SessionListSort.LastMessage -> R.string.sessions_view_sort_last_message
SessionListSort.Created -> R.string.sessions_view_sort_created
},
)
@Composable
private fun SectionTitle(text: String) {
Text(
text,
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.hapi.textSecondary,
modifier = Modifier.padding(start = 24.dp, end = 24.dp, top = 12.dp, bottom = 4.dp),
)
}
/** One 56dp row: label on the left, [trailing] (value, chevron, switch) on the right. */
@Composable
private fun SettingRow(
label: String,
onClick: () -> Unit,
tag: String,
modifier: Modifier = Modifier,
trailing: @Composable RowScope.() -> Unit,
) {
Row(
modifier.fillMaxWidth().clickable(role = Role.Button, onClick = onClick)
.heightIn(min = 56.dp).padding(start = 24.dp, end = 16.dp).testTag(tag),
verticalAlignment = Alignment.CenterVertically,
) {
Text(label, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f).padding(end = 16.dp))
trailing()
}
}
@Composable
private fun ValueText(text: String, active: Boolean = false) {
Text(
text,
style = MaterialTheme.typography.bodyMedium,
color = if (active) MaterialTheme.colorScheme.primary else MaterialTheme.hapi.textSecondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.End,
modifier = Modifier.widthIn(max = 200.dp),
)
}
@Composable
private fun Chevron(expanded: Boolean = false, opensDialog: Boolean = false) {
Icon(
painterResource(if (opensDialog) R.drawable.ic_sym_chevron_right else R.drawable.ic_sym_expand_more),
contentDescription = null,
tint = MaterialTheme.hapi.textSecondary,
modifier = Modifier.padding(start = 4.dp).size(20.dp).rotate(if (expanded) 180f else 0f),
)
}
/** A [SettingRow] whose value opens an anchored menu of [options]; pass `close` before acting. */
@Composable
private fun ChoiceRow(
label: String,
value: String,
tag: String,
options: @Composable ColumnScope.(close: () -> Unit) -> Unit,
) {
var open by remember { mutableStateOf(false) }
Box {
SettingRow(label, onClick = { open = true }, tag = tag) {
ValueText(value)
Chevron(open)
}
// Anchored under the row's trailing edge, where the value sits.
Box(Modifier.align(Alignment.BottomEnd).padding(end = 16.dp)) {
DropdownMenu(
expanded = open,
onDismissRequest = { open = false },
shape = RoundedCornerShape(12.dp),
) { options { open = false } }
}
}
}
@Composable
private fun MenuChoice(label: String, selected: Boolean, trailing: String? = null, onClick: () -> Unit) {
DropdownMenuItem(
text = { Text(label, maxLines = 1, overflow = TextOverflow.Ellipsis) },
onClick = onClick,
leadingIcon = {
Box(Modifier.size(20.dp)) {
if (selected) Icon(painterResource(R.drawable.ic_sym_check), contentDescription = null, modifier = Modifier.size(20.dp))
}
},
trailingIcon = trailing?.let {
{ Text(it, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.hapi.textSecondary) }
},
modifier = Modifier
.widthIn(min = 200.dp)
.semantics { this.selected = selected },
)
}
@@ -181,22 +283,10 @@ private fun SectionTitle(text: String) {
private fun SwitchOption(label: String, checked: Boolean, onCheckedChange: (Boolean) -> Unit, tag: String) {
Row(
Modifier.fillMaxWidth().toggleable(checked, role = Role.Switch, onValueChange = onCheckedChange)
.heightIn(min = 56.dp).padding(horizontal = 16.dp, vertical = 8.dp).testTag(tag),
.heightIn(min = 56.dp).padding(start = 24.dp, end = 16.dp).testTag(tag),
verticalAlignment = Alignment.CenterVertically,
) {
Text(label, modifier = Modifier.weight(1f))
Text(label, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f))
Switch(checked = checked, onCheckedChange = null)
}
}
@Composable
private fun FilterOption(label: String, selected: Boolean, select: () -> Unit) {
Row(
Modifier.fillMaxWidth().selectable(selected, role = Role.RadioButton, onClick = select)
.heightIn(min = 56.dp).padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
RadioButton(selected = selected, onClick = null)
Text(label, modifier = Modifier.padding(start = 12.dp))
}
}
@@ -65,18 +65,40 @@ private fun ColorScheme.withNeutralSurfaces(dark: Boolean): ColorScheme = if (da
)
}
// Full accent role sets for the green seed (Material theme builder). Unset
// roles would fall back to Material's baseline purple: date-range bands
// (secondaryContainer), tonal buttons and chips all read those containers.
private val LightColorScheme = lightColorScheme(
primary = Color(0xFF3D6837),
onPrimary = Color(0xFFFFFFFF),
primaryContainer = Color(0xFFBEF0B1),
onPrimaryContainer = Color(0xFF002201),
inversePrimary = Color(0xFFA3D397),
secondary = Color(0xFF54634D),
onSecondary = Color(0xFFFFFFFF),
secondaryContainer = Color(0xFFD7E8CD),
onSecondaryContainer = Color(0xFF121F0E),
tertiary = Color(0xFF386569),
onTertiary = Color(0xFFFFFFFF),
tertiaryContainer = Color(0xFFBCEBEE),
onTertiaryContainer = Color(0xFF002022),
).withNeutralSurfaces(dark = false)
private val DarkColorScheme = darkColorScheme(
primary = Color(0xFFA3D397),
// Material's baseline onPrimary is purple; ink on the light-green accent.
// Ink on the light-green accent.
onPrimary = Color(0xFF0F1115),
primaryContainer = Color(0xFF25501F),
onPrimaryContainer = Color(0xFFBEF0B1),
inversePrimary = Color(0xFF3D6837),
secondary = Color(0xFFBCCBB2),
onSecondary = Color(0xFF263422),
secondaryContainer = Color(0xFF3C4B37),
onSecondaryContainer = Color(0xFFD7E8CD),
tertiary = Color(0xFFA0CFD2),
onTertiary = Color(0xFF00373A),
tertiaryContainer = Color(0xFF1F4D51),
onTertiaryContainer = Color(0xFFBCEBEE),
).withNeutralSurfaces(dark = true)
/**
@@ -726,13 +726,14 @@
<string name="sessions_filters">Сортировка и фильтр</string>
<string name="sessions_filters_active">Фильтры применены</string>
<string name="sessions_filters_reset">Сбросить</string>
<string name="sessions_filter_section">Фильтр</string>
<string name="sessions_sort_section">Сортировка</string>
<string name="sessions_filters_done">Готово</string>
<string name="sessions_filter_machines">Машины</string>
<string name="sessions_filter_dates">Даты активности</string>
<string name="sessions_filter_any_date">Любая дата</string>
<string name="sessions_filter_clear_dates">Сбросить фильтр по дате</string>
<string name="sessions_machine_fallback">Машина · %1$s</string>
<string name="sessions_time_filter_label">Фильтр сессий по последней активности</string>
<string name="sessions_time_filter_apply">Применить</string>
<string name="sessions_time_filter_clear">Очистить</string>
<string name="sessions_time_filter_summary">%1$s – %2$s</string>
@@ -712,13 +712,14 @@
<string name="sessions_filters">排序与筛选</string>
<string name="sessions_filters_active">已应用筛选</string>
<string name="sessions_filters_reset">重置</string>
<string name="sessions_filter_section">筛选</string>
<string name="sessions_sort_section">排序</string>
<string name="sessions_filters_done">完成</string>
<string name="sessions_filter_machines">机器</string>
<string name="sessions_filter_dates">活动日期</string>
<string name="sessions_filter_any_date">不限日期</string>
<string name="sessions_filter_clear_dates">清除日期筛选</string>
<string name="sessions_machine_fallback">机器 · %1$s</string>
<string name="sessions_time_filter_label">按最后活动时间筛选会话</string>
<string name="sessions_time_filter_apply">应用</string>
<string name="sessions_time_filter_clear">清除</string>
<string name="sessions_time_filter_summary">%1$s – %2$s</string>
+2 -1
View File
@@ -712,13 +712,14 @@
<string name="sessions_filters">Sort &amp; filter</string>
<string name="sessions_filters_active">Filters applied</string>
<string name="sessions_filters_reset">Reset</string>
<string name="sessions_filter_section">Filter</string>
<string name="sessions_sort_section">Sort</string>
<string name="sessions_filters_done">Done</string>
<string name="sessions_filter_machines">Machines</string>
<string name="sessions_filter_dates">Activity dates</string>
<string name="sessions_filter_any_date">Any date</string>
<string name="sessions_filter_clear_dates">Clear date filter</string>
<string name="sessions_machine_fallback">Machine · %1$s</string>
<string name="sessions_time_filter_label">Filter sessions by last activity</string>
<string name="sessions_time_filter_apply">Apply</string>
<string name="sessions_time_filter_clear">Clear</string>
<string name="sessions_time_filter_summary">%1$s – %2$s</string>
@@ -0,0 +1,90 @@
package app.hapi.companion.specimens
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import app.hapi.companion.feature.sessions.MachineFilterUi
import app.hapi.companion.feature.sessions.SessionDateRange
import app.hapi.companion.feature.sessions.SessionDateRangePickerDialog
import app.hapi.companion.feature.sessions.SessionFilterSheet
import app.hapi.companion.feature.sessions.SessionListUiState
import app.hapi.companion.ui.theme.HapiTheme
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.captureScreenRoboImage
import java.time.LocalDate
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
/** Window-level specimens (bottom sheet, dialog) at a phone size, captured with their scrim. */
@OptIn(ExperimentalRoborazziApi::class)
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(sdk = [35], qualifiers = "w411dp-h890dp-xxhdpi")
class SessionFilterSpecimenTest {
@get:Rule val compose = createComposeRule()
private val today = LocalDate.of(2026, 11, 13).toEpochDay()
private fun state(dateRange: SessionDateRange? = null) = SessionListUiState(
rows = emptyList(),
machineFilters = listOf(
MachineFilterUi("m1", "debian", 1751),
MachineFilterUi("m2", "mac", 930),
MachineFilterUi("m3", "529e6566", 164, unnamed = true),
MachineFilterUi("m4", "b459b4ee", 78, unnamed = true),
),
activeMachineFilter = null,
isRefreshing = false,
hasLoaded = true,
isOffline = false,
dateRange = dateRange,
dateActivityEpochDays = (0L..20L step 2).map { today - it }.toSet(),
)
@Test fun filterSheetDark() = sheet(dark = true)
@Test fun filterSheetLight() = sheet(dark = false)
@Test fun machineMenuDark() = sheet(dark = true, openMachines = true)
@Test fun datePickerDark() = dates(dark = true)
@Test fun datePickerLight() = dates(dark = false)
private fun sheet(dark: Boolean, openMachines: Boolean = false) {
compose.setContent {
HapiTheme(darkTheme = dark, dynamicColor = false) {
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {}
SessionFilterSheet(
state = state(),
onSelectSort = {}, onSetActiveFirst = {}, onSelectStatus = {}, onSetUnreadOnly = {},
onSelectMachine = {}, onOpenDates = {}, onClearDates = {}, onReset = {}, onDismiss = {},
)
}
}
compose.waitForIdle()
if (openMachines) compose.onNodeWithTag("session-machine-filter").performClick()
compose.waitForIdle()
val name = if (openMachines) "machine-menu" else "filter-sheet"
captureScreenRoboImage("build/outputs/roborazzi/specimens/$name-${if (dark) "dark" else "light"}.png")
}
private fun dates(dark: Boolean) {
compose.setContent {
HapiTheme(darkTheme = dark, dynamicColor = false) {
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {}
SessionDateRangePickerDialog(
current = SessionDateRange(today - 6, today),
activityEpochDays = state().dateActivityEpochDays,
onApply = { _, _ -> }, onClear = {}, onDismiss = {},
)
}
}
compose.waitForIdle()
captureScreenRoboImage("build/outputs/roborazzi/specimens/date-picker-${if (dark) "dark" else "light"}.png")
}
}