|
| 1 | +package me.nanova.summaryexpressive.ui.page.settings.search |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.layout.Arrangement |
| 5 | +import androidx.compose.foundation.layout.Box |
| 6 | +import androidx.compose.foundation.layout.Column |
| 7 | +import androidx.compose.foundation.layout.Row |
| 8 | +import androidx.compose.foundation.layout.Spacer |
| 9 | +import androidx.compose.foundation.layout.fillMaxHeight |
| 10 | +import androidx.compose.foundation.layout.fillMaxSize |
| 11 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 12 | +import androidx.compose.foundation.layout.height |
| 13 | +import androidx.compose.foundation.layout.padding |
| 14 | +import androidx.compose.foundation.layout.size |
| 15 | +import androidx.compose.foundation.layout.width |
| 16 | +import androidx.compose.foundation.shape.CircleShape |
| 17 | +import androidx.compose.foundation.text.BasicTextField |
| 18 | +import androidx.compose.material.icons.Icons |
| 19 | +import androidx.compose.material.icons.rounded.Close |
| 20 | +import androidx.compose.material.icons.rounded.Search |
| 21 | +import androidx.compose.material.icons.rounded.SearchOff |
| 22 | +import androidx.compose.material3.Icon |
| 23 | +import androidx.compose.material3.IconButton |
| 24 | +import androidx.compose.material3.MaterialTheme |
| 25 | +import androidx.compose.material3.Surface |
| 26 | +import androidx.compose.material3.Text |
| 27 | +import androidx.compose.runtime.Composable |
| 28 | +import androidx.compose.ui.Alignment |
| 29 | +import androidx.compose.ui.Alignment.Companion.CenterHorizontally |
| 30 | +import androidx.compose.ui.Modifier |
| 31 | +import androidx.compose.ui.graphics.SolidColor |
| 32 | +import androidx.compose.ui.res.stringResource |
| 33 | +import androidx.compose.ui.text.font.FontWeight |
| 34 | +import androidx.compose.ui.text.style.TextAlign |
| 35 | +import androidx.compose.ui.unit.dp |
| 36 | +import me.nanova.summaryexpressive.R |
| 37 | + |
| 38 | +/** |
| 39 | + * Android 16 Pill Search Bar |
| 40 | + */ |
| 41 | +@Composable |
| 42 | +fun SettingsSearchBar( |
| 43 | + query: String, |
| 44 | + onQueryChange: (String) -> Unit, |
| 45 | + onClear: () -> Unit, |
| 46 | + modifier: Modifier = Modifier, |
| 47 | +) { |
| 48 | + Surface( |
| 49 | + modifier = modifier |
| 50 | + .fillMaxWidth() |
| 51 | + .padding(bottom = 2.dp), |
| 52 | + shape = CircleShape, |
| 53 | + color = MaterialTheme.colorScheme.surfaceContainerHigh, |
| 54 | + tonalElevation = 1.dp |
| 55 | + ) { |
| 56 | + Row( |
| 57 | + modifier = Modifier |
| 58 | + .fillMaxWidth() |
| 59 | + .height(54.dp) |
| 60 | + .padding(horizontal = 16.dp), |
| 61 | + verticalAlignment = Alignment.CenterVertically |
| 62 | + ) { |
| 63 | + Icon( |
| 64 | + imageVector = Icons.Rounded.Search, |
| 65 | + contentDescription = stringResource(R.string.search), |
| 66 | + tint = MaterialTheme.colorScheme.onSurfaceVariant, |
| 67 | + modifier = Modifier.size(22.dp) |
| 68 | + ) |
| 69 | + Spacer(modifier = Modifier.width(12.dp)) |
| 70 | + BasicTextField( |
| 71 | + value = query, |
| 72 | + onValueChange = onQueryChange, |
| 73 | + modifier = Modifier |
| 74 | + .weight(1f) |
| 75 | + .fillMaxHeight(), |
| 76 | + textStyle = MaterialTheme.typography.bodyLarge.copy( |
| 77 | + color = MaterialTheme.colorScheme.onSurface |
| 78 | + ), |
| 79 | + singleLine = true, |
| 80 | + cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), |
| 81 | + decorationBox = { innerTextField -> |
| 82 | + Box( |
| 83 | + modifier = Modifier.fillMaxSize(), |
| 84 | + contentAlignment = Alignment.CenterStart |
| 85 | + ) { |
| 86 | + if (query.isEmpty()) { |
| 87 | + Text( |
| 88 | + text = stringResource(R.string.searchSettings), |
| 89 | + style = MaterialTheme.typography.bodyLarge, |
| 90 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 91 | + ) |
| 92 | + } |
| 93 | + innerTextField() |
| 94 | + } |
| 95 | + } |
| 96 | + ) |
| 97 | + if (query.isNotEmpty()) { |
| 98 | + IconButton( |
| 99 | + onClick = onClear, |
| 100 | + modifier = Modifier.size(36.dp) |
| 101 | + ) { |
| 102 | + Icon( |
| 103 | + imageVector = Icons.Rounded.Close, |
| 104 | + contentDescription = "Clear", |
| 105 | + tint = MaterialTheme.colorScheme.onSurfaceVariant, |
| 106 | + modifier = Modifier.size(20.dp) |
| 107 | + ) |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +/** |
| 115 | + * Empty search results state |
| 116 | + */ |
| 117 | +@Composable |
| 118 | +fun SettingsEmptySearchResults( |
| 119 | + query: String, |
| 120 | + modifier: Modifier = Modifier, |
| 121 | +) { |
| 122 | + Column( |
| 123 | + modifier = modifier |
| 124 | + .fillMaxWidth() |
| 125 | + .padding(vertical = 48.dp), |
| 126 | + horizontalAlignment = CenterHorizontally, |
| 127 | + verticalArrangement = Arrangement.spacedBy(12.dp) |
| 128 | + ) { |
| 129 | + Box( |
| 130 | + modifier = Modifier |
| 131 | + .size(56.dp) |
| 132 | + .background( |
| 133 | + color = MaterialTheme.colorScheme.surfaceContainerHighest, |
| 134 | + shape = CircleShape |
| 135 | + ), |
| 136 | + contentAlignment = Alignment.Center |
| 137 | + ) { |
| 138 | + Icon( |
| 139 | + imageVector = Icons.Rounded.SearchOff, |
| 140 | + contentDescription = null, |
| 141 | + tint = MaterialTheme.colorScheme.onSurfaceVariant, |
| 142 | + modifier = Modifier.size(28.dp) |
| 143 | + ) |
| 144 | + } |
| 145 | + Text( |
| 146 | + text = stringResource(id = R.string.nothingFound), |
| 147 | + style = MaterialTheme.typography.titleMedium, |
| 148 | + fontWeight = FontWeight.SemiBold, |
| 149 | + color = MaterialTheme.colorScheme.onSurface |
| 150 | + ) |
| 151 | + Text( |
| 152 | + text = "\"$query\"", |
| 153 | + style = MaterialTheme.typography.bodyMedium, |
| 154 | + color = MaterialTheme.colorScheme.onSurfaceVariant, |
| 155 | + textAlign = TextAlign.Center |
| 156 | + ) |
| 157 | + } |
| 158 | +} |
0 commit comments