From ab07347e5af5fe680a7d1a32b3551ca6eb12255c Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Thu, 25 Jun 2026 05:34:53 -0500 Subject: [PATCH] refactor: drop two over-engineered seams (enum + stdlib Base64) (#5945) Co-authored-by: Claude Opus 4.8 --- .../core/common/util/Base64Factory.kt | 28 ------------------- .../core/ui/component/ScrollToTopEvent.kt | 7 ++--- .../feature/messaging/ui/contact/Contacts.kt | 2 +- .../node/component/NodeDetailsSection.kt | 7 +++-- .../feature/node/list/NodeListScreen.kt | 2 +- 5 files changed, 9 insertions(+), 37 deletions(-) delete mode 100644 core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Base64Factory.kt diff --git a/core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Base64Factory.kt b/core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Base64Factory.kt deleted file mode 100644 index a20a04ecd..000000000 --- a/core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Base64Factory.kt +++ /dev/null @@ -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 . - */ -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) -} diff --git a/core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/ScrollToTopEvent.kt b/core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/ScrollToTopEvent.kt index 4548c23d0..6e35fb43e 100644 --- a/core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/ScrollToTopEvent.kt +++ b/core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/ScrollToTopEvent.kt @@ -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 = remember { MutableSharedFlow() } diff --git a/feature/messaging/src/commonMain/kotlin/org/meshtastic/feature/messaging/ui/contact/Contacts.kt b/feature/messaging/src/commonMain/kotlin/org/meshtastic/feature/messaging/ui/contact/Contacts.kt index 3a3e75a23..8d49c7051 100644 --- a/feature/messaging/src/commonMain/kotlin/org/meshtastic/feature/messaging/ui/contact/Contacts.kt +++ b/feature/messaging/src/commonMain/kotlin/org/meshtastic/feature/messaging/ui/contact/Contacts.kt @@ -173,7 +173,7 @@ fun ContactsScreen( LaunchedEffect(scrollToTopEvents) { scrollToTopEvents?.collectLatest { event -> - if (event is ScrollToTopEvent.ConversationsTabPressed) { + if (event == ScrollToTopEvent.ConversationsTabPressed) { contactsListState.smartScrollToTop(coroutineScope) } } diff --git a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/component/NodeDetailsSection.kt b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/component/NodeDetailsSection.kt index 7641103fc..11df01a8c 100644 --- a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/component/NodeDetailsSection.kt +++ b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/component/NodeDetailsSection.kt @@ -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) diff --git a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/list/NodeListScreen.kt b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/list/NodeListScreen.kt index e991ee36c..7e20fe475 100644 --- a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/list/NodeListScreen.kt +++ b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/list/NodeListScreen.kt @@ -114,7 +114,7 @@ fun NodeListScreen( LaunchedEffect(scrollToTopEvents) { scrollToTopEvents?.collectLatest { event -> - if (event is ScrollToTopEvent.NodesTabPressed) { + if (event == ScrollToTopEvent.NodesTabPressed) { listState.smartScrollToTop(coroutineScope) } }