refactor: drop two over-engineered seams (enum + stdlib Base64) (#5945)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
James Rich
2026-06-25 05:34:53 -05:00
committed by GitHub
parent 40627fb02a
commit ab07347e5a
5 changed files with 9 additions and 37 deletions

View File

@@ -1,28 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.common.util
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
/** Pure Kotlin Base64 utility — no expect/actual needed. */
@OptIn(ExperimentalEncodingApi::class)
object Base64Factory {
fun encode(data: ByteArray): String = Base64.Default.encode(data)
fun decode(data: String): ByteArray = Base64.Default.decode(data)
}

View File

@@ -24,10 +24,9 @@ import kotlinx.coroutines.flow.MutableSharedFlow
* Event emitted when a user re-presses a bottom navigation destination that should trigger a scroll-to-top behaviour on
* the corresponding screen.
*/
sealed class ScrollToTopEvent {
data object NodesTabPressed : ScrollToTopEvent()
data object ConversationsTabPressed : ScrollToTopEvent()
enum class ScrollToTopEvent {
NodesTabPressed,
ConversationsTabPressed,
}
@Composable fun rememberScrollToTopEvents(): MutableSharedFlow<ScrollToTopEvent> = remember { MutableSharedFlow() }

View File

@@ -173,7 +173,7 @@ fun ContactsScreen(
LaunchedEffect(scrollToTopEvents) {
scrollToTopEvents?.collectLatest { event ->
if (event is ScrollToTopEvent.ConversationsTabPressed) {
if (event == ScrollToTopEvent.ConversationsTabPressed) {
contactsListState.smartScrollToTop(coroutineScope)
}
}

View File

@@ -49,7 +49,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.stringResource
import org.meshtastic.core.common.util.Base64Factory
import org.meshtastic.core.common.util.MetricFormatter
import org.meshtastic.core.model.DeviceHardware
import org.meshtastic.core.model.Node
@@ -92,6 +91,8 @@ import org.meshtastic.core.ui.icon.Verified
import org.meshtastic.core.ui.icon.role
import org.meshtastic.core.ui.util.createClipEntry
import org.meshtastic.core.ui.util.formatAgo
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
@Composable
fun NodeDetailsSection(
@@ -324,7 +325,7 @@ private fun MqttAndVerificationRow(node: Node) {
}
}
@OptIn(ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class, ExperimentalEncodingApi::class)
@Suppress("LongMethod", "MagicNumber")
@Composable
private fun PublicKeyItem(publicKeyBytes: ByteArray) {
@@ -335,7 +336,7 @@ private fun PublicKeyItem(publicKeyBytes: ByteArray) {
if (isMismatch) {
stringResource(Res.string.error)
} else {
Base64Factory.encode(publicKeyBytes).trim()
Base64.Default.encode(publicKeyBytes).trim()
}
val label = stringResource(Res.string.public_key)
val copyLabel = stringResource(Res.string.copy)

View File

@@ -114,7 +114,7 @@ fun NodeListScreen(
LaunchedEffect(scrollToTopEvents) {
scrollToTopEvents?.collectLatest { event ->
if (event is ScrollToTopEvent.NodesTabPressed) {
if (event == ScrollToTopEvent.NodesTabPressed) {
listState.smartScrollToTop(coroutineScope)
}
}