diff --git a/README.md b/README.md index e243759..7454940 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,7 @@ keep the same API surface without storing or displaying bridge messages. | `createInterceptor(tag?, protobufDecoder)` | Create a protobuf-capable interceptor while retaining all string/JSON methods | | `setShakeToOpenEnabled(enabled)` | Enable/disable shake-to-open at runtime (persisted) | | `setDarkMode(value)` | Override dark mode: `true` / `false` / `null` (system default). Persisted | +| `setShowTagChip(show)` | Show/hide bridge tag chips in the message list. Persisted | | `showNotification()` | Show the notification (e.g., after permission grant) | | `clear()` | Clear all stored messages and dismiss notification | diff --git a/dari-noop/src/main/kotlin/com/easyhooon/dari/Dari.kt b/dari-noop/src/main/kotlin/com/easyhooon/dari/Dari.kt index 1590f8e..8376822 100644 --- a/dari-noop/src/main/kotlin/com/easyhooon/dari/Dari.kt +++ b/dari-noop/src/main/kotlin/com/easyhooon/dari/Dari.kt @@ -28,6 +28,9 @@ object Dari { @Suppress("UNUSED_PARAMETER") fun setDarkMode(value: Boolean?) = Unit + @Suppress("UNUSED_PARAMETER") + fun setShowTagChip(show: Boolean) = Unit + fun showNotification() = Unit fun clear() = Unit diff --git a/dari/src/main/kotlin/com/easyhooon/dari/Dari.kt b/dari/src/main/kotlin/com/easyhooon/dari/Dari.kt index c378396..1fddaac 100644 --- a/dari/src/main/kotlin/com/easyhooon/dari/Dari.kt +++ b/dari/src/main/kotlin/com/easyhooon/dari/Dari.kt @@ -105,6 +105,14 @@ object Dari { preferences.setJsonFoldingEnabled(enabled) } + /** + * Show or hide bridge tag chips beside handler names in the message list. + * Persists across process restarts. + */ + fun setShowTagChip(show: Boolean) { + preferences.setShowTagChip(show) + } + private fun applyShakeToOpen(enabled: Boolean) { shakeManager?.unregister() shakeManager = if (enabled) { diff --git a/dari/src/main/kotlin/com/easyhooon/dari/data/DariPreferences.kt b/dari/src/main/kotlin/com/easyhooon/dari/data/DariPreferences.kt index fe8ed66..a21f958 100644 --- a/dari/src/main/kotlin/com/easyhooon/dari/data/DariPreferences.kt +++ b/dari/src/main/kotlin/com/easyhooon/dari/data/DariPreferences.kt @@ -43,6 +43,8 @@ internal class DariPreferences( private val _jsonFoldingEnabled = MutableStateFlow(true) + private val _showTagChip = MutableStateFlow(true) + init { // One-shot blocking read so settings are correct for the first synchronous // caller (e.g. Dari.init or Compose initialValue). @@ -51,6 +53,7 @@ internal class DariPreferences( _shakeToOpen.value = snapshot[KEY_SHAKE_TO_OPEN] ?: defaultShakeToOpen _darkMode.value = snapshot[KEY_DARK_MODE] _jsonFoldingEnabled.value = snapshot[KEY_JSON_FOLDING_ENABLED] ?: true + _showTagChip.value = snapshot[KEY_SHOW_TAG_CHIP] ?: true } // Keep the StateFlows in sync with any subsequent DataStore writes. @@ -59,6 +62,7 @@ internal class DariPreferences( _shakeToOpen.value = prefs[KEY_SHAKE_TO_OPEN] ?: defaultShakeToOpen _darkMode.value = prefs[KEY_DARK_MODE] _jsonFoldingEnabled.value = prefs[KEY_JSON_FOLDING_ENABLED] ?: true + _showTagChip.value = prefs[KEY_SHOW_TAG_CHIP] ?: true } } } @@ -111,9 +115,24 @@ internal class DariPreferences( // endregion + // region tag chip + + val showTagChip: Boolean get() = _showTagChip.value + + fun showTagChipFlow(): Flow = _showTagChip.asStateFlow() + + fun setShowTagChip(value: Boolean) { + scope.launch { + dataStore.edit { it[KEY_SHOW_TAG_CHIP] = value } + } + } + + // endregion + companion object { private val KEY_SHAKE_TO_OPEN = booleanPreferencesKey("shake_to_open") private val KEY_DARK_MODE = booleanPreferencesKey("dark_mode") private val KEY_JSON_FOLDING_ENABLED = booleanPreferencesKey("json_folding_enabled") + private val KEY_SHOW_TAG_CHIP = booleanPreferencesKey("show_tag_chip") } } diff --git a/dari/src/main/kotlin/com/easyhooon/dari/ui/DariActivity.kt b/dari/src/main/kotlin/com/easyhooon/dari/ui/DariActivity.kt index 83bda84..2108590 100644 --- a/dari/src/main/kotlin/com/easyhooon/dari/ui/DariActivity.kt +++ b/dari/src/main/kotlin/com/easyhooon/dari/ui/DariActivity.kt @@ -155,6 +155,9 @@ class DariActivity : ComponentActivity() { .collectAsStateWithLifecycle( initialValue = Dari.preferences.jsonFoldingEnabled, ) + val showTagChip by Dari.preferences.showTagChipFlow().collectAsStateWithLifecycle( + initialValue = Dari.preferences.showTagChip, + ) var isSearchMode by rememberSaveable { mutableStateOf(false) } var searchQuery by rememberSaveable { mutableStateOf("") } var selectedTag by rememberSaveable { mutableStateOf(null) } @@ -378,6 +381,7 @@ class DariActivity : ComponentActivity() { ) { entry -> MessageListItem( entry = entry, + showTagChip = showTagChip, onClick = { val intent = Intent( this@DariActivity, @@ -402,6 +406,8 @@ class DariActivity : ComponentActivity() { onDarkModeChange = { Dari.setDarkMode(it) }, jsonFoldingEnabled = jsonFoldingEnabled, onJsonFoldingEnabledChange = { Dari.setJsonFoldingEnabled(it) }, + showTagChip = showTagChip, + onShowTagChipChange = { Dari.setShowTagChip(it) }, onClearMessages = { showSettingsSheet = false showClearDialog = true diff --git a/dari/src/main/kotlin/com/easyhooon/dari/ui/components/MessageListItem.kt b/dari/src/main/kotlin/com/easyhooon/dari/ui/components/MessageListItem.kt index 5f6f7cc..96ae212 100644 --- a/dari/src/main/kotlin/com/easyhooon/dari/ui/components/MessageListItem.kt +++ b/dari/src/main/kotlin/com/easyhooon/dari/ui/components/MessageListItem.kt @@ -42,6 +42,7 @@ import java.util.Locale @Composable internal fun MessageListItem( entry: MessageEntry, + showTagChip: Boolean, onClick: () -> Unit, ) { Row( @@ -73,7 +74,7 @@ internal fun MessageListItem( overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false), ) - entry.tag?.let { tag -> + entry.tag?.takeIf { showTagChip }?.let { tag -> Spacer(modifier = Modifier.width(6.dp)) Text( text = tag, diff --git a/dari/src/main/kotlin/com/easyhooon/dari/ui/components/SettingsBottomSheet.kt b/dari/src/main/kotlin/com/easyhooon/dari/ui/components/SettingsBottomSheet.kt index c7ed4d7..1911c88 100644 --- a/dari/src/main/kotlin/com/easyhooon/dari/ui/components/SettingsBottomSheet.kt +++ b/dari/src/main/kotlin/com/easyhooon/dari/ui/components/SettingsBottomSheet.kt @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.Label import androidx.compose.material.icons.automirrored.filled.OpenInNew import androidx.compose.material.icons.filled.Brightness6 import androidx.compose.material.icons.filled.Code @@ -58,6 +59,8 @@ internal fun SettingsBottomSheet( onDarkModeChange: (Boolean?) -> Unit, jsonFoldingEnabled: Boolean, onJsonFoldingEnabledChange: (Boolean) -> Unit, + showTagChip: Boolean, + onShowTagChipChange: (Boolean) -> Unit, onClearMessages: () -> Unit, onDismiss: () -> Unit, ) { @@ -103,6 +106,13 @@ internal fun SettingsBottomSheet( checked = jsonFoldingEnabled, onCheckedChange = onJsonFoldingEnabledChange, ) + SettingToggleRow( + icon = Icons.AutoMirrored.Filled.Label, + title = "Bridge tag chip", + description = "Show bridge tags beside handler names", + checked = showTagChip, + onCheckedChange = onShowTagChipChange, + ) HorizontalDivider( modifier = Modifier.padding(vertical = 12.dp), diff --git a/dari/src/test/kotlin/com/easyhooon/dari/data/DariPreferencesTest.kt b/dari/src/test/kotlin/com/easyhooon/dari/data/DariPreferencesTest.kt new file mode 100644 index 0000000..456fe5a --- /dev/null +++ b/dari/src/test/kotlin/com/easyhooon/dari/data/DariPreferencesTest.kt @@ -0,0 +1,58 @@ +package com.easyhooon.dari.data + +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.emptyPreferences +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class DariPreferencesTest { + + @Test + fun `tag chip is shown by default`() { + val preferences = DariPreferences( + dataStore = InMemoryDataStore(), + defaultShakeToOpen = false, + ) + + assertTrue(preferences.showTagChip) + } + + @Test + fun `tag chip visibility is persisted`() = runBlocking { + val dataStore = InMemoryDataStore() + val preferences = DariPreferences( + dataStore = dataStore, + defaultShakeToOpen = false, + ) + + preferences.setShowTagChip(false) + withTimeout(1_000) { + preferences.showTagChipFlow().first { !it } + } + + val restoredPreferences = DariPreferences( + dataStore = dataStore, + defaultShakeToOpen = false, + ) + assertFalse(restoredPreferences.showTagChip) + } +} + +private class InMemoryDataStore( + initialValue: Preferences = emptyPreferences(), +) : DataStore { + private val state = MutableStateFlow(initialValue) + + override val data: Flow = state + + override suspend fun updateData( + transform: suspend (Preferences) -> Preferences, + ): Preferences = transform(state.value).also { state.value = it } +} diff --git a/documentation/content/docs/ko/setup.mdx b/documentation/content/docs/ko/setup.mdx index 9f60621..38dcb49 100644 --- a/documentation/content/docs/ko/setup.mdx +++ b/documentation/content/docs/ko/setup.mdx @@ -9,8 +9,8 @@ description: Android 프로젝트에 Dari 추가하기 ```kotlin dependencies { - debugImplementation("io.github.easyhooon:dari:1.7.0") - releaseImplementation("io.github.easyhooon:dari-noop:1.7.0") + debugImplementation("io.github.easyhooon:dari:1.8.0") + releaseImplementation("io.github.easyhooon:dari-noop:1.8.0") } ``` diff --git a/documentation/content/docs/setup.mdx b/documentation/content/docs/setup.mdx index 3bbb1c6..9baa801 100644 --- a/documentation/content/docs/setup.mdx +++ b/documentation/content/docs/setup.mdx @@ -9,8 +9,8 @@ Add the dependencies to your app module's `build.gradle.kts`: ```kotlin dependencies { - debugImplementation("io.github.easyhooon:dari:1.7.0") - releaseImplementation("io.github.easyhooon:dari-noop:1.7.0") + debugImplementation("io.github.easyhooon:dari:1.8.0") + releaseImplementation("io.github.easyhooon:dari-noop:1.8.0") } ``` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6d5f3cd..63d898c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -dari = "1.7.0" +dari = "1.8.0" agp = "9.0.0" coreKtx = "1.13.1" junit = "4.13.2"