Skip to content

Commit

Permalink
Use M3 menu drop for inbox unread sort (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV-GH authored Aug 8, 2023
1 parent 71d2684 commit 9a1f9b6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
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),
)
}
}

0 comments on commit 9a1f9b6

Please sign in to comment.