Skip to content

Commit 851ba4b

Browse files
Use segmented button for sort options
1 parent 975ba3c commit 851ba4b

3 files changed

Lines changed: 35 additions & 76 deletions

File tree

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.schabi.newpipe.local.history
22

3-
enum class SortKey {
4-
LAST_PLAYED,
5-
MOST_PLAYED
3+
import androidx.annotation.StringRes
4+
import org.schabi.newpipe.R
5+
6+
enum class SortKey(@StringRes val title: Int) {
7+
LAST_PLAYED(R.string.title_last_played),
8+
MOST_PLAYED(R.string.title_most_played)
69
}

app/src/main/java/org/schabi/newpipe/ui/screens/HistoryScreen.kt

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.schabi.newpipe.ui.screens
22

33
import android.content.res.Configuration
44
import androidx.compose.foundation.layout.Arrangement
5-
import androidx.compose.foundation.layout.Column
65
import androidx.compose.foundation.layout.ExperimentalLayoutApi
76
import androidx.compose.foundation.layout.FlowRow
87
import androidx.compose.foundation.layout.Row
@@ -15,19 +14,13 @@ import androidx.compose.material.icons.filled.Headphones
1514
import androidx.compose.material.icons.filled.PictureInPicture
1615
import androidx.compose.material3.AlertDialog
1716
import androidx.compose.material3.ExperimentalMaterial3Api
18-
import androidx.compose.material3.ExposedDropdownMenuBox
19-
import androidx.compose.material3.ExposedDropdownMenuDefaults
2017
import androidx.compose.material3.Icon
21-
import androidx.compose.material3.IconButton
22-
import androidx.compose.material3.MenuAnchorType
23-
import androidx.compose.material3.PlainTooltip
18+
import androidx.compose.material3.SegmentedButton
19+
import androidx.compose.material3.SegmentedButtonDefaults
20+
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
2421
import androidx.compose.material3.Surface
2522
import androidx.compose.material3.Text
2623
import androidx.compose.material3.TextButton
27-
import androidx.compose.material3.TextField
28-
import androidx.compose.material3.TooltipBox
29-
import androidx.compose.material3.TooltipDefaults
30-
import androidx.compose.material3.rememberTooltipState
3124
import androidx.compose.runtime.Composable
3225
import androidx.compose.runtime.getValue
3326
import androidx.compose.runtime.mutableStateOf
@@ -47,7 +40,6 @@ import org.schabi.newpipe.ktx.findFragmentActivity
4740
import org.schabi.newpipe.local.history.HistoryViewModel
4841
import org.schabi.newpipe.local.history.SortKey
4942
import org.schabi.newpipe.player.playqueue.SinglePlayQueue
50-
import org.schabi.newpipe.ui.components.common.DropdownTextMenuItem
5143
import org.schabi.newpipe.ui.components.common.IconButtonWithLabel
5244
import org.schabi.newpipe.ui.components.items.ItemList
5345
import org.schabi.newpipe.ui.theme.AppTheme
@@ -93,73 +85,23 @@ private fun HistoryHeader(
9385
onClickPlayAll: () -> Unit,
9486
onClickPopup: () -> Unit
9587
) {
96-
Column(
88+
FlowRow(
9789
modifier = Modifier
9890
.fillMaxWidth()
9991
.padding(12.dp),
10092
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically),
101-
horizontalAlignment = Alignment.CenterHorizontally,
93+
horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally),
10294
) {
103-
Row(verticalAlignment = Alignment.CenterVertically) {
104-
var expanded by remember { mutableStateOf(false) }
105-
val selected = when (sortKey) {
106-
SortKey.MOST_PLAYED -> R.string.title_most_played
107-
SortKey.LAST_PLAYED -> R.string.title_last_played
108-
}
109-
110-
ExposedDropdownMenuBox(
111-
expanded = expanded,
112-
onExpandedChange = { expanded = it },
113-
) {
114-
TextField(
115-
enabled = true,
116-
modifier = Modifier.menuAnchor(MenuAnchorType.PrimaryNotEditable),
117-
value = stringResource(selected),
118-
readOnly = true,
119-
onValueChange = {},
120-
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
121-
colors = ExposedDropdownMenuDefaults.textFieldColors(),
122-
label = { Text(text = stringResource(R.string.history_sort_label)) },
123-
)
124-
125-
ExposedDropdownMenu(
126-
expanded = expanded,
127-
onDismissRequest = { expanded = false },
95+
SingleChoiceSegmentedButtonRow {
96+
SortKey.entries.forEachIndexed { index, key ->
97+
SegmentedButton(
98+
selected = key == sortKey,
99+
onClick = { onSelectSortKey(key) },
100+
shape = SegmentedButtonDefaults
101+
.itemShape(index = index, count = SortKey.entries.size)
128102
) {
129-
DropdownTextMenuItem(
130-
text = R.string.title_most_played,
131-
onClick = {
132-
expanded = false
133-
onSelectSortKey(SortKey.MOST_PLAYED)
134-
},
135-
)
136-
DropdownTextMenuItem(
137-
text = R.string.title_last_played,
138-
onClick = {
139-
expanded = false
140-
onSelectSortKey(SortKey.LAST_PLAYED)
141-
},
142-
)
143-
}
144-
}
145-
146-
TooltipBox(
147-
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
148-
tooltip = {
149-
PlainTooltip { Text(text = stringResource(R.string.clear_views_history_title)) }
150-
},
151-
state = rememberTooltipState(),
152-
) {
153-
var openClearDialog by remember { mutableStateOf(false) }
154-
155-
IconButton(onClick = { openClearDialog = true }) {
156-
Icon(
157-
imageVector = Icons.Default.ClearAll,
158-
contentDescription = stringResource(R.string.clear_history_description),
159-
)
103+
Text(text = stringResource(key.title))
160104
}
161-
162-
ClearHistoryDialog(openClearDialog, onClickClear, onDismissRequest = { openClearDialog = false })
163105
}
164106
}
165107

@@ -181,6 +123,20 @@ private fun HistoryHeader(
181123
label = R.string.controls_popup_title,
182124
onClick = onClickPopup,
183125
)
126+
127+
var openClearDialog by remember { mutableStateOf(false) }
128+
129+
TextButton(onClick = { openClearDialog = true }) {
130+
Row(
131+
horizontalArrangement = Arrangement.spacedBy(4.dp),
132+
verticalAlignment = Alignment.CenterVertically,
133+
) {
134+
Icon(imageVector = Icons.Default.ClearAll, contentDescription = null)
135+
Text(text = stringResource(R.string.clear))
136+
}
137+
}
138+
139+
ClearHistoryDialog(openClearDialog, onClickClear, onDismissRequest = { openClearDialog = false })
184140
}
185141
}
186142
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@
389389
<string name="title_activity_history">History</string>
390390
<string name="action_history">History</string>
391391
<string name="delete_item_search_history">Do you want to delete this item from search history?</string>
392-
<string name="title_last_played">Last Played</string>
393-
<string name="title_most_played">Most Played</string>
392+
<string name="title_last_played">Date</string>
393+
<string name="title_most_played">Views</string>
394394
<!-- Content -->
395395
<string name="main_page_content">Content of main page</string>
396396
<string name="main_page_content_summary">What tabs are shown on the main page</string>

0 commit comments

Comments
 (0)