diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/notes/presentation/NoteListScreen.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/notes/presentation/NoteListScreen.kt index ee3c05e0..f0680fd3 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/notes/presentation/NoteListScreen.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/notes/presentation/NoteListScreen.kt @@ -10,7 +10,10 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.SegmentedButton +import androidx.compose.material3.SingleChoiceSegmentedButtonRow import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -46,8 +49,6 @@ import com.fibelatti.pinboard.features.appstate.SidePanelContent import com.fibelatti.pinboard.features.appstate.ViewNote import com.fibelatti.pinboard.features.notes.domain.model.Note import com.fibelatti.pinboard.features.notes.domain.model.NoteSorting -import com.fibelatti.ui.components.RowToggleButtonGroup -import com.fibelatti.ui.components.ToggleButtonGroup import com.fibelatti.ui.foundation.asHorizontalPaddingDp import com.fibelatti.ui.foundation.navigationBarsCompat import com.fibelatti.ui.preview.ThemePreviews @@ -145,6 +146,7 @@ fun NoteListScreen( } @Composable +@OptIn(ExperimentalMaterial3Api::class) private fun NoteListContent( notes: List, onSortOptionClicked: (NoteList.Sorting) -> Unit = {}, @@ -170,28 +172,43 @@ private fun NoteListContent( val (leftPadding, rightPadding) = WindowInsets.navigationBarsCompat .asHorizontalPaddingDp(addStart = 16.dp, addEnd = 16.dp) - RowToggleButtonGroup( - items = NoteList.Sorting.entries.map { sorting -> - ToggleButtonGroup.Item( - id = sorting.id, - text = stringResource(id = sorting.label), - ) - }, - onButtonClick = { - val (index, sorting) = requireNotNull(NoteList.Sorting.findByIdWithIndex(it.id)) - selectedSortingIndex = index - onSortOptionClicked(sorting) - }, + SingleChoiceSegmentedButtonRow( modifier = Modifier .fillMaxWidth() .padding( start = leftPadding, end = if (sidePanelVisible) 16.dp else rightPadding, ), - selectedIndex = selectedSortingIndex, - buttonHeight = 40.dp, - textStyle = MaterialTheme.typography.bodySmall, - ) + ) { + NoteList.Sorting.entries.forEachIndexed { index, sorting -> + SegmentedButton( + selected = index == selectedSortingIndex, + onClick = { + selectedSortingIndex = index + onSortOptionClicked(sorting) + }, + shape = when (index) { + 0 -> RoundedCornerShape( + topStart = 16.dp, + bottomStart = 16.dp, + ) + + NoteList.Sorting.entries.size - 1 -> RoundedCornerShape( + topEnd = 16.dp, + bottomEnd = 16.dp, + ) + + else -> RoundedCornerShape(0.dp) + }, + label = { + Text( + text = stringResource(id = sorting.label), + style = MaterialTheme.typography.bodySmall, + ) + }, + ) + } + } val (listLeftPadding, listRightPadding) = WindowInsets.navigationBarsCompat.asHorizontalPaddingDp() @@ -258,18 +275,11 @@ private fun NoteListItem( object NoteList { - enum class Sorting(val id: String, val label: Int) { - ByDateUpdatedDesc(id = "date-updated-desc", label = R.string.note_sorting_date_updated_desc), - ByDateUpdatedAsc(id = "date-updated-asc", label = R.string.note_sorting_date_updated_asc), - AtoZ(id = "a-to-z", label = R.string.note_sorting_a_to_z), + enum class Sorting(val label: Int) { + ByDateUpdatedDesc(label = R.string.note_sorting_date_updated_desc), + ByDateUpdatedAsc(label = R.string.note_sorting_date_updated_asc), + AtoZ(label = R.string.note_sorting_a_to_z), ; - - companion object { - - fun findByIdWithIndex(id: String): IndexedValue? = entries - .withIndex() - .find { it.value.id == id } - } } } diff --git a/app/src/main/kotlin/com/fibelatti/pinboard/features/tags/presentation/TagList.kt b/app/src/main/kotlin/com/fibelatti/pinboard/features/tags/presentation/TagList.kt index 60a1da46..5164e52c 100644 --- a/app/src/main/kotlin/com/fibelatti/pinboard/features/tags/presentation/TagList.kt +++ b/app/src/main/kotlin/com/fibelatti/pinboard/features/tags/presentation/TagList.kt @@ -25,11 +25,14 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.SegmentedButton +import androidx.compose.material3.SingleChoiceSegmentedButtonRow import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -69,8 +72,6 @@ import com.fibelatti.pinboard.features.appstate.PostsForTag import com.fibelatti.pinboard.features.appstate.RefreshTags import com.fibelatti.pinboard.features.tags.domain.model.Tag import com.fibelatti.pinboard.features.tags.domain.model.TagSorting -import com.fibelatti.ui.components.RowToggleButtonGroup -import com.fibelatti.ui.components.ToggleButtonGroup import com.fibelatti.ui.foundation.asHorizontalPaddingDp import com.fibelatti.ui.foundation.imeCompat import com.fibelatti.ui.foundation.navigationBarsCompat @@ -257,6 +258,7 @@ fun TagList( } @Composable +@OptIn(ExperimentalMaterial3Api::class) private fun TagListSortingControls( onSortOptionClicked: (TagList.Sorting) -> Unit, onSearchInputChanged: (newValue: String) -> Unit, @@ -272,32 +274,47 @@ private fun TagListSortingControls( var showFilter by rememberSaveable { mutableStateOf(false) } val focusManager = LocalFocusManager.current - RowToggleButtonGroup( - items = TagList.Sorting.entries.map { sorting -> - ToggleButtonGroup.Item( - id = sorting.id, - text = stringResource(id = sorting.label), - ) - }, - onButtonClick = { - val (index, sorting) = requireNotNull(TagList.Sorting.findByIdWithIndex(it.id)) - selectedSortingIndex = index - showFilter = sorting == TagList.Sorting.Search - - onSortOptionClicked(sorting) - - if (!showFilter) { - onSearchInputChanged("") - onSearchInputFocusChanged(false) - } - }, + SingleChoiceSegmentedButtonRow( modifier = Modifier .fillMaxWidth() .padding(horizontal = 16.dp), - selectedIndex = selectedSortingIndex, - buttonHeight = 40.dp, - textStyle = MaterialTheme.typography.bodySmall, - ) + ) { + TagList.Sorting.entries.forEachIndexed { index, sorting -> + SegmentedButton( + selected = index == selectedSortingIndex, + onClick = { + selectedSortingIndex = index + showFilter = sorting == TagList.Sorting.Search + + onSortOptionClicked(sorting) + + if (!showFilter) { + onSearchInputChanged("") + onSearchInputFocusChanged(false) + } + }, + shape = when (index) { + 0 -> RoundedCornerShape( + topStart = 16.dp, + bottomStart = 16.dp, + ) + + TagList.Sorting.entries.size - 1 -> RoundedCornerShape( + topEnd = 16.dp, + bottomEnd = 16.dp, + ) + + else -> RoundedCornerShape(0.dp) + }, + label = { + Text( + text = stringResource(id = sorting.label), + style = MaterialTheme.typography.bodySmall, + ) + }, + ) + } + } AnimatedVisibility( visible = showFilter, @@ -382,20 +399,13 @@ private fun ScrollToTopButton( object TagList { - enum class Sorting(val id: String, val label: Int) { + enum class Sorting(val label: Int) { - Alphabetically(id = "alphabetically", label = R.string.tags_sorting_a_to_z), - MoreFirst(id = "more-first", label = R.string.tags_sorting_more_first), - LessFirst(id = "less-first", label = R.string.tags_sorting_less_first), - Search(id = "search", label = R.string.tags_sorting_filter), + Alphabetically(label = R.string.tags_sorting_a_to_z), + MoreFirst(label = R.string.tags_sorting_more_first), + LessFirst(label = R.string.tags_sorting_less_first), + Search(label = R.string.tags_sorting_filter), ; - - companion object { - - fun findByIdWithIndex(id: String): IndexedValue? = entries - .withIndex() - .find { it.value.id == id } - } } }