Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
3 changes: 3 additions & 0 deletions dari-noop/src/main/kotlin/com/easyhooon/dari/Dari.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions dari/src/main/kotlin/com/easyhooon/dari/Dari.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions dari/src/main/kotlin/com/easyhooon/dari/data/DariPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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.
Expand All @@ -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
}
}
}
Expand Down Expand Up @@ -111,9 +115,24 @@ internal class DariPreferences(

// endregion

// region tag chip

val showTagChip: Boolean get() = _showTagChip.value

fun showTagChipFlow(): Flow<Boolean> = _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")
}
}
6 changes: 6 additions & 0 deletions dari/src/main/kotlin/com/easyhooon/dari/ui/DariActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>(null) }
Expand Down Expand Up @@ -378,6 +381,7 @@ class DariActivity : ComponentActivity() {
) { entry ->
MessageListItem(
entry = entry,
showTagChip = showTagChip,
onClick = {
val intent = Intent(
this@DariActivity,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import java.util.Locale
@Composable
internal fun MessageListItem(
entry: MessageEntry,
showTagChip: Boolean,
onClick: () -> Unit,
) {
Row(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +59,8 @@ internal fun SettingsBottomSheet(
onDarkModeChange: (Boolean?) -> Unit,
jsonFoldingEnabled: Boolean,
onJsonFoldingEnabledChange: (Boolean) -> Unit,
showTagChip: Boolean,
onShowTagChipChange: (Boolean) -> Unit,
onClearMessages: () -> Unit,
onDismiss: () -> Unit,
) {
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Preferences> {
private val state = MutableStateFlow(initialValue)

override val data: Flow<Preferences> = state

override suspend fun updateData(
transform: suspend (Preferences) -> Preferences,
): Preferences = transform(state.value).also { state.value = it }
}
4 changes: 2 additions & 2 deletions documentation/content/docs/ko/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
```

Expand Down
4 changes: 2 additions & 2 deletions documentation/content/docs/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading