Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use M3 menu dropdown for inbox unread sort #1152

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import androidx.compose.material.icons.outlined.BarChart
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.MarkunreadMailbox
import androidx.compose.material.icons.outlined.Moving
import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material3.AlertDialog
Expand All @@ -36,7 +34,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.SortType
Expand Down Expand Up @@ -205,34 +202,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(
Expand Down
68 changes: 50 additions & 18 deletions app/src/main/java/com/jerboa/ui/components/inbox/Inbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down Expand Up @@ -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),
)
}
}