findfamily: UI overhaul
- Commit
673a4a307b93fadb8c423ef954c9b986d50323b6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-09 20:15 UTC (5 months ago)
- Parents
f76442a
Diff
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.ktindex 75855e5176..f57fdd00ac 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt@@ -11,12 +11,14 @@ import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.asPaddingValues-import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn+import androidx.compose.foundation.layout.navigationBarsPadding+import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width@@ -24,46 +26,58 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardOptions-import androidx.compose.material3.BottomAppBarDefaults+import androidx.compose.material3.AssistChip+import androidx.compose.material3.BottomSheetDefaults+import androidx.compose.material3.BottomSheetScaffold import androidx.compose.material3.Card-import androidx.compose.material3.Checkbox import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi+import androidx.compose.material3.FilledTonalButton import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.FloatingActionButtonMenu import androidx.compose.material3.FloatingActionButtonMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.ListItem+import androidx.compose.material3.ListItemDefaults import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField-import androidx.compose.material3.Scaffold-import androidx.compose.material3.Surface+import androidx.compose.material3.Slider+import androidx.compose.material3.SheetValue+import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.ToggleFloatingActionButton import androidx.compose.material3.TopAppBar-import androidx.compose.material3.VerticalSlider+import androidx.compose.material3.TopAppBarDefaults+import androidx.compose.material3.dynamicLightColorScheme+import androidx.compose.material3.rememberBottomSheetScaffoldState import androidx.compose.material3.rememberSliderState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue+import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.lerp import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp+import kotlin.math.roundToInt import com.vayunmathur.findfamily.R import com.vayunmathur.findfamily.Route import com.vayunmathur.findfamily.data.LocationValue@@ -84,6 +98,7 @@ import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconEdit import com.vayunmathur.library.ui.IconNavigation import com.vayunmathur.library.ui.IconNavigationArrow+import com.vayunmathur.library.ui.IconRestore import com.vayunmathur.library.ui.IconVerify import com.vayunmathur.library.ui.IconSave import com.vayunmathur.library.util.NavBackStack@@ -105,6 +120,11 @@ import kotlinx.datetime.toInstant import kotlinx.datetime.toLocalDateTime import kotlin.time.Instant +// Small peek so most of the map stays visible with the sheet collapsed.+private val SheetPeekHeight = 128.dp+// Compact peek used in history mode: just the contact's name.+private val HistoryPeekHeight = 84.dp+ @OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class) @Composable fun MainPage(@@ -129,8 +149,15 @@ fun MainPage( val waypointName by ffViewModel.waypointName.collectAsState() val waypointRange by ffViewModel.waypointRange.collectAsState() + // History mode = a contact is selected and we're viewing their past track.+ val historyMode = selectedUserId != null && !isShowingPresent+ BackHandler(selectedUserId != null || (selectedWaypointId != null && selectedWaypointId != 0L)) {- ffViewModel.clearSelection()+ if (historyMode) {+ ffViewModel.setShowingPresent(true)+ } else {+ ffViewModel.clearSelection()+ } } val temporaryLinks by ffViewModel.temporaryLinks.collectAsState()@@ -141,18 +168,79 @@ fun MainPage( val usersByLocationName by ffViewModel.usersByLocationName.collectAsState() val userPositions by ffViewModel.latestLocationByUser.collectAsState() - Scaffold(+ val scaffoldState = rememberBottomSheetScaffoldState()++ // In history mode drop the sheet entirely (peek 0); the name goes in the app bar.+ val peekHeight = if (historyMode) 0.dp else SheetPeekHeight++ // The FAB sits on top of the always-light map, so color it from a light dynamic+ // scheme regardless of the app's (possibly dark) theme. Captured OUTSIDE the+ // scaffold to avoid the library's in-scaffold color-resolution quirk. Remembered+ // so we don't rebuild the whole palette on every recomposition.+ val context = LocalContext.current+ val lightScheme = remember(context) { dynamicLightColorScheme(context) }+ val fabContainerColor = lightScheme.primaryContainer+ val fabExpandedColor = lightScheme.primary+ val fabContentColor = lightScheme.onPrimaryContainer++ // The sheet's offset when settled at its peek, captured ONCE. Overlays then sit+ // at their default position plus (currentSheetOffset - peekOffset), clamped <= 0,+ // so they move 1:1 with the sheet. Peek is constant (128) whenever overlays show,+ // so a single capture stays correct across list/detail/back-from-history.+ val collapsedSheetOffset = remember { mutableFloatStateOf(Float.NaN) }+ LaunchedEffect(scaffoldState) {+ snapshotFlow {+ val st = scaffoldState.bottomSheetState+ val settled = st.currentValue == SheetValue.PartiallyExpanded &&+ st.targetValue == SheetValue.PartiallyExpanded+ val hist = selectedUserId != null && !isShowingPresent+ if (settled && !hist) runCatching { st.requireOffset() }.getOrNull() else null+ }.collect { off ->+ if (off != null && collapsedSheetOffset.floatValue.isNaN()) {+ collapsedSheetOffset.floatValue = off+ }+ }+ }++ // Leaving history sets the peek back to non-zero, but the collapsed sheet needs+ // a nudge to animate back to its peek. Retry until the anchor is ready.+ LaunchedEffect(historyMode) {+ if (!historyMode) {+ repeat(10) {+ if (runCatching { scaffoldState.bottomSheetState.partialExpand() }.isSuccess) {+ return@LaunchedEffect+ }+ kotlinx.coroutines.delay(50)+ }+ }+ }++ BottomSheetScaffold(+ scaffoldState = scaffoldState,+ sheetPeekHeight = peekHeight,+ sheetSwipeEnabled = !historyMode,+ sheetDragHandle = if (historyMode) null else { { BottomSheetDefaults.DragHandle() } },+ sheetContainerColor = MaterialTheme.colorScheme.surfaceContainerLow,+ // Transparent app bar so the map shows through behind it. topBar = { TopAppBar(+ colors = TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent), title = {- if (selectedUserId == null && selectedWaypointId == null) {+ if (historyMode) {+ val historyUser by ffViewModel.userByIdState(selectedUserId!!)+ Text(stringResource(R.string.history_title, historyUser?.name ?: ""))+ } else if (selectedUserId == null && selectedWaypointId == null) { Text(stringResource(R.string.app_name)) } }, navigationIcon = { if (selectedUserId != null || selectedWaypointId != null) { IconNavigation {- ffViewModel.clearSelection()+ if (historyMode) {+ ffViewModel.setShowingPresent(true)+ } else {+ ffViewModel.clearSelection()+ } } } },@@ -196,164 +284,120 @@ fun MainPage( } ) },- floatingActionButton = {+ sheetContent = { if (selectedUserId == null && selectedWaypointId == null) {- var expanded by remember { mutableStateOf(false) }- FloatingActionButtonMenu(expanded, {- ToggleFloatingActionButton(expanded, { expanded = it }) {- if (!expanded)- IconAdd()- else- IconClose()+ LazyColumn(+ Modifier.fillMaxWidth().navigationBarsPadding().padding(horizontal = 12.dp),+ verticalArrangement = Arrangement.spacedBy(6.dp),+ contentPadding = PaddingValues(bottom = 24.dp)+ ) {+ items(+ connectedUsers,+ key = { it.id }+ ) {+ UserCard(it, userPositions[it.id], true) {+ ffViewModel.selectUser(it.id)+ }+ }+ if (awaitingRequestUsers.isNotEmpty()) {+ item { SectionHeader(stringResource(R.string.section_location_sharing_requests)) }+ }+ items(+ awaitingRequestUsers,+ key = { it.id }+ ) {+ AwaitingRequestCard(backStack, it.id)+ }+ if (temporaryLinks.isNotEmpty()) {+ item { SectionHeader(stringResource(R.string.section_temporary_links)) }+ }+ items(temporaryLinks, key = { it.id }) {+ TemporaryLinkCard(platform, ffViewModel, it)+ }+ if (waypoints.isNotEmpty()) {+ item { SectionHeader(stringResource(R.string.section_saved_places)) }+ }+ items(waypoints, key = { it.id }) {+ WaypointCard(it, usersByLocationName[it.name].orEmpty()) {+ ffViewModel.beginEditWaypoint(it)+ } }- }) {- FloatingActionButtonMenuItem({- backStack.add(Route.AddPersonDialog())- },- { Text(stringResource(R.string.fab_person)) },- { Icon(painterResource(R.drawable.outline_person_24), null) })- FloatingActionButtonMenuItem({- ffViewModel.beginCreateWaypoint()- },- { Text(stringResource(R.string.fab_location)) },- { Icon(painterResource(R.drawable.outline_pin_drop_24), null) })- FloatingActionButtonMenuItem({- backStack.add(Route.AddLinkDialog)- },- { Text(stringResource(R.string.fab_link)) },- { Icon(painterResource(R.drawable.outline_link_24), null) }) }- } else if (selectedWaypointId != null) {- FloatingActionButton({- ffViewModel.saveCurrentWaypoint()- }) {- IconSave()+ } else if (historyMode) {+ // History mode has no sheet; the name is shown in the app bar.+ } else if (selectedUserId != null) {+ val selectedUser by ffViewModel.userByIdState(selectedUserId!!)+ val requestPickContact = platform.requestPickContact { name, photo ->+ selectedUser?.let { ffViewModel.upsertUser(it.copy(name = name, photo = photo)) } }- }- }, bottomBar = {- Surface(- Modifier.heightIn(max = 400.dp).padding(BottomAppBarDefaults.windowInsets.asPaddingValues()),- color = MaterialTheme.colorScheme.background- ) {- if (selectedUserId == null && selectedWaypointId == null) {- LazyColumn(- Modifier.padding(horizontal = 8.dp),- verticalArrangement = Arrangement.spacedBy(8.dp),- contentPadding = PaddingValues(vertical = 16.dp)- ) {- items(- connectedUsers,- key = { it.id }+ selectedUser?.let { user ->+ Column(Modifier.fillMaxWidth().navigationBarsPadding().padding(horizontal = 12.dp, vertical = 4.dp)) {+ UserCard(user, userPositions[user.id], true) {}+ Spacer(Modifier.height(8.dp))+ Row(+ Modifier.fillMaxWidth().padding(horizontal = 4.dp),+ verticalAlignment = Alignment.CenterVertically ) {- UserCard(it, userPositions[it.id], true) {- ffViewModel.selectUser(it.id)- }- }- if (awaitingRequestUsers.isNotEmpty()) {- item {- Text(- stringResource(R.string.section_location_sharing_requests),- Modifier.padding(start = 8.dp)- )- }+ Text(+ stringResource(R.string.share_your_location),+ Modifier.weight(1f),+ style = MaterialTheme.typography.bodyMedium+ )+ Switch(+ user.sendingEnabled,+ { send -> ffViewModel.setUserSharing(user, send) }+ ) }- items(- awaitingRequestUsers,- key = { it.id }+ Spacer(Modifier.height(4.dp))+ OutlinedButton(+ { requestPickContact() },+ Modifier.fillMaxWidth() ) {- AwaitingRequestCard(backStack, it.id)- }- if (temporaryLinks.isNotEmpty()) {- item {- Text(- stringResource(R.string.section_temporary_links),- Modifier.padding(start = 8.dp)- )- }- }- items(temporaryLinks, key = { it.id }) {- TemporaryLinkCard(platform, ffViewModel, it)- }- item {- if (waypoints.isNotEmpty()) {- Text(- stringResource(R.string.section_saved_places),- Modifier.padding(start = 8.dp)- )- }- }- items(waypoints, key = { it.id }) {- WaypointCard(it, usersByLocationName[it.name].orEmpty()) {- ffViewModel.beginEditWaypoint(it)- }- }- }- } else if (selectedUserId != null) {- val selectedUser by ffViewModel.userByIdState(selectedUserId!!)- val requestPickContact = platform.requestPickContact { name, photo ->- selectedUser?.let { ffViewModel.upsertUser(it.copy(name = name, photo = photo)) }- }- Column {- selectedUser?.let { user ->- UserCard(user, userPositions[user.id], true) {}- Spacer(Modifier.height(4.dp))- Column(- Modifier.fillMaxWidth(),- horizontalAlignment = Alignment.CenterHorizontally- ) {- Card {- Row(- Modifier.padding(horizontal = 16.dp, vertical = 8.dp),- verticalAlignment = Alignment.CenterVertically- ) {- Text(stringResource(R.string.share_your_location))- Spacer(Modifier.weight(1f))- Checkbox(- user.sendingEnabled,- { send ->- ffViewModel.setUserSharing(user, send)- })- }- }- Spacer(Modifier.height(4.dp))- OutlinedButton({- requestPickContact()- }) {- Text(stringResource(R.string.change_connected_contact))- }- }+ Text(stringResource(R.string.change_connected_contact)) } }- } else if (selectedWaypointId != null) {- Column(Modifier.padding(16.dp)) {- OutlinedTextField(- waypointName,- { ffViewModel.setWaypointName(it) },- Modifier.fillMaxWidth(),- isError = waypointName.isBlank(),- supportingText = if (waypointName.isBlank()) {- { Text(stringResource(R.string.waypoint_name_blank_error)) }- } else null- )- Spacer(Modifier.heightIn(8.dp))- OutlinedTextField(- waypointRange,- { ffViewModel.setWaypointRange(it) },- Modifier.fillMaxWidth(),- suffix = { Text(stringResource(R.string.waypoint_range_suffix)) },- keyboardOptions = KeyboardOptions(- keyboardType = KeyboardType.Number- ),- isError = waypointRange.toDoubleOrNull() == null,- supportingText = if (waypointRange.toDoubleOrNull() == null) {- { Text(stringResource(R.string.waypoint_range_error)) }- } else null- )- } }+ } else if (selectedWaypointId != null) {+ Column(Modifier.fillMaxWidth().navigationBarsPadding().padding(horizontal = 12.dp, vertical = 4.dp)) {+ OutlinedTextField(+ waypointName,+ { ffViewModel.setWaypointName(it) },+ Modifier.fillMaxWidth(),+ isError = waypointName.isBlank(),+ supportingText = if (waypointName.isBlank()) {+ { Text(stringResource(R.string.waypoint_name_blank_error)) }+ } else null+ )+ Spacer(Modifier.height(8.dp))+ OutlinedTextField(+ waypointRange,+ { ffViewModel.setWaypointRange(it) },+ Modifier.fillMaxWidth(),+ suffix = { Text(stringResource(R.string.waypoint_range_suffix)) },+ keyboardOptions = KeyboardOptions(+ keyboardType = KeyboardType.Number+ ),+ isError = waypointRange.toDoubleOrNull() == null,+ supportingText = if (waypointRange.toDoubleOrNull() == null) {+ { Text(stringResource(R.string.waypoint_range_error)) }+ } else null+ )+ }+ }+ }+ ) { _ ->+ // Full-bleed map; overlays (FAB, history bar) sit just above the collapsed+ // sheet peek and lift upward as the sheet expands.+ Box(Modifier.fillMaxSize()) {+ // Lift overlays above their peek baseline as the sheet expands:+ // (current - settledPeekOffset), clamped to <= 0. Uses the settled peek+ // offset (sampled above) so transitions never push overlays off-screen.+ val sheetLiftPx: () -> Int = {+ val base = collapsedSheetOffset.floatValue+ val cur = runCatching { scaffoldState.bottomSheetState.requireOffset() }.getOrNull()+ if (cur != null && !base.isNaN()) (cur - base).roundToInt().coerceAtMost(0) else 0 }- }) { paddingValues ->- Box(Modifier.padding(paddingValues).fillMaxWidth()) {+ val selectedUserObj = if (selectedUserId != null) { val user by ffViewModel.userByIdState(selectedUserId!!) user?.let { SelectedUser(it, isShowingPresent, historicalPosition) }@@ -378,15 +422,72 @@ fun MainPage( selectedWaypoint = selectedWaypointObj ) - if (selectedUserId != null) {- HistoryBar(+ if (historyMode) {+ HistoryScrubber( backStack,- isShowingPresent,- { ffViewModel.setShowingPresent(it) }, ffViewModel, selectedUserId!! ) { ffViewModel.setHistoricalPosition(it) } }++ // FAB floats just above the sheet peek, lifting as the sheet expands.+ // Wrapped in the light scheme so it reads correctly over the light map.+ Box(+ Modifier.align(Alignment.BottomEnd)+ .padding(end = 16.dp, bottom = peekHeight + 16.dp)+ .offset { IntOffset(0, sheetLiftPx()) }+ ) {+ MaterialTheme(colorScheme = lightScheme) {+ if (selectedUserId == null && selectedWaypointId == null) {+ var expanded by remember { mutableStateOf(false) }+ FloatingActionButtonMenu(expanded, {+ ToggleFloatingActionButton(+ expanded,+ { expanded = it },+ containerColor = { progress -> lerp(fabContainerColor, fabExpandedColor, progress) }+ ) {+ if (!expanded)+ IconAdd(tint = fabContentColor)+ else+ IconClose(tint = fabContentColor)+ }+ }) {+ FloatingActionButtonMenuItem({+ backStack.add(Route.AddPersonDialog())+ },+ { Text(stringResource(R.string.fab_person)) },+ { Icon(painterResource(R.drawable.outline_person_24), null) })+ FloatingActionButtonMenuItem({+ ffViewModel.beginCreateWaypoint()+ },+ { Text(stringResource(R.string.fab_location)) },+ { Icon(painterResource(R.drawable.outline_pin_drop_24), null) })+ FloatingActionButtonMenuItem({+ backStack.add(Route.AddLinkDialog)+ },+ { Text(stringResource(R.string.fab_link)) },+ { Icon(painterResource(R.drawable.outline_link_24), null) })+ }+ } else if (selectedWaypointId != null) {+ FloatingActionButton(+ { ffViewModel.saveCurrentWaypoint() },+ containerColor = fabContainerColor,+ contentColor = fabContentColor+ ) {+ IconSave()+ }+ } else if (selectedUserId != null && isShowingPresent) {+ // Enter history mode; exit is via back.+ FloatingActionButton(+ { ffViewModel.setShowingPresent(false) },+ containerColor = fabContainerColor,+ contentColor = fabContentColor+ ) {+ IconRestore()+ }+ }+ }+ } } } @@ -429,121 +530,122 @@ fun MainPage( } } +@OptIn(ExperimentalMaterial3ExpressiveApi::class)+@Composable+fun SectionHeader(title: String) {+ Text(+ title,+ Modifier.fillMaxWidth().padding(start = 12.dp, top = 8.dp, bottom = 2.dp),+ color = MaterialTheme.colorScheme.primary,+ style = MaterialTheme.typography.titleSmallEmphasized+ )+}+ @OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class) @Composable-fun BoxScope.HistoryBar(+fun BoxScope.HistoryScrubber( backStack: NavBackStack<Route>,- isShowingPresent: Boolean,- setShowingPresent: (Boolean) -> Unit, ffViewModel: FindFamilyViewModel, userid: Long, setHistoricalPosition: (org.maplibre.spatialk.geojson.Position) -> Unit ) {- Card(Modifier.width(105.dp).padding(2.dp).align(Alignment.BottomEnd)) {- val colmod = if (isShowingPresent) Modifier else Modifier.fillMaxHeight(1f)- Column(colmod.padding(4.dp).fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {- if (!isShowingPresent) {- val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())- val currentDate = now.date- val currentTime = now.time- var pickedLocalDate by remember { mutableStateOf(currentDate) }- val sliderState = rememberSliderState(- currentTime.toSecondOfDay().toFloat(), valueRange = 0.0f..(24f * 60f * 60f - 0.1f)- )+ val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())+ val currentDate = now.date+ val currentTime = now.time+ var pickedLocalDate by remember { mutableStateOf(currentDate) }+ val sliderState = rememberSliderState(+ currentTime.toSecondOfDay().toFloat(), valueRange = 0.0f..(24f * 60f * 60f - 0.1f)+ ) - sliderState.onValueChange = {- val maximum = if (currentDate == pickedLocalDate) currentTime.toSecondOfDay().toFloat() else null- if (maximum != null && it > maximum) sliderState.value = maximum- else sliderState.value = it- }- val pickedLocalTime by remember {- derivedStateOf {- LocalTime.fromSecondOfDay(sliderState.value.toInt())- }- }- Box(Modifier.weight(1f)) {- VerticalSlider(sliderState, reverseDirection = true)- }- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {- IconButton({- sliderState.value -= 5 * 60- }) {- Text(stringResource(R.string.history_rewind_large))- }- IconButton({- sliderState.value += 5 * 60- }) {- Text(stringResource(R.string.history_forward_large))- }- }- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {- IconButton({- sliderState.value -= 60- }) {- Text(stringResource(R.string.history_rewind_medium))- }- IconButton({- sliderState.value += 60- }) {- Text(stringResource(R.string.history_forward_medium))- }- }- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {- IconButton({- sliderState.value -= 10- }) {- Text(stringResource(R.string.history_rewind_small))- }- IconButton({- sliderState.value += 10- }) {- Text(stringResource(R.string.history_forward_small))- }- }- Text(pickedLocalTime.format(DateFormats.TIME_SECOND_AM_PM), fontSize = 11.sp)+ sliderState.onValueChange = {+ val maximum = if (currentDate == pickedLocalDate) currentTime.toSecondOfDay().toFloat() else null+ if (maximum != null && it > maximum) sliderState.value = maximum+ else sliderState.value = it+ }+ val pickedLocalTime by remember {+ derivedStateOf {+ LocalTime.fromSecondOfDay(sliderState.value.toInt())+ }+ } - ResultEffect<LocalDate>("HistoryDatePicker") {- pickedLocalDate = it- }+ Card(+ Modifier.align(Alignment.BottomCenter)+ .fillMaxWidth()+ .navigationBarsPadding()+ .padding(horizontal = 12.dp, vertical = 8.dp)+ ) {+ Column(+ Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),+ verticalArrangement = Arrangement.spacedBy(6.dp)+ ) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Slider(sliderState, Modifier.weight(1f))+ Spacer(Modifier.width(8.dp))+ Text(+ pickedLocalTime.format(DateFormats.TIME_SECOND_AM_PM),+ style = MaterialTheme.typography.labelLarge+ )+ }+ AssistChip(+ { backStack.add(Route.UserPageHistoryDatePicker(pickedLocalDate)) },+ { Text(pickedLocalDate.format(DateFormats.DATE_INPUT)) }+ )+ Row(+ Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(4.dp)+ ) {+ StepButton(stringResource(R.string.history_step_minus_5m)) { sliderState.value -= 5 * 60 }+ StepButton(stringResource(R.string.history_step_minus_1m)) { sliderState.value -= 60 }+ StepButton(stringResource(R.string.history_step_minus_10s)) { sliderState.value -= 10 }+ StepButton(stringResource(R.string.history_step_plus_10s)) { sliderState.value += 10 }+ StepButton(stringResource(R.string.history_step_plus_1m)) { sliderState.value += 60 }+ StepButton(stringResource(R.string.history_step_plus_5m)) { sliderState.value += 5 * 60 }+ }+ }+ } - OutlinedButton({- backStack.add(Route.UserPageHistoryDatePicker(pickedLocalDate))- }, Modifier.fillMaxWidth()) {- Text(pickedLocalDate.format(DateFormats.DATE_INPUT))- }- val simulatedTimestamp = pickedLocalDate.atTime(pickedLocalTime)- .toInstant(TimeZone.currentSystemDefault())+ ResultEffect<LocalDate>("HistoryDatePicker") {+ pickedLocalDate = it+ } - val locs by ffViewModel.locationHistory.collectAsState()+ val simulatedTimestamp = pickedLocalDate.atTime(pickedLocalTime)+ .toInstant(TimeZone.currentSystemDefault()) - LaunchedEffect(simulatedTimestamp, locs) {- if (locs.isNotEmpty()) {- val closest = locs.minBy { (it.timestamp - simulatedTimestamp).absoluteValue }- setHistoricalPosition(closest.coord.toPosition())- }- }- }- OutlinedButton({- setShowingPresent(!isShowingPresent)- }, Modifier.fillMaxWidth()) {- Text(if (isShowingPresent) stringResource(R.string.history_button) else stringResource(R.string.hide_button), fontSize = 11.sp)- }+ val locs by ffViewModel.locationHistory.collectAsState()++ LaunchedEffect(simulatedTimestamp, locs) {+ if (locs.isNotEmpty()) {+ val closest = locs.minBy { (it.timestamp - simulatedTimestamp).absoluteValue }+ setHistoricalPosition(closest.coord.toPosition()) } } } +@Composable+private fun RowScope.StepButton(label: String, onClick: () -> Unit) {+ FilledTonalButton(+ onClick,+ Modifier.weight(1f).heightIn(min = 36.dp),+ contentPadding = PaddingValues(horizontal = 4.dp, vertical = 0.dp)+ ) {+ Text(label, fontSize = 12.sp, maxLines = 1)+ }+}+ @Composable fun AwaitingRequestCard(backStack: NavBackStack<Route>, id: Long) { Card {- ListItem({- Text(stringResource(R.string.request_from, id.encodeBase26()))- }, trailingContent = {- IconButton({- backStack.add(Route.AddPersonDialog(id))- }) {- IconAdd()+ ListItem(+ { Text(stringResource(R.string.request_from, id.encodeBase26())) },+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),+ trailingContent = {+ IconButton({+ backStack.add(Route.AddPersonDialog(id))+ }) {+ IconAdd()+ } }- })+ ) } } @@ -551,25 +653,27 @@ fun AwaitingRequestCard(backStack: NavBackStack<Route>, id: Long) { fun TemporaryLinkCard(platform: Platform, ffViewModel: FindFamilyViewModel, temporaryLink: TemporaryLink) { val context = LocalContext.current Card {- ListItem({- Text(temporaryLink.name)- }, Modifier, {}, {- Text(stringResource(R.string.expires, timestring(temporaryLink.deleteAt, true, context)))- }, trailingContent = {- Row {- IconButton({- platform.copy("https://findfamily.cc/view/${temporaryLink.id}#key=${temporaryLink.key}")- }) {- IconCopy()- }- Spacer(Modifier.width(16.dp))- IconButton({- ffViewModel.deleteTemporaryLink(temporaryLink)- }) {- IconDelete()+ ListItem(+ { Text(temporaryLink.name, fontWeight = FontWeight.Bold) },+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),+ supportingContent = {+ Text(stringResource(R.string.expires, timestring(temporaryLink.deleteAt, true, context)))+ },+ trailingContent = {+ Row {+ IconButton({+ platform.copy("https://findfamily.cc/view/${temporaryLink.id}#key=${temporaryLink.key}")+ }) {+ IconCopy()+ }+ IconButton({+ ffViewModel.deleteTemporaryLink(temporaryLink)+ }) {+ IconDelete()+ } } }- })+ ) } } @@ -583,15 +687,14 @@ fun WaypointCard(waypoint: Waypoint, userNamesHere: List<String>, onSelect: () - Card(Modifier.clickable(onClick = onSelect)) { ListItem( headlineContent = { Text(waypoint.name, fontWeight = FontWeight.Bold) },- supportingContent = { Text(usersString) },- trailingContent = {- IconEdit()- }+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),+ supportingContent = { Text(usersString, maxLines = 1, overflow = TextOverflow.Ellipsis) },+ trailingContent = { IconEdit() } ) } } -@OptIn(ExperimentalTime::class)+@OptIn(ExperimentalTime::class, ExperimentalMaterial3ExpressiveApi::class) @Composable fun UserCard(user: User, locationValue: LocationValue?, showSupportingContent: Boolean, onClick: () -> Unit) { val context = LocalContext.current@@ -621,44 +724,53 @@ fun UserCard(user: User, locationValue: LocationValue?, showSupportingContent: B } Card(if (showSupportingContent) Modifier.clickable(onClick = onClick) else Modifier) { ListItem(- leadingContent = {- Column(Modifier.width(65.dp)) {- UserPicture(user, 65.dp)- Spacer(Modifier.height(4.dp))- locationValue?.battery?.let {- BatteryBar(it)- }- }+ leadingContent = { UserPicture(user, 40.dp) },+ colors = ListItemDefaults.colors(containerColor = Color.Transparent),+ headlineContent = {+ Text(+ user.name,+ style = MaterialTheme.typography.titleMediumEmphasized,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis+ ) },- headlineContent = { Text(user.name, fontWeight = FontWeight.Bold) }, supportingContent = { if (showSupportingContent) { Text(stringResource(R.string.user_card_status, lastUpdatedTime, user.locationName, sinceString)) }- }, trailingContent = {+ },+ trailingContent = { if (showSupportingContent) {- Text(speedString)+ Column(horizontalAlignment = Alignment.End) {+ Text(speedString, style = MaterialTheme.typography.labelMedium)+ Spacer(Modifier.height(2.dp))+ locationValue?.battery?.let { BatteryBar(it) }+ } }- })+ }+ ) } } @Composable-fun BatteryBar(percent: Float, width: Dp = 30.dp, height: Dp = 15.dp) {+fun BatteryBar(percent: Float, width: Dp = 24.dp, height: Dp = 12.dp) { val color = when { percent > 50 -> Color.Green percent > 20 -> Color.Yellow else -> Color.Red } - Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween) {- Box(Modifier.size(width, height).border(2.dp, MaterialTheme.colorScheme.primary, RoundedCornerShape(4.dp))) {- Box(Modifier.fillMaxHeight().width((width * (percent / 100f))).background(color, RoundedCornerShape(4.dp)))+ Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {+ Box(Modifier.size(width, height).border(1.5.dp, MaterialTheme.colorScheme.primary, RoundedCornerShape(3.dp))) {+ Box(Modifier.fillMaxWidthFraction(percent).height(height).background(color, RoundedCornerShape(3.dp))) }- Text(stringResource(R.string.battery_percentage, percent.toInt()), fontSize = 12.sp)+ Text(stringResource(R.string.battery_percentage, percent.toInt()), fontSize = 11.sp) } } +private fun Modifier.fillMaxWidthFraction(percent: Float): Modifier =+ this.fillMaxWidth((percent / 100f).coerceIn(0f, 1f))+ fun timestring(timestamp: Instant, future: Boolean, context: Context): String { val duration = (Clock.System.now() - timestamp).absoluteValue return when {
findfamily/src/main/res/values-cs/strings.xml
diff --git a/findfamily/src/main/res/values-cs/strings.xml b/findfamily/src/main/res/values-cs/strings.xmlindex 32b71f26cb..bed709944c 100644--- a/findfamily/src/main/res/values-cs/strings.xml+++ b/findfamily/src/main/res/values-cs/strings.xml@@ -35,12 +35,6 @@ <string name="change_connected_contact">Změnit připojený kontakt</string> <string name="history_button">Historie</string> <string name="hide_button">Skrýt</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="waypoint_name_blank_error">Název nemůže být prázdný</string> <string name="waypoint_range_error">Rozsah musí být číslo</string> <string name="waypoint_range_suffix">metrů</string>
findfamily/src/main/res/values-de/strings.xml
diff --git a/findfamily/src/main/res/values-de/strings.xml b/findfamily/src/main/res/values-de/strings.xmlindex 99aaac3462..2bd68b9f58 100644--- a/findfamily/src/main/res/values-de/strings.xml+++ b/findfamily/src/main/res/values-de/strings.xml@@ -48,12 +48,6 @@ <string name="change_connected_contact">Verbundenen Kontakt ändern</string> <string name="history_button">Verlauf</string> <string name="hide_button">Verstecken</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="waypoint_name_blank_error">Name kann nicht leer sein</string> <string name="waypoint_range_error">Durchmesser muss eine Zahl sein</string> <string name="waypoint_range_suffix">Meter</string>
findfamily/src/main/res/values-et/strings.xml
diff --git a/findfamily/src/main/res/values-et/strings.xml b/findfamily/src/main/res/values-et/strings.xmlindex 03b336b1fc..9ac1b24c6c 100644--- a/findfamily/src/main/res/values-et/strings.xml+++ b/findfamily/src/main/res/values-et/strings.xml@@ -12,12 +12,6 @@ <string name="change_connected_contact">Muuda ühendatud kasutajakontot</string> <string name="history_button">Ajalugu</string> <string name="hide_button">Peida</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="waypoint_name_blank_error">Nimi ei saa jääda tühjaks</string> <string name="waypoint_range_error">Vahemik peab olema number</string> <string name="waypoint_range_suffix">meetrit</string>
findfamily/src/main/res/values-it/strings.xml
diff --git a/findfamily/src/main/res/values-it/strings.xml b/findfamily/src/main/res/values-it/strings.xmlindex 566c395703..83cda1d13e 100644--- a/findfamily/src/main/res/values-it/strings.xml+++ b/findfamily/src/main/res/values-it/strings.xml@@ -45,12 +45,6 @@ <string name="change_connected_contact">Cambia il contatto connesso</string> <string name="history_button">Cronologia</string> <string name="hide_button">Nascondi</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="waypoint_name_blank_error">Il nome non può essere vuoto</string> <string name="waypoint_range_error">L\'intervallo deve essere un numero</string> <string name="waypoint_range_suffix">metri</string>
findfamily/src/main/res/values-pl/strings.xml
diff --git a/findfamily/src/main/res/values-pl/strings.xml b/findfamily/src/main/res/values-pl/strings.xmlindex b9d6b91f1c..263c89c7e3 100644--- a/findfamily/src/main/res/values-pl/strings.xml+++ b/findfamily/src/main/res/values-pl/strings.xml@@ -48,12 +48,6 @@ <string name="change_connected_contact">Zmień powiązany kontakt</string> <string name="history_button">Historia</string> <string name="hide_button">Ukryj</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="waypoint_name_blank_error">Pole „Imię” nie może pozostać puste</string> <string name="waypoint_range_error">Wartość musi być liczbą</string> <string name="waypoint_range_suffix">metry</string>
findfamily/src/main/res/values-zh-rCN/strings.xml
diff --git a/findfamily/src/main/res/values-zh-rCN/strings.xml b/findfamily/src/main/res/values-zh-rCN/strings.xmlindex 7d4abe5028..a8da91325a 100644--- a/findfamily/src/main/res/values-zh-rCN/strings.xml+++ b/findfamily/src/main/res/values-zh-rCN/strings.xml@@ -41,12 +41,6 @@ <string name="time_minutes_ago">%1$d 分钟前</string> <string name="time_hours_ago">%1$d 小时前</string> <string name="time_days_ago">%1$d 天前</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string> <string name="expiry_15_minutes">15 分钟</string> <string name="expiry_30_minutes">30 分钟</string> <string name="expiry_1_hour">1 小时</string>
findfamily/src/main/res/values/strings.xml
diff --git a/findfamily/src/main/res/values/strings.xml b/findfamily/src/main/res/values/strings.xmlindex 0968211ea9..070d4460bc 100644--- a/findfamily/src/main/res/values/strings.xml+++ b/findfamily/src/main/res/values/strings.xml@@ -70,13 +70,16 @@ <string name="share_your_location">Share your location with this person</string> <string name="change_connected_contact">Change connected contact</string> <string name="history_button">History</string>- <string name="hide_button">Hide</string>- <string name="history_rewind_large"><<<</string>- <string name="history_forward_large">>>></string>- <string name="history_rewind_medium"><<</string>- <string name="history_forward_medium">>></string>- <string name="history_rewind_small"><</string>- <string name="history_forward_small">></string>+ <string name="history_title">History: %1$s</string>+ <string name="hide_button">Live</string>+ <string name="history_show_content_desc">View location history</string>+ <string name="history_hide_content_desc">Back to live location</string>+ <string name="history_step_minus_5m">-5m</string>+ <string name="history_step_minus_1m">-1m</string>+ <string name="history_step_minus_10s">-10s</string>+ <string name="history_step_plus_10s">+10s</string>+ <string name="history_step_plus_1m">+1m</string>+ <string name="history_step_plus_5m">+5m</string> <!-- WaypointEditPage --> <string name="waypoint_name_blank_error">Name cannot be blank</string>