Skip to content

Commit 59bc2c7

Browse files
committed
refactor: replace ClipboardManager with Clipboard and update related functionality
1 parent 4a926fb commit 59bc2c7

10 files changed

Lines changed: 60 additions & 20 deletions

File tree

‎core/ui/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Each screen is a composable function connected to a ViewModel:
112112

113113
### Global Snackbar Host (`ui/GlobalSnackbarHost.kt`)
114114

115-
- Provides a single `SnackbarHost` for the entire app and wires `SnackbarInteractor` dependencies (`SnackbarHostState`, `ClipboardManager`, `CoroutineScope`).
115+
- Provides a single `SnackbarHost` for the entire app and wires `SnackbarInteractor` dependencies (`SnackbarHostState`, `Clipboard`, `CoroutineScope`).
116116
- Installed once in `App.kt`; Compose disposes it safely across Android, Desktop, Web, and iOS targets.
117117
- Use `SnackbarMessage` variants from `core/presentation` to trigger user messages—never create view-specific hosts.
118118

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import android.content.ClipData
4+
import androidx.compose.ui.platform.ClipEntry
5+
6+
actual fun createClipEntry(text: String): ClipEntry = ClipEntry(ClipData.newPlainText("text", text))

‎core/ui/src/commonMain/kotlin/com/softartdev/notedelight/interactor/SnackbarInteractorImpl.kt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.softartdev.notedelight.interactor
33
import androidx.compose.material3.SnackbarDuration
44
import androidx.compose.material3.SnackbarHostState
55
import androidx.compose.material3.SnackbarResult
6-
import androidx.compose.ui.platform.ClipboardManager
7-
import androidx.compose.ui.text.AnnotatedString
6+
import androidx.compose.ui.platform.Clipboard
7+
import com.softartdev.notedelight.ui.setText
88
import kotlinx.coroutines.CoroutineScope
99
import kotlinx.coroutines.Job
1010
import kotlinx.coroutines.launch
@@ -19,18 +19,18 @@ import org.jetbrains.compose.resources.getString
1919

2020
class SnackbarInteractorImpl : SnackbarInteractor {
2121
private var snackbarHostState: SnackbarHostState? = null
22-
private var clipboardManager: ClipboardManager? = null
22+
private var clipboard: Clipboard? = null
2323
private var coroutineScope: CoroutineScope? = null
2424

2525
override fun setDependencies(hostState: Any, clipboard: Any, coroutineScope: CoroutineScope) {
2626
this.snackbarHostState = hostState as SnackbarHostState
27-
this.clipboardManager = clipboard as ClipboardManager
27+
this.clipboard = clipboard as Clipboard
2828
this.coroutineScope = coroutineScope
2929
}
3030

3131
override fun releaseDependencies() {
3232
this.snackbarHostState = null
33-
this.clipboardManager = null
33+
this.clipboard = null
3434
this.coroutineScope = null
3535
}
3636

@@ -45,7 +45,7 @@ class SnackbarInteractorImpl : SnackbarInteractor {
4545
duration = SnackbarDuration.Long
4646
)
4747
if (result == SnackbarResult.ActionPerformed) {
48-
clipboardManager?.setText(AnnotatedString(message.text))
48+
clipboard?.setText(message.text)
4949
}
5050
}
5151
is SnackbarMessage.Resource -> {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import androidx.compose.ui.platform.ClipEntry
4+
import androidx.compose.ui.platform.Clipboard
5+
6+
expect fun createClipEntry(text: String): ClipEntry
7+
8+
suspend fun Clipboard.setText(text: String) {
9+
setClipEntry(createClipEntry(text))
10+
}

‎core/ui/src/commonMain/kotlin/com/softartdev/notedelight/ui/GlobalSnackbarHost.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import androidx.compose.runtime.remember
1414
import androidx.compose.runtime.rememberCoroutineScope
1515
import androidx.compose.ui.Alignment
1616
import androidx.compose.ui.Modifier
17-
import androidx.compose.ui.platform.ClipboardManager
18-
import androidx.compose.ui.platform.LocalClipboardManager
17+
import androidx.compose.ui.platform.Clipboard
18+
import androidx.compose.ui.platform.LocalClipboard
1919
import androidx.compose.ui.tooling.preview.Preview
2020
import com.softartdev.notedelight.interactor.SnackbarInteractor
2121
import com.softartdev.notedelight.ui.main.PreviewMainScreen
@@ -27,10 +27,10 @@ fun GlobalSnackbarHost(
2727
snackbarInteractor: SnackbarInteractor,
2828
snackbarHostState: SnackbarHostState,
2929
) {
30-
val clipboardManager: ClipboardManager = LocalClipboardManager.current
30+
val clipboard: Clipboard = LocalClipboard.current
3131
val coroutineScope: CoroutineScope = rememberCoroutineScope()
32-
DisposableEffect(key1 = snackbarInteractor, key2 = snackbarHostState, key3 = clipboardManager) {
33-
snackbarInteractor.setDependencies(snackbarHostState, clipboardManager, coroutineScope)
32+
DisposableEffect(key1 = snackbarInteractor, key2 = snackbarHostState, key3 = clipboard) {
33+
snackbarInteractor.setDependencies(snackbarHostState, clipboard, coroutineScope)
3434
onDispose(snackbarInteractor::releaseDependencies)
3535
}
3636
SnackbarHost(

‎core/ui/src/commonMain/kotlin/com/softartdev/notedelight/ui/settings/detail/ConsoleScreen.kt‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ import androidx.compose.runtime.collectAsState
3030
import androidx.compose.runtime.getValue
3131
import androidx.compose.runtime.mutableStateOf
3232
import androidx.compose.runtime.remember
33+
import androidx.compose.runtime.rememberCoroutineScope
3334
import androidx.compose.runtime.setValue
3435
import androidx.compose.ui.Alignment
3536
import androidx.compose.ui.Modifier
36-
import androidx.compose.ui.platform.LocalClipboardManager
37+
import androidx.compose.ui.platform.Clipboard
38+
import androidx.compose.ui.platform.LocalClipboard
3739
import androidx.compose.ui.platform.testTag
38-
import androidx.compose.ui.text.AnnotatedString
3940
import androidx.compose.ui.text.TextStyle
4041
import androidx.compose.ui.text.font.FontFamily
4142
import androidx.compose.ui.tooling.preview.Preview
4243
import androidx.compose.ui.unit.dp
44+
import com.softartdev.notedelight.ui.setText
45+
import kotlinx.coroutines.launch
4346
import com.softartdev.notedelight.feature.console.ui.ConsoleSurface
4447
import com.softartdev.notedelight.feature.console.ui.buffer.ConsoleBuffer
4548
import com.softartdev.notedelight.feature.console.ui.buffer.ConsoleBufferBuilder
@@ -82,9 +85,11 @@ fun ConsoleScreenBody(
8285
result: ConsoleResult = ConsoleResult(),
8386
onBackClick: () -> Unit = {},
8487
onAction: (ConsoleAction) -> Unit = {},
88+
tipTextStyle: TextStyle = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
8589
) {
8690
var tipsExpanded by remember { mutableStateOf(false) }
87-
val clipboardManager = LocalClipboardManager.current
91+
val clipboard: Clipboard = LocalClipboard.current
92+
val coroutineScope = rememberCoroutineScope()
8893
Scaffold(
8994
topBar = {
9095
TopAppBar(
@@ -109,20 +114,19 @@ fun ConsoleScreenBody(
109114
expanded = tipsExpanded,
110115
onDismissRequest = { tipsExpanded = false },
111116
) {
112-
val monospaceBodySmall: TextStyle = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace)
113117
ConsoleTips.entries.forEachIndexed { index, tip ->
114118
TipMenuItem(
115119
tip = tip.sql,
116120
index = index,
117121
onCopy = {
118-
clipboardManager.setText(AnnotatedString(tip.sql))
122+
coroutineScope.launch { clipboard.setText(tip.sql) }
119123
tipsExpanded = false
120124
},
121125
onAutofill = {
122126
onAction(ConsoleAction.UpdateInput(tip.sql))
123127
tipsExpanded = false
124128
},
125-
textStyle = monospaceBodySmall,
129+
textStyle = tipTextStyle,
126130
)
127131
if (index < ConsoleTips.entries.lastIndex) HorizontalDivider()
128132
}

‎core/ui/src/commonMain/kotlin/com/softartdev/notedelight/ui/signin/AdaptiveFrame.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.PaddingValues
55
import androidx.compose.foundation.layout.fillMaxSize
66
import androidx.compose.foundation.layout.imePadding
77
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
8-
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
8+
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfoV2
99
import androidx.compose.runtime.Composable
1010
import androidx.compose.ui.Alignment
1111
import androidx.compose.ui.Modifier
@@ -21,7 +21,7 @@ fun AdaptiveFrame(
2121
expandedMaxWidth: Dp = 600.dp,
2222
content: @Composable (PaddingValues) -> Unit
2323
) {
24-
val info: WindowAdaptiveInfo = currentWindowAdaptiveInfo()
24+
val info: WindowAdaptiveInfo = currentWindowAdaptiveInfoV2()
2525
val sizeClass: WindowSizeClass = info.windowSizeClass
2626
val isAtLeastMedium: Boolean = sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND)
2727
val isAtLeastExpanded: Boolean = sizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_EXPANDED_LOWER_BOUND)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import androidx.compose.ui.ExperimentalComposeUiApi
4+
import androidx.compose.ui.platform.ClipEntry
5+
6+
@OptIn(ExperimentalComposeUiApi::class)
7+
actual fun createClipEntry(text: String): ClipEntry = ClipEntry.withPlainText(text)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import androidx.compose.ui.ExperimentalComposeUiApi
4+
import androidx.compose.ui.platform.ClipEntry
5+
import java.awt.datatransfer.StringSelection
6+
7+
@OptIn(ExperimentalComposeUiApi::class)
8+
actual fun createClipEntry(text: String): ClipEntry = ClipEntry(StringSelection(text))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import androidx.compose.ui.platform.ClipEntry
4+
5+
actual fun createClipEntry(text: String): ClipEntry = ClipEntry.withPlainText(text)

0 commit comments

Comments
 (0)