diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index 1810b6ef..cd5cd728 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -35,6 +35,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.twotone.Check import androidx.compose.material.icons.twotone.Close import androidx.compose.material.ButtonDefaults +import androidx.compose.material.icons.twotone.ContentCopy import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState @@ -50,7 +51,6 @@ import androidx.compose.runtime.toMutableStateList import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter -import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.LocalClipboardManager @@ -410,10 +410,10 @@ fun ChannelScreen( } }) { Icon( - painter = when { - isError -> rememberVectorPainter(Icons.TwoTone.Close) - !isUrlEqual -> rememberVectorPainter(Icons.TwoTone.Check) - else -> painterResource(R.drawable.ic_twotone_content_copy_24) + imageVector = when { + isError -> Icons.TwoTone.Close + !isUrlEqual -> Icons.TwoTone.Check + else -> Icons.TwoTone.ContentCopy }, contentDescription = when { isError -> "Error" diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/EditBase64Preference.kt b/app/src/main/java/com/geeksville/mesh/ui/components/EditBase64Preference.kt index f419d43f..3a2f1cdc 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/EditBase64Preference.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/EditBase64Preference.kt @@ -41,6 +41,7 @@ fun EditBase64Preference( keyboardActions: KeyboardActions, onValueChange: (ByteString) -> Unit, modifier: Modifier = Modifier, + onGenerateKey: (() -> Unit)? = null, ) { fun ByteString.encodeToString() = Base64.encodeToString(this.toByteArray(), Base64.NO_WRAP) fun String.toByteString() = Base64.decode(this, Base64.NO_WRAP).toByteString() @@ -56,6 +57,12 @@ fun EditBase64Preference( } } + val (icon, description) = when { + isError -> Icons.TwoTone.Close to stringResource(R.string.error) + onGenerateKey != null && !isFocused -> Icons.TwoTone.Refresh to stringResource(R.string.reset) + else -> null to null + } + OutlinedTextField( value = valueState, onValueChange = { @@ -75,14 +82,18 @@ fun EditBase64Preference( trailingIcon = { IconButton( onClick = { - val psk = if (isError) value else Channel.getRandomKey() - valueState = psk.encodeToString() - onValueChange(psk) - } + if (isError) { + valueState = value.encodeToString() + onValueChange(value) + } else if (onGenerateKey != null && !isFocused) { + onGenerateKey() + } + }, + enabled = enabled, ) { Icon( - imageVector = if (isError) Icons.TwoTone.Close else Icons.TwoTone.Refresh, - contentDescription = stringResource(if (isError) R.string.error else R.string.reset), + imageVector = icon ?: return@IconButton, + contentDescription = description, tint = if (isError) MaterialTheme.colors.error else LocalContentColor.current.copy(alpha = LocalContentAlpha.current) ) @@ -100,6 +111,7 @@ private fun EditBase64PreferencePreview() { enabled = true, keyboardActions = KeyboardActions {}, onValueChange = {}, + onGenerateKey = {}, modifier = Modifier.padding(16.dp) ) } diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt index 649d772a..b1126fb6 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt @@ -67,7 +67,7 @@ fun EditChannelDialog( keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), onValueChanged = { channelInput = channelInput.copy { - name = it + name = it.trim() if (psk == Channel.default.settings.psk) psk = Channel.getRandomKey() } }, @@ -85,6 +85,9 @@ fun EditChannelDialog( channelInput = channelInput.copy { psk = it } } }, + onGenerateKey = { + channelInput = channelInput.copy { psk = Channel.getRandomKey() } + }, ) SwitchPreference( @@ -137,7 +140,7 @@ fun EditChannelDialog( .fillMaxWidth() .weight(1f), onClick = { - onAddClick(channelInput.copy { name = channelInput.name.trim() }) + onAddClick(channelInput) }, enabled = true, ) { Text(stringResource(R.string.save)) } diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/SecurityConfigItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/SecurityConfigItemList.kt index bab18365..0ec62933 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/SecurityConfigItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/SecurityConfigItemList.kt @@ -42,7 +42,9 @@ fun SecurityConfigItemList( enabled = enabled, keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), onValueChange = { - securityInput = securityInput.copy { publicKey = it } + if (it.size() == 32) { + securityInput = securityInput.copy { publicKey = it } + } }, ) } @@ -54,7 +56,9 @@ fun SecurityConfigItemList( enabled = enabled, keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), onValueChange = { - securityInput = securityInput.copy { privateKey = it } + if (it.size() == 32) { + securityInput = securityInput.copy { privateKey = it } + } }, ) } @@ -66,9 +70,11 @@ fun SecurityConfigItemList( enabled = enabled, keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }), onValueChange = { - securityInput = securityInput.copy { - adminKey.clear() - adminKey.add(it) + if (it.size() == 32) { + securityInput = securityInput.copy { + adminKey.clear() + adminKey.add(it) + } } }, ) diff --git a/app/src/main/res/drawable/ic_twotone_content_copy_24.xml b/app/src/main/res/drawable/ic_twotone_content_copy_24.xml deleted file mode 100644 index bf15de1e..00000000 --- a/app/src/main/res/drawable/ic_twotone_content_copy_24.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -