kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Clearer node filter options (#3250)
rodzic
6abe0124d2
commit
cf59033c49
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package com.geeksville.mesh.ui.node.components
|
package com.geeksville.mesh.ui.node.components
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
@ -25,8 +24,10 @@ import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.defaultMinSize
|
import androidx.compose.foundation.layout.defaultMinSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
@ -34,13 +35,16 @@ import androidx.compose.material.icons.automirrored.filled.Sort
|
||||||
import androidx.compose.material.icons.filled.Clear
|
import androidx.compose.material.icons.filled.Clear
|
||||||
import androidx.compose.material.icons.filled.Done
|
import androidx.compose.material.icons.filled.Done
|
||||||
import androidx.compose.material.icons.filled.Search
|
import androidx.compose.material.icons.filled.Search
|
||||||
|
import androidx.compose.material3.Checkbox
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MenuDefaults
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
@ -54,6 +58,7 @@ import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.PreviewLightDark
|
import androidx.compose.ui.tooling.preview.PreviewLightDark
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.geeksville.mesh.ui.common.preview.LargeFontPreview
|
import com.geeksville.mesh.ui.common.preview.LargeFontPreview
|
||||||
|
@ -184,104 +189,94 @@ private fun NodeSortButton(
|
||||||
onDismissRequest = { expanded = false },
|
onDismissRequest = { expanded = false },
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = 1f)),
|
modifier = Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = 1f)),
|
||||||
) {
|
) {
|
||||||
|
DropdownMenuTitle(text = stringResource(R.string.node_sort_title))
|
||||||
|
|
||||||
NodeSortOption.entries.forEach { sort ->
|
NodeSortOption.entries.forEach { sort ->
|
||||||
DropdownMenuItem(
|
DropdownMenuRadio(
|
||||||
onClick = {
|
text = stringResource(id = sort.stringRes),
|
||||||
onSortSelect(sort)
|
selected = sort == currentSortOption,
|
||||||
expanded = false
|
onClick = { onSortSelect(sort) },
|
||||||
},
|
|
||||||
text = {
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = sort.stringRes),
|
|
||||||
fontWeight = if (sort == currentSortOption) FontWeight.ExtraBold else null,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
HorizontalDivider()
|
|
||||||
DropdownMenuItem(
|
HorizontalDivider(modifier = Modifier.padding(MenuDefaults.DropdownMenuItemContentPadding))
|
||||||
onClick = {
|
|
||||||
toggles.onToggleIncludeUnknown()
|
DropdownMenuTitle(text = stringResource(R.string.node_filter_title))
|
||||||
expanded = false
|
|
||||||
},
|
DropdownMenuCheck(
|
||||||
text = {
|
text = stringResource(R.string.node_filter_include_unknown),
|
||||||
Row {
|
checked = toggles.includeUnknown,
|
||||||
AnimatedVisibility(visible = toggles.includeUnknown) {
|
onClick = toggles.onToggleIncludeUnknown,
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Done,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.padding(end = 4.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(text = stringResource(id = R.string.node_filter_include_unknown))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
|
||||||
onClick = {
|
DropdownMenuCheck(
|
||||||
toggles.onToggleOnlyOnline()
|
text = stringResource(R.string.node_filter_only_online),
|
||||||
expanded = false
|
checked = toggles.onlyOnline,
|
||||||
},
|
onClick = toggles.onToggleOnlyOnline,
|
||||||
text = {
|
|
||||||
Row {
|
|
||||||
AnimatedVisibility(visible = toggles.onlyOnline) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Done,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.padding(end = 4.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(text = stringResource(id = R.string.node_filter_only_online))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
|
||||||
onClick = {
|
DropdownMenuCheck(
|
||||||
toggles.onToggleOnlyDirect()
|
text = stringResource(R.string.node_filter_only_direct),
|
||||||
expanded = false
|
checked = toggles.onlyDirect,
|
||||||
},
|
onClick = toggles.onToggleOnlyDirect,
|
||||||
text = {
|
|
||||||
Row {
|
|
||||||
AnimatedVisibility(visible = toggles.onlyDirect) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Done,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.padding(end = 4.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(text = stringResource(id = R.string.node_filter_only_direct))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
HorizontalDivider()
|
|
||||||
DropdownMenuItem(
|
DropdownMenuCheck(
|
||||||
onClick = {
|
text = stringResource(R.string.node_filter_show_ignored),
|
||||||
toggles.onToggleShowIgnored()
|
checked = toggles.showIgnored,
|
||||||
expanded = false
|
onClick = toggles.onToggleShowIgnored,
|
||||||
},
|
trailing =
|
||||||
text = {
|
if (toggles.ignoredNodeCount > 0) {
|
||||||
Row {
|
{
|
||||||
AnimatedVisibility(visible = toggles.showIgnored) {
|
Text(
|
||||||
Icon(
|
text = " (${toggles.ignoredNodeCount})",
|
||||||
imageVector = Icons.Default.Done,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
contentDescription = null,
|
modifier = Modifier.padding(start = 4.dp),
|
||||||
modifier = Modifier.padding(end = 4.dp),
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(text = stringResource(id = R.string.node_filter_show_ignored))
|
|
||||||
if (toggles.ignoredNodeCount > 0) {
|
|
||||||
Text(
|
|
||||||
text = " (${toggles.ignoredNodeCount})",
|
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.padding(start = 4.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DropdownMenuTitle(text: String) {
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
modifier =
|
||||||
|
Modifier.height(48.dp)
|
||||||
|
.padding(MenuDefaults.DropdownMenuItemContentPadding)
|
||||||
|
.wrapContentHeight(align = Alignment.CenterVertically),
|
||||||
|
fontWeight = FontWeight.ExtraBold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DropdownMenuRadio(text: String, selected: Boolean, onClick: () -> Unit) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = onClick,
|
||||||
|
leadingIcon = { RadioButton(selected = selected, onClick = null) },
|
||||||
|
text = { Text(text = text) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DropdownMenuCheck(
|
||||||
|
text: String,
|
||||||
|
checked: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
trailing: @Composable (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = onClick,
|
||||||
|
leadingIcon = { Checkbox(checked = checked, onCheckedChange = null) },
|
||||||
|
trailingIcon = trailing,
|
||||||
|
text = { Text(text = text) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@PreviewLightDark
|
@PreviewLightDark
|
||||||
@LargeFontPreview
|
@LargeFontPreview
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
@ -31,11 +31,13 @@
|
||||||
<string name="fallback_node_name">Meshtastic %s</string>
|
<string name="fallback_node_name">Meshtastic %s</string>
|
||||||
<string name="node_filter_placeholder">Filter</string>
|
<string name="node_filter_placeholder">Filter</string>
|
||||||
<string name="desc_node_filter_clear">clear node filter</string>
|
<string name="desc_node_filter_clear">clear node filter</string>
|
||||||
|
<string name="node_filter_title">Filter by</string>
|
||||||
<string name="node_filter_include_unknown">Include unknown</string>
|
<string name="node_filter_include_unknown">Include unknown</string>
|
||||||
<string name="node_filter_only_online">Hide offline nodes</string>
|
<string name="node_filter_only_online">Hide offline nodes</string>
|
||||||
<string name="node_filter_only_direct">Only show direct nodes</string>
|
<string name="node_filter_only_direct">Only show direct nodes</string>
|
||||||
<string name="node_filter_ignored">You are viewing ignored nodes,\nPress to return to the node list.</string>
|
<string name="node_filter_ignored">You are viewing ignored nodes,\nPress to return to the node list.</string>
|
||||||
<string name="node_filter_show_details">Show details</string>
|
<string name="node_filter_show_details">Show details</string>
|
||||||
|
<string name="node_sort_title">Sort by</string>
|
||||||
<string name="node_sort_button">Node sorting options</string>
|
<string name="node_sort_button">Node sorting options</string>
|
||||||
<string name="node_sort_alpha">A-Z</string>
|
<string name="node_sort_alpha">A-Z</string>
|
||||||
<string name="node_sort_channel">Channel</string>
|
<string name="node_sort_channel">Channel</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue