web: convert raw Scaffolds to shared scaffolds (BrowserPage toolbar documented exception)
- Commit
5f6c13ab48d5928a7bf96d8a62b64504dc0f53dd- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 03:21 UTC (3 months ago)
- Parents
fe787a0
Diff
web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt b/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.ktindex e92189c50e..46478ee6cc 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt@@ -1,313 +1,308 @@-package com.vayunmathur.web.ui--import androidx.compose.ui.res.stringResource-import com.vayunmathur.web.R-import androidx.compose.foundation.ExperimentalFoundationApi-import androidx.compose.foundation.combinedClickable-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.shape.CircleShape-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import com.vayunmathur.library.ui.R as UiR-import com.vayunmathur.library.ui.ConfirmDialog-import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.DropdownMenu-import com.vayunmathur.library.ui.DropdownMenuItem-import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.FilterChip-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconFolder-import com.vayunmathur.library.ui.IconNavigation-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField-import com.vayunmathur.library.ui.Scaffold-import com.vayunmathur.library.ui.Surface-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.TopAppBar-import com.vayunmathur.web.Route-import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.web.data.Bookmark-import com.vayunmathur.web.data.BookmarkFolder-import com.vayunmathur.web.platform.BrowserUtils-import com.vayunmathur.web.platform.WebViewModel--@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)-@Composable-fun BookmarksPage(- viewModel: WebViewModel,- backStack: NavBackStack<Route>,-) {- val bookmarks by viewModel.bookmarks.collectAsStateWithLifecycle()- val folders by viewModel.folders.collectAsStateWithLifecycle()-- BookmarksScreen(- bookmarks = bookmarks,- folders = folders,- navigationIcon = { IconNavigation(backStack) },- onOpen = { bm ->- viewModel.externalIntentUrl(bm.url)- backStack.pop()- },- onDelete = { viewModel.removeBookmark(it) },- onCreateFolder = { viewModel.createFolder(it) },- onDeleteFolder = { viewModel.deleteFolder(it) },- )-}--/**- * The bookmark list, with no ViewModel and no back stack so it can be rendered from a- * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.- * [navigationIcon] is a slot because "up" is navigation, not state.- */-@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)-@Composable-private fun BookmarksScreen(- bookmarks: List<Bookmark>,- folders: List<BookmarkFolder>,- navigationIcon: @Composable () -> Unit = {},- onOpen: (Bookmark) -> Unit = {},- onDelete: (Bookmark) -> Unit = {},- onCreateFolder: (String) -> Unit = {},- onDeleteFolder: (BookmarkFolder) -> Unit = {},-) {- var selectedFolder by remember { mutableStateOf<Long?>(null) }- var showNewFolderDialog by remember { mutableStateOf(false) }- var newFolderName by remember { mutableStateOf("") }- var showDeleteDialog by remember { mutableStateOf<Bookmark?>(null) }- var showFolderDeleteDialog by remember { mutableStateOf<BookmarkFolder?>(null) }-- val filtered = remember(bookmarks, selectedFolder) {- if (selectedFolder == null) bookmarks.filter { it.folderId == null }- else bookmarks.filter { it.folderId == selectedFolder }- }-- Scaffold(- topBar = {- TopAppBar(- title = { Text(stringResource(R.string.bookmarks)) },- navigationIcon = navigationIcon,- actions = {- IconButton(onClick = { showNewFolderDialog = true }) {- IconFolder()- }- }- )- }- ) { paddingValues ->- Column(Modifier.fillMaxSize().padding(paddingValues)) {- if (folders.isNotEmpty()) {- androidx.compose.foundation.lazy.LazyRow(- modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),- horizontalArrangement = Arrangement.spacedBy(8.dp)- ) {- item {- FilterChip(- selected = selectedFolder == null,- onClick = { selectedFolder = null },- label = { Text(stringResource(R.string.all)) }- )- }- items(folders, key = { it.id }) { folder ->- var showFolderMenu by remember { mutableStateOf(false) }- Box {- FilterChip(- selected = selectedFolder == folder.id,- onClick = { selectedFolder = folder.id },- label = { Text(folder.name) }- )- // Long press area handled via combinedClickable would conflict with chip,- // use a small overflow dropdown anchored to same box via click on trailing.- // For simplicity, expose delete via extra dropdown triggered by chip click when selected:- if (showFolderMenu) {- DropdownMenu(expanded = true, onDismissRequest = { showFolderMenu = false }) {- DropdownMenuItem(- text = { Text(stringResource(R.string.delete_folder)) },- onClick = {- showFolderMenu = false- showFolderDeleteDialog = folder- }- )- }- }- // Tap folder chip to open menu if long-press story is too much: we add Box clickable overlay for long press- // Disabled to keep FilterChip semantics; instead add long-press via combinedClickable wrapper- // (Workaround: Clicking folder when already selected opens menu)- if (selectedFolder == folder.id) {- // As soon as folder is selected, allow tap to open delete menu via extra button would be confusing.- // For simplicity, attach long-press to select then expose delete elsewhere.- // We add a clickable overlay that opens menu on long press.- // Use combinedClickable on inner Box via Modifier on wrapping Box- // Since we are inside LazyRow, we handle this differently — keep simple:- // If this folder is selected, clicking again opens delete.- // So second click triggers menu.- }- }- // Support long press on chip row via separate combinedClickable hack:- // We'll handle delete via dedicated long-press shim:- // Actually re-implment chip with combinedClickable wrapper that opens menu- // The simplest: when folder id matches selected, show context via Dropdown triggered by icon inside filter chip is not available.- // For now, expose folder deletion via explicit long press on the chip surface using a Box overlay:- // We cannot easily add combinedClickable to FilterChip, so we use a wrapper approach outside:- // Handled by adding a second clickable area: long-press on folder name area triggers menu by toggling showFolderMenu.- // The above Box approach already captures clicks; to support long-press we add combinedClickable on outer Box.- }- // Additional helper: for each folder, add a long-press detector overlay using Box with combinedClickable- // This section intentionally minimal — folder deletion also accessible via settings.- }- }-- if (filtered.isEmpty() && bookmarks.isEmpty()) {- EmptyState(- title = stringResource(R.string.no_bookmarks_yet),- )- } else if (filtered.isEmpty()) {- EmptyState(- title = stringResource(R.string.no_bookmarks_in_this_folder),- modifier = Modifier.fillMaxSize().padding(24.dp),- )- } else {- LazyColumn(- modifier = Modifier.fillMaxSize(),- verticalArrangement = Arrangement.spacedBy(2.dp)- ) {- items(filtered, key = { it.id }) { bm ->- BookmarkRow(- bookmark = bm,- onClick = { onOpen(bm) },- onLongClick = { showDeleteDialog = bm }- )- }- }- }- }- }-- if (showNewFolderDialog) {- AlertDialog(- onDismissRequest = { showNewFolderDialog = false },- title = { Text(stringResource(R.string.new_folder)) },- text = {- OutlinedTextField(- value = newFolderName,- onValueChange = { newFolderName = it },- placeholder = { Text(stringResource(R.string.folder_name)) },- singleLine = true,- modifier = Modifier.fillMaxWidth()- )- },- confirmButton = {- TextButton(- onClick = {- if (newFolderName.isNotBlank()) {- onCreateFolder(newFolderName.trim())- }- newFolderName = ""- showNewFolderDialog = false- },- enabled = newFolderName.isNotBlank()- ) { Text(stringResource(R.string.create)) }- },- dismissButton = {- TextButton(onClick = {- newFolderName = ""- showNewFolderDialog = false- }) { Text(stringResource(UiR.string.cancel)) }- }- )- }-- showDeleteDialog?.let { bm ->- AlertDialog(- onDismissRequest = { showDeleteDialog = null },- title = { Text(stringResource(R.string.delete_bookmark)) },- text = { Text(bm.title.ifBlank { bm.url }) },- confirmButton = {- TextButton(onClick = {- onDelete(bm)- showDeleteDialog = null- }) { Text(stringResource(UiR.string.delete)) }- },- dismissButton = {- TextButton(onClick = { showDeleteDialog = null }) { Text(stringResource(UiR.string.cancel)) }- }- )- }-- showFolderDeleteDialog?.let { folder ->- ConfirmDialog(- title = stringResource(R.string.delete_folder_2),- message = stringResource(R.string.bookmarks_inside_will_also_be_deleted, folder.name),- confirmLabel = stringResource(UiR.string.delete),- dismissLabel = stringResource(UiR.string.cancel),- onConfirm = { onDeleteFolder(folder)- if (selectedFolder == folder.id) selectedFolder = null },- onDismiss = { showFolderDeleteDialog = null },- destructive = true,- )- }-}--@Composable-private fun BookmarkRow(- bookmark: Bookmark,- onClick: () -> Unit,- onLongClick: () -> Unit,-) {- Row(- modifier = Modifier- .fillMaxWidth()- .combinedClickable(onClick = onClick, onLongClick = onLongClick)- .padding(horizontal = 16.dp, vertical = 12.dp),- verticalAlignment = Alignment.CenterVertically- ) {- Surface(- shape = CircleShape,- color = MaterialTheme.colorScheme.secondaryContainer,- modifier = Modifier.size(40.dp)- ) {- Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {- Text(- bookmark.title.take(1).uppercase().ifBlank { "B" },- style = MaterialTheme.typography.titleSmall- )- }- }- Spacer(Modifier.width(12.dp))- Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {- Text(- bookmark.title.ifBlank { bookmark.url },- maxLines = 1,- overflow = TextOverflow.Ellipsis,- style = MaterialTheme.typography.bodyMedium- )- Text(- BrowserUtils.prettyUrl(bookmark.url),- maxLines = 1,- overflow = TextOverflow.Ellipsis,- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- }- }-}+package com.vayunmathur.web.ui++import androidx.compose.ui.res.stringResource+import com.vayunmathur.web.R+import androidx.compose.foundation.ExperimentalFoundationApi+import androidx.compose.foundation.combinedClickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.lifecycle.compose.collectAsStateWithLifecycle+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.ConfirmDialog+import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.DropdownMenuItem+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.FilterChip+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconFolder+import com.vayunmathur.library.ui.IconNavigation+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.web.Route+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.web.data.Bookmark+import com.vayunmathur.web.data.BookmarkFolder+import com.vayunmathur.web.platform.BrowserUtils+import com.vayunmathur.web.platform.WebViewModel++@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)+@Composable+fun BookmarksPage(+ viewModel: WebViewModel,+ backStack: NavBackStack<Route>,+) {+ val bookmarks by viewModel.bookmarks.collectAsStateWithLifecycle()+ val folders by viewModel.folders.collectAsStateWithLifecycle()++ BookmarksScreen(+ bookmarks = bookmarks,+ folders = folders,+ navigationIcon = { IconNavigation(backStack) },+ onOpen = { bm ->+ viewModel.externalIntentUrl(bm.url)+ backStack.pop()+ },+ onDelete = { viewModel.removeBookmark(it) },+ onCreateFolder = { viewModel.createFolder(it) },+ onDeleteFolder = { viewModel.deleteFolder(it) },+ )+}++/**+ * The bookmark list, with no ViewModel and no back stack so it can be rendered from a+ * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.+ * [navigationIcon] is a slot because "up" is navigation, not state.+ */+@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)+@Composable+private fun BookmarksScreen(+ bookmarks: List<Bookmark>,+ folders: List<BookmarkFolder>,+ navigationIcon: @Composable () -> Unit = {},+ onOpen: (Bookmark) -> Unit = {},+ onDelete: (Bookmark) -> Unit = {},+ onCreateFolder: (String) -> Unit = {},+ onDeleteFolder: (BookmarkFolder) -> Unit = {},+) {+ var selectedFolder by remember { mutableStateOf<Long?>(null) }+ var showNewFolderDialog by remember { mutableStateOf(false) }+ var newFolderName by remember { mutableStateOf("") }+ var showDeleteDialog by remember { mutableStateOf<Bookmark?>(null) }+ var showFolderDeleteDialog by remember { mutableStateOf<BookmarkFolder?>(null) }++ val filtered = remember(bookmarks, selectedFolder) {+ if (selectedFolder == null) bookmarks.filter { it.folderId == null }+ else bookmarks.filter { it.folderId == selectedFolder }+ }++ AppScaffold(+ title = stringResource(R.string.bookmarks),+ navigationIcon = navigationIcon,+ actions = {+ IconButton(onClick = { showNewFolderDialog = true }) {+ IconFolder()+ }+ },+ ) { paddingValues ->+ Column(Modifier.fillMaxSize().padding(paddingValues)) {+ if (folders.isNotEmpty()) {+ androidx.compose.foundation.lazy.LazyRow(+ modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),+ horizontalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ item {+ FilterChip(+ selected = selectedFolder == null,+ onClick = { selectedFolder = null },+ label = { Text(stringResource(R.string.all)) }+ )+ }+ items(folders, key = { it.id }) { folder ->+ var showFolderMenu by remember { mutableStateOf(false) }+ Box {+ FilterChip(+ selected = selectedFolder == folder.id,+ onClick = { selectedFolder = folder.id },+ label = { Text(folder.name) }+ )+ // Long press area handled via combinedClickable would conflict with chip,+ // use a small overflow dropdown anchored to same box via click on trailing.+ // For simplicity, expose delete via extra dropdown triggered by chip click when selected:+ if (showFolderMenu) {+ DropdownMenu(expanded = true, onDismissRequest = { showFolderMenu = false }) {+ DropdownMenuItem(+ text = { Text(stringResource(R.string.delete_folder)) },+ onClick = {+ showFolderMenu = false+ showFolderDeleteDialog = folder+ }+ )+ }+ }+ // Tap folder chip to open menu if long-press story is too much: we add Box clickable overlay for long press+ // Disabled to keep FilterChip semantics; instead add long-press via combinedClickable wrapper+ // (Workaround: Clicking folder when already selected opens menu)+ if (selectedFolder == folder.id) {+ // As soon as folder is selected, allow tap to open delete menu via extra button would be confusing.+ // For simplicity, attach long-press to select then expose delete elsewhere.+ // We add a clickable overlay that opens menu on long press.+ // Use combinedClickable on inner Box via Modifier on wrapping Box+ // Since we are inside LazyRow, we handle this differently — keep simple:+ // If this folder is selected, clicking again opens delete.+ // So second click triggers menu.+ }+ }+ // Support long press on chip row via separate combinedClickable hack:+ // We'll handle delete via dedicated long-press shim:+ // Actually re-implment chip with combinedClickable wrapper that opens menu+ // The simplest: when folder id matches selected, show context via Dropdown triggered by icon inside filter chip is not available.+ // For now, expose folder deletion via explicit long press on the chip surface using a Box overlay:+ // We cannot easily add combinedClickable to FilterChip, so we use a wrapper approach outside:+ // Handled by adding a second clickable area: long-press on folder name area triggers menu by toggling showFolderMenu.+ // The above Box approach already captures clicks; to support long-press we add combinedClickable on outer Box.+ }+ // Additional helper: for each folder, add a long-press detector overlay using Box with combinedClickable+ // This section intentionally minimal — folder deletion also accessible via settings.+ }+ }++ if (filtered.isEmpty() && bookmarks.isEmpty()) {+ EmptyState(+ title = stringResource(R.string.no_bookmarks_yet),+ )+ } else if (filtered.isEmpty()) {+ EmptyState(+ title = stringResource(R.string.no_bookmarks_in_this_folder),+ modifier = Modifier.fillMaxSize().padding(24.dp),+ )+ } else {+ LazyColumn(+ modifier = Modifier.fillMaxSize(),+ verticalArrangement = Arrangement.spacedBy(2.dp)+ ) {+ items(filtered, key = { it.id }) { bm ->+ BookmarkRow(+ bookmark = bm,+ onClick = { onOpen(bm) },+ onLongClick = { showDeleteDialog = bm }+ )+ }+ }+ }+ }+ }++ if (showNewFolderDialog) {+ AlertDialog(+ onDismissRequest = { showNewFolderDialog = false },+ title = { Text(stringResource(R.string.new_folder)) },+ text = {+ OutlinedTextField(+ value = newFolderName,+ onValueChange = { newFolderName = it },+ placeholder = { Text(stringResource(R.string.folder_name)) },+ singleLine = true,+ modifier = Modifier.fillMaxWidth()+ )+ },+ confirmButton = {+ TextButton(+ onClick = {+ if (newFolderName.isNotBlank()) {+ onCreateFolder(newFolderName.trim())+ }+ newFolderName = ""+ showNewFolderDialog = false+ },+ enabled = newFolderName.isNotBlank()+ ) { Text(stringResource(R.string.create)) }+ },+ dismissButton = {+ TextButton(onClick = {+ newFolderName = ""+ showNewFolderDialog = false+ }) { Text(stringResource(UiR.string.cancel)) }+ }+ )+ }++ showDeleteDialog?.let { bm ->+ AlertDialog(+ onDismissRequest = { showDeleteDialog = null },+ title = { Text(stringResource(R.string.delete_bookmark)) },+ text = { Text(bm.title.ifBlank { bm.url }) },+ confirmButton = {+ TextButton(onClick = {+ onDelete(bm)+ showDeleteDialog = null+ }) { Text(stringResource(UiR.string.delete)) }+ },+ dismissButton = {+ TextButton(onClick = { showDeleteDialog = null }) { Text(stringResource(UiR.string.cancel)) }+ }+ )+ }++ showFolderDeleteDialog?.let { folder ->+ ConfirmDialog(+ title = stringResource(R.string.delete_folder_2),+ message = stringResource(R.string.bookmarks_inside_will_also_be_deleted, folder.name),+ confirmLabel = stringResource(UiR.string.delete),+ dismissLabel = stringResource(UiR.string.cancel),+ onConfirm = { onDeleteFolder(folder)+ if (selectedFolder == folder.id) selectedFolder = null },+ onDismiss = { showFolderDeleteDialog = null },+ destructive = true,+ )+ }+}++@Composable+private fun BookmarkRow(+ bookmark: Bookmark,+ onClick: () -> Unit,+ onLongClick: () -> Unit,+) {+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .combinedClickable(onClick = onClick, onLongClick = onLongClick)+ .padding(horizontal = 16.dp, vertical = 12.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Surface(+ shape = CircleShape,+ color = MaterialTheme.colorScheme.secondaryContainer,+ modifier = Modifier.size(40.dp)+ ) {+ Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ Text(+ bookmark.title.take(1).uppercase().ifBlank { "B" },+ style = MaterialTheme.typography.titleSmall+ )+ }+ }+ Spacer(Modifier.width(12.dp))+ Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {+ Text(+ bookmark.title.ifBlank { bookmark.url },+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodyMedium+ )+ Text(+ BrowserUtils.prettyUrl(bookmark.url),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+ }+}
web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.ktindex 3f33322dc8..088e798c90 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt@@ -50,6 +50,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.ui.ExternalIntents import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults import com.vayunmathur.library.ui.CommonSearchBar@@ -157,43 +158,39 @@ fun BrowserPage( Box(Modifier.fillMaxSize()) { if (viewModel.omniboxFocused) {- Scaffold(- topBar = {- TopAppBar(- navigationIcon = {- IconButton(onClick = {+ AppScaffold(+ title = {+ OutlinedTextField(+ value = viewModel.searchDraft,+ onValueChange = { viewModel.searchDraft = it },+ modifier = Modifier+ .fillMaxWidth()+ .focusRequester(searchFocusRequester),+ placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+ leadingIcon = { IconSearch() },+ trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {+ {+ IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }+ }+ } else null,+ shape = RoundedCornerShape(28.dp),+ singleLine = true,+ keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),+ keyboardActions = KeyboardActions(onSearch = {+ if (viewModel.searchDraft.isNotBlank()) {+ viewModel.navigateActiveTab(viewModel.searchDraft) focusManager.clearFocus() viewModel.omniboxFocused = false- }) { IconBack() }- },- title = {- OutlinedTextField(- value = viewModel.searchDraft,- onValueChange = { viewModel.searchDraft = it },- modifier = Modifier- .fillMaxWidth()- .focusRequester(searchFocusRequester),- placeholder = { Text(stringResource(R.string.search_or_enter_address)) },- leadingIcon = { IconSearch() },- trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {- {- IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }- }- } else null,- shape = RoundedCornerShape(28.dp),- singleLine = true,- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),- keyboardActions = KeyboardActions(onSearch = {- if (viewModel.searchDraft.isNotBlank()) {- viewModel.navigateActiveTab(viewModel.searchDraft)- focusManager.clearFocus()- viewModel.omniboxFocused = false- }- })- )- }+ }+ }) )- }+ },+ navigationIcon = {+ IconButton(onClick = {+ focusManager.clearFocus()+ viewModel.omniboxFocused = false+ }) { IconBack() }+ }, ) { paddingValues -> LazyColumn( modifier = Modifier@@ -613,6 +610,12 @@ private fun BrowserChrome( menu: @Composable () -> Unit = {}, content: @Composable (PaddingValues) -> Unit, ) {+ // RAW SCAFFOLD EXCEPTION: bespoke browser toolbar chrome. The top bar is a+ // Column of a custom TopAppBar (back/forward nav row, a tappable read-only+ // address pill as the title, and shield + tab-count + overflow-menu actions+ // on a surface-colored bar) with a page LinearProgressIndicator drawn+ // underneath it. That composite bar has no equivalent in the shared+ // scaffolds, and the content is the full-bleed WebView. Scaffold( topBar = { Column {
web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.ktindex 743d6dcd34..a72041fa2e 100644--- a/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt@@ -1,98 +1,92 @@-package com.vayunmathur.web.ui--import androidx.compose.ui.res.stringResource-import com.vayunmathur.web.R-import kotlin.time.Clock-import kotlin.time.Instant-import kotlinx.datetime.LocalDateTime-import kotlinx.datetime.LocalTime-import kotlinx.datetime.TimeZone-import kotlinx.datetime.format-import kotlinx.datetime.format.char-import kotlinx.datetime.toLocalDateTime-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.material3.ExperimentalMaterial3Api-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconDelete-import com.vayunmathur.library.ui.IconDownload-import com.vayunmathur.library.ui.IconNavigation-import com.vayunmathur.library.ui.ListItem-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Scaffold-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TopAppBar-import com.vayunmathur.web.Route-import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.web.platform.WebViewModel--@OptIn(ExperimentalMaterial3Api::class)-@Composable-fun DownloadsPage(- viewModel: WebViewModel,- backStack: NavBackStack<Route>,-) {- val downloads by viewModel.downloads.collectAsStateWithLifecycle()-- Scaffold(- topBar = {- TopAppBar(- title = { Text(stringResource(R.string.downloads)) },- navigationIcon = { IconNavigation(backStack) },- actions = {- if (downloads.isNotEmpty()) {- IconButton(onClick = { viewModel.clearAllDownloads() }) { IconDelete() }- }- }- )- }- ) { paddingValues ->- if (downloads.isEmpty()) {- EmptyState(- title = stringResource(R.string.no_downloads),- modifier = Modifier.fillMaxSize().padding(paddingValues),- )- } else {- LazyColumn(Modifier.fillMaxSize().padding(paddingValues), verticalArrangement = Arrangement.spacedBy(2.dp)) {- items(downloads, key = { it.id }) { dl ->- ListItem(- headlineContent = { Text(dl.fileName, maxLines = 1, overflow = TextOverflow.Ellipsis) },- supportingContent = {- Column {- Text(dl.url, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall)- Text("${dl.mimeType ?: ""} • ${formatTime(dl.startedAt)}", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)- }- },- leadingContent = { IconDownload() }- )- }- }- }- }-}--private fun formatTime(millis: Long): String {- return try {- Instant.fromEpochMilliseconds(millis)- .toLocalDateTime(TimeZone.currentSystemDefault())- .format(- LocalDateTime.Format {- year(); char('-'); monthNumber(); char('-'); day()- char(' '); hour(); char(':'); minute()- },- )- } catch (_: Exception) { "" }-}+package com.vayunmathur.web.ui++import androidx.compose.ui.res.stringResource+import com.vayunmathur.web.R+import kotlin.time.Clock+import kotlin.time.Instant+import kotlinx.datetime.LocalDateTime+import kotlinx.datetime.LocalTime+import kotlinx.datetime.TimeZone+import kotlinx.datetime.format+import kotlinx.datetime.format.char+import kotlinx.datetime.toLocalDateTime+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.material3.ExperimentalMaterial3Api+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.lifecycle.compose.collectAsStateWithLifecycle+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconDownload+import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.web.Route+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.web.platform.WebViewModel++@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun DownloadsPage(+ viewModel: WebViewModel,+ backStack: NavBackStack<Route>,+) {+ val downloads by viewModel.downloads.collectAsStateWithLifecycle()++ AppScaffold(+ title = stringResource(R.string.downloads),+ backStack = backStack,+ actions = {+ if (downloads.isNotEmpty()) {+ IconButton(onClick = { viewModel.clearAllDownloads() }) { IconDelete() }+ }+ },+ ) { paddingValues ->+ if (downloads.isEmpty()) {+ EmptyState(+ title = stringResource(R.string.no_downloads),+ modifier = Modifier.fillMaxSize().padding(paddingValues),+ )+ } else {+ LazyColumn(Modifier.fillMaxSize().padding(paddingValues), verticalArrangement = Arrangement.spacedBy(2.dp)) {+ items(downloads, key = { it.id }) { dl ->+ ListItem(+ headlineContent = { Text(dl.fileName, maxLines = 1, overflow = TextOverflow.Ellipsis) },+ supportingContent = {+ Column {+ Text(dl.url, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall)+ Text("${dl.mimeType ?: ""} • ${formatTime(dl.startedAt)}", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)+ }+ },+ leadingContent = { IconDownload() }+ )+ }+ }+ }+ }+}++private fun formatTime(millis: Long): String {+ return try {+ Instant.fromEpochMilliseconds(millis)+ .toLocalDateTime(TimeZone.currentSystemDefault())+ .format(+ LocalDateTime.Format {+ year(); char('-'); monthNumber(); char('-'); day()+ char(' '); hour(); char(':'); minute()+ },+ )+ } catch (_: Exception) { "" }+}
web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt b/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.ktindex 05d9cc4043..35c241a3a2 100644--- a/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt@@ -1,203 +1,197 @@-package com.vayunmathur.web.ui--import androidx.compose.ui.res.stringResource-import com.vayunmathur.web.R-import android.content.Context-import android.text.format.DateFormat-import android.text.format.DateUtils-import androidx.compose.ui.platform.LocalContext-import java.util.Date-import kotlin.time.Clock-import kotlin.time.Instant-import kotlinx.datetime.LocalDateTime-import kotlinx.datetime.LocalTime-import kotlinx.datetime.format-import kotlinx.datetime.format.char-import androidx.compose.foundation.ExperimentalFoundationApi-import androidx.compose.foundation.background-import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.clip-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import com.vayunmathur.library.ui.R as UiR-import com.vayunmathur.library.ui.ConfirmDialog-import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconDelete-import com.vayunmathur.library.ui.IconNavigation-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Scaffold-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton-import com.vayunmathur.library.ui.TopAppBar-import com.vayunmathur.web.Route-import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.web.data.HistoryEntry-import com.vayunmathur.web.platform.BrowserUtils-import com.vayunmathur.web.platform.WebViewModel-import kotlinx.datetime.TimeZone-import kotlinx.datetime.toLocalDateTime--@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)-@Composable-fun HistoryPage(- viewModel: WebViewModel,- backStack: NavBackStack<Route>,-) {- val history by viewModel.history.collectAsStateWithLifecycle()- var showClearConfirm by remember { mutableStateOf(false) }-- val context = LocalContext.current- val grouped = remember(history, context) {- groupByDate(context, history)- }-- Scaffold(- topBar = {- TopAppBar(- title = { Text(stringResource(R.string.history)) },- navigationIcon = { IconNavigation(backStack) },- actions = {- if (history.isNotEmpty()) {- IconButton(onClick = { showClearConfirm = true }) {- IconDelete()- }- }- }- )- }- ) { paddingValues ->- if (history.isEmpty()) {- EmptyState(- title = stringResource(R.string.no_history_yet),- modifier = Modifier.fillMaxSize().padding(paddingValues),- )- } else {- LazyColumn(- modifier = Modifier.fillMaxSize().padding(paddingValues),- verticalArrangement = Arrangement.spacedBy(2.dp)- ) {- grouped.forEach { (dateLabel, entries) ->- stickyHeader {- Text(- dateLabel,- style = MaterialTheme.typography.titleSmall,- color = MaterialTheme.colorScheme.onSurfaceVariant,- modifier = Modifier- .fillMaxWidth()- .background(MaterialTheme.colorScheme.surface)- .padding(horizontal = 16.dp, vertical = 8.dp)- )- }- items(entries, key = { it.id }) { entry ->- HistoryRow(- entry = entry,- onClick = {- viewModel.externalIntentUrl(entry.url)- backStack.pop()- }- )- }- }- }- }- }-- if (showClearConfirm) {- ConfirmDialog(- title = stringResource(R.string.clear_history),- message = stringResource(R.string.this_will_permanently_delete_your_browsi),- confirmLabel = stringResource(UiR.string.clear),- dismissLabel = stringResource(UiR.string.cancel),- onConfirm = { viewModel.clearHistory() },- onDismiss = { showClearConfirm = false },- destructive = true,- )- }-}--@Composable-private fun HistoryRow(- entry: HistoryEntry,- onClick: () -> Unit,-) {- Row(- modifier = Modifier- .fillMaxWidth()- .clip(RoundedCornerShape(0.dp))- .clickable(onClick = onClick)- .padding(horizontal = 16.dp, vertical = 12.dp),- verticalAlignment = Alignment.CenterVertically- ) {- Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {- Text(- entry.title.ifBlank { entry.url },- maxLines = 1,- overflow = TextOverflow.Ellipsis,- style = MaterialTheme.typography.bodyMedium- )- Text(- BrowserUtils.prettyUrl(entry.url),- maxLines = 1,- overflow = TextOverflow.Ellipsis,- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- }- Spacer(Modifier.width(8.dp))- Text(- formatTime(entry.visitedAt),- style = MaterialTheme.typography.labelSmall,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- }-}--private fun formatTime(millis: Long): String {- return try {- Instant.fromEpochMilliseconds(millis)- .toLocalDateTime(TimeZone.currentSystemDefault()).time- .format(LocalTime.Format { hour(); char(':'); minute() })- } catch (_: Exception) {- ""- }-}--private fun groupByDate(context: Context, entries: List<HistoryEntry>): List<Pair<String, List<HistoryEntry>>> {- val tz = TimeZone.currentSystemDefault()- val now = Instant.fromEpochMilliseconds(System.currentTimeMillis()).toLocalDateTime(tz).date- return entries.groupBy { entry ->- val date = Instant.fromEpochMilliseconds(entry.visitedAt).toLocalDateTime(tz).date- when (now.toEpochDays() - date.toEpochDays()) {- // DateUtils yields a localized "Today"/"Yesterday" in every locale Android ships.- 0L, 1L -> DateUtils.getRelativeTimeSpanString(- entry.visitedAt,- System.currentTimeMillis(),- DateUtils.DAY_IN_MILLIS,- ).toString()- else -> DateFormat.getMediumDateFormat(context).format(Date(entry.visitedAt))- }- }.toList()-}+package com.vayunmathur.web.ui++import androidx.compose.ui.res.stringResource+import com.vayunmathur.web.R+import android.content.Context+import android.text.format.DateFormat+import android.text.format.DateUtils+import androidx.compose.ui.platform.LocalContext+import java.util.Date+import kotlin.time.Clock+import kotlin.time.Instant+import kotlinx.datetime.LocalDateTime+import kotlinx.datetime.LocalTime+import kotlinx.datetime.format+import kotlinx.datetime.format.char+import androidx.compose.foundation.ExperimentalFoundationApi+import androidx.compose.foundation.background+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.lifecycle.compose.collectAsStateWithLifecycle+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.ConfirmDialog+import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.web.Route+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.web.data.HistoryEntry+import com.vayunmathur.web.platform.BrowserUtils+import com.vayunmathur.web.platform.WebViewModel+import kotlinx.datetime.TimeZone+import kotlinx.datetime.toLocalDateTime++@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)+@Composable+fun HistoryPage(+ viewModel: WebViewModel,+ backStack: NavBackStack<Route>,+) {+ val history by viewModel.history.collectAsStateWithLifecycle()+ var showClearConfirm by remember { mutableStateOf(false) }++ val context = LocalContext.current+ val grouped = remember(history, context) {+ groupByDate(context, history)+ }++ AppScaffold(+ title = stringResource(R.string.history),+ backStack = backStack,+ actions = {+ if (history.isNotEmpty()) {+ IconButton(onClick = { showClearConfirm = true }) {+ IconDelete()+ }+ }+ },+ ) { paddingValues ->+ if (history.isEmpty()) {+ EmptyState(+ title = stringResource(R.string.no_history_yet),+ modifier = Modifier.fillMaxSize().padding(paddingValues),+ )+ } else {+ LazyColumn(+ modifier = Modifier.fillMaxSize().padding(paddingValues),+ verticalArrangement = Arrangement.spacedBy(2.dp)+ ) {+ grouped.forEach { (dateLabel, entries) ->+ stickyHeader {+ Text(+ dateLabel,+ style = MaterialTheme.typography.titleSmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ modifier = Modifier+ .fillMaxWidth()+ .background(MaterialTheme.colorScheme.surface)+ .padding(horizontal = 16.dp, vertical = 8.dp)+ )+ }+ items(entries, key = { it.id }) { entry ->+ HistoryRow(+ entry = entry,+ onClick = {+ viewModel.externalIntentUrl(entry.url)+ backStack.pop()+ }+ )+ }+ }+ }+ }+ }++ if (showClearConfirm) {+ ConfirmDialog(+ title = stringResource(R.string.clear_history),+ message = stringResource(R.string.this_will_permanently_delete_your_browsi),+ confirmLabel = stringResource(UiR.string.clear),+ dismissLabel = stringResource(UiR.string.cancel),+ onConfirm = { viewModel.clearHistory() },+ onDismiss = { showClearConfirm = false },+ destructive = true,+ )+ }+}++@Composable+private fun HistoryRow(+ entry: HistoryEntry,+ onClick: () -> Unit,+) {+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .clip(RoundedCornerShape(0.dp))+ .clickable(onClick = onClick)+ .padding(horizontal = 16.dp, vertical = 12.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {+ Text(+ entry.title.ifBlank { entry.url },+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodyMedium+ )+ Text(+ BrowserUtils.prettyUrl(entry.url),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+ Spacer(Modifier.width(8.dp))+ Text(+ formatTime(entry.visitedAt),+ style = MaterialTheme.typography.labelSmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+}++private fun formatTime(millis: Long): String {+ return try {+ Instant.fromEpochMilliseconds(millis)+ .toLocalDateTime(TimeZone.currentSystemDefault()).time+ .format(LocalTime.Format { hour(); char(':'); minute() })+ } catch (_: Exception) {+ ""+ }+}++private fun groupByDate(context: Context, entries: List<HistoryEntry>): List<Pair<String, List<HistoryEntry>>> {+ val tz = TimeZone.currentSystemDefault()+ val now = Instant.fromEpochMilliseconds(System.currentTimeMillis()).toLocalDateTime(tz).date+ return entries.groupBy { entry ->+ val date = Instant.fromEpochMilliseconds(entry.visitedAt).toLocalDateTime(tz).date+ when (now.toEpochDays() - date.toEpochDays()) {+ // DateUtils yields a localized "Today"/"Yesterday" in every locale Android ships.+ 0L, 1L -> DateUtils.getRelativeTimeSpanString(+ entry.visitedAt,+ System.currentTimeMillis(),+ DateUtils.DAY_IN_MILLIS,+ ).toString()+ else -> DateFormat.getMediumDateFormat(context).format(Date(entry.visitedAt))+ }+ }.toList()+}
web/src/main/java/com/vayunmathur/web/ui/PermissionSheets.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/PermissionSheets.kt b/web/src/main/java/com/vayunmathur/web/ui/PermissionSheets.ktindex f2806479a9..de69f32cf4 100644--- a/web/src/main/java/com/vayunmathur/web/ui/PermissionSheets.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/PermissionSheets.kt@@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable@@ -37,8 +36,8 @@ import com.vayunmathur.library.ui.IconGlobe import com.vayunmathur.library.ui.IconLocationOn import com.vayunmathur.library.ui.IconMic import com.vayunmathur.library.ui.IconNavigation+import com.vayunmathur.library.ui.LazyListScaffold import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Scaffold import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton@@ -142,7 +141,9 @@ internal fun SiteDataPage( val storages by viewModel.storageInfos.collectAsStateWithLifecycle() val permissions by viewModel.sitePermissions.collectAsStateWithLifecycle() - Scaffold(+ LazyListScaffold(+ horizontalPadding = 12.dp,+ verticalArrangement = Arrangement.spacedBy(10.dp), topBar = { TopAppBar( title = { Text(stringResource(R.string.site_data)) },@@ -151,39 +152,34 @@ internal fun SiteDataPage( if (storages.isNotEmpty() || permissions.isNotEmpty()) { IconButton(onClick = { viewModel.clearAllSiteData() }) { IconDelete() } }- }+ }, )- }- ) { paddingValues ->- LazyColumn(- modifier = Modifier.fillMaxWidth().padding(paddingValues).padding(12.dp),- verticalArrangement = Arrangement.spacedBy(10.dp)- ) {- if (storages.isEmpty() && permissions.isEmpty()) {- item {- Text(- stringResource(R.string.no_site_data_yet_cookies_localstorage_in),- style = MaterialTheme.typography.bodyMedium,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- }+ },+ ) {+ if (storages.isEmpty() && permissions.isEmpty()) {+ item {+ Text(+ stringResource(R.string.no_site_data_yet_cookies_localstorage_in),+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ ) }+ } - if (storages.isNotEmpty()) {- item { Text(stringResource(R.string.storage), style = MaterialTheme.typography.titleMedium) }- items(storages, key = { it.id }) { info ->- StorageInfoCard(info, viewModel)- }+ if (storages.isNotEmpty()) {+ item { Text(stringResource(R.string.storage), style = MaterialTheme.typography.titleMedium) }+ items(storages, key = { it.id }) { info ->+ StorageInfoCard(info, viewModel) }+ } - if (permissions.isNotEmpty()) {- item {- Spacer(Modifier.height(8.dp))- Text(stringResource(R.string.permissions), style = MaterialTheme.typography.titleMedium)- }- items(permissions, key = { it.id }) { perm ->- PermissionInfoCard(perm, viewModel)- }+ if (permissions.isNotEmpty()) {+ item {+ Spacer(Modifier.height(8.dp))+ Text(stringResource(R.string.permissions), style = MaterialTheme.typography.titleMedium)+ }+ items(permissions, key = { it.id }) { perm ->+ PermissionInfoCard(perm, viewModel) } } }