From ecc925226918276983c399dd049f6fb7b8ea258e Mon Sep 17 00:00:00 2001 From: "maarten.vercruysse" Date: Mon, 7 Aug 2023 12:36:38 +0200 Subject: [PATCH] Use M3 menu drop for inbox unread sort --- .../jerboa/ui/components/common/Dialogs.kt | 31 --------- .../ui/components/common/DropdownMenu.kt | 21 ++++++ .../com/jerboa/ui/components/inbox/Inbox.kt | 68 ++++++++++++++----- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt b/app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt index 4f124bf8c..009b3580a 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt @@ -11,10 +11,8 @@ import androidx.compose.material.icons.outlined.Bookmarks import androidx.compose.material.icons.outlined.BrightnessLow import androidx.compose.material.icons.outlined.FormatListNumbered import androidx.compose.material.icons.outlined.History -import androidx.compose.material.icons.outlined.List import androidx.compose.material.icons.outlined.LocalFireDepartment import androidx.compose.material.icons.outlined.LocationCity -import androidx.compose.material.icons.outlined.MarkunreadMailbox import androidx.compose.material.icons.outlined.Moving import androidx.compose.material.icons.outlined.NewReleases import androidx.compose.material.icons.outlined.Public @@ -39,7 +37,6 @@ import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.tooling.preview.Preview import com.jerboa.PostViewMode import com.jerboa.R -import com.jerboa.UnreadOrAll import com.jerboa.api.MINIMUM_API_VERSION import com.jerboa.datatypes.types.CommentSortType import com.jerboa.datatypes.types.ListingType @@ -244,34 +241,6 @@ fun CommentSortOptionsDialog( ) } -@Composable -fun UnreadOrAllOptionsDialog( - onDismissRequest: () -> Unit, - onClickUnreadOrAll: (UnreadOrAll) -> Unit, - selectedUnreadOrAll: UnreadOrAll, -) { - AlertDialog( - onDismissRequest = onDismissRequest, - text = { - Column { - IconAndTextDrawerItem( - text = stringResource(R.string.dialogs_all), - icon = Icons.Outlined.List, - onClick = { onClickUnreadOrAll(UnreadOrAll.All) }, - highlight = (selectedUnreadOrAll == UnreadOrAll.All), - ) - IconAndTextDrawerItem( - text = stringResource(R.string.dialogs_unread), - icon = Icons.Outlined.MarkunreadMailbox, - onClick = { onClickUnreadOrAll(UnreadOrAll.Unread) }, - highlight = (selectedUnreadOrAll == UnreadOrAll.Unread), - ) - } - }, - confirmButton = {}, - ) -} - @OptIn(ExperimentalComposeUiApi::class) @Composable fun PostViewModeDialog( diff --git a/app/src/main/java/com/jerboa/ui/components/common/DropdownMenu.kt b/app/src/main/java/com/jerboa/ui/components/common/DropdownMenu.kt index 58c8fc776..f81579e33 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/DropdownMenu.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/DropdownMenu.kt @@ -1,5 +1,6 @@ package com.jerboa.ui.components.common +import androidx.compose.foundation.background import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -34,3 +35,23 @@ fun MenuItem( modifier = modifier, ) } + +@Composable +fun MenuItem( + text: String, + modifier: Modifier = Modifier, + icon: ImageVector? = null, + onClick: () -> Unit, + highlight: Boolean, +) { + MenuItem( + text = text, + icon = icon, + onClick = onClick, + modifier = if (highlight) { + modifier.background(MaterialTheme.colorScheme.onBackground.copy(alpha = .1f)) + } else { + modifier + }, + ) +} diff --git a/app/src/main/java/com/jerboa/ui/components/inbox/Inbox.kt b/app/src/main/java/com/jerboa/ui/components/inbox/Inbox.kt index 70f73d156..5ce973c51 100644 --- a/app/src/main/java/com/jerboa/ui/components/inbox/Inbox.kt +++ b/app/src/main/java/com/jerboa/ui/components/inbox/Inbox.kt @@ -2,11 +2,15 @@ package com.jerboa.ui.components.inbox +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DoneAll import androidx.compose.material.icons.outlined.FilterList +import androidx.compose.material.icons.outlined.List +import androidx.compose.material.icons.outlined.MarkunreadMailbox import androidx.compose.material.icons.outlined.Menu +import androidx.compose.material3.DropdownMenu import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -24,7 +28,7 @@ import androidx.compose.ui.res.stringResource import com.jerboa.R import com.jerboa.UnreadOrAll import com.jerboa.getLocalizedUnreadOrAllName -import com.jerboa.ui.components.common.UnreadOrAllOptionsDialog +import com.jerboa.ui.components.common.MenuItem @Composable fun InboxHeader( @@ -37,17 +41,6 @@ fun InboxHeader( ) { var showUnreadOrAllOptions by remember { mutableStateOf(false) } - if (showUnreadOrAllOptions) { - UnreadOrAllOptionsDialog( - selectedUnreadOrAll = selectedUnreadOrAll, - onDismissRequest = { showUnreadOrAllOptions = false }, - onClickUnreadOrAll = { - showUnreadOrAllOptions = false - onClickUnreadOrAll(it) - }, - ) - } - TopAppBar( scrollBehavior = scrollBehavior, title = { @@ -65,14 +58,27 @@ fun InboxHeader( } }, actions = { - IconButton(onClick = { - showUnreadOrAllOptions = !showUnreadOrAllOptions - }) { - Icon( - Icons.Outlined.FilterList, - contentDescription = stringResource(R.string.inbox_filter), + Box { + IconButton(onClick = { + showUnreadOrAllOptions = !showUnreadOrAllOptions + }) { + Icon( + Icons.Outlined.FilterList, + contentDescription = stringResource(R.string.inbox_filter), + ) + } + + UnreadOrAllOptionsDropDown( + expanded = showUnreadOrAllOptions, + selectedUnreadOrAll = selectedUnreadOrAll, + onDismissRequest = { showUnreadOrAllOptions = false }, + onClickUnreadOrAll = { + showUnreadOrAllOptions = false + onClickUnreadOrAll(it) + }, ) } + IconButton(onClick = onClickMarkAllAsRead) { Icon( Icons.Outlined.DoneAll, @@ -101,3 +107,29 @@ fun InboxHeaderTitle(selectedUnreadOrAll: UnreadOrAll, unreadCount: Int? = null) ) } } + +@Composable +fun UnreadOrAllOptionsDropDown( + expanded: Boolean, + onDismissRequest: () -> Unit, + onClickUnreadOrAll: (UnreadOrAll) -> Unit, + selectedUnreadOrAll: UnreadOrAll, +) { + DropdownMenu( + expanded = expanded, + onDismissRequest = onDismissRequest, + ) { + MenuItem( + text = stringResource(R.string.dialogs_all), + icon = Icons.Outlined.List, + onClick = { onClickUnreadOrAll(UnreadOrAll.All) }, + highlight = (selectedUnreadOrAll == UnreadOrAll.All), + ) + MenuItem( + text = stringResource(R.string.dialogs_unread), + icon = Icons.Outlined.MarkunreadMailbox, + onClick = { onClickUnreadOrAll(UnreadOrAll.Unread) }, + highlight = (selectedUnreadOrAll == UnreadOrAll.Unread), + ) + } +}