Skip to content

Commit

Permalink
Copy & paste URL to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Oct 13, 2024
1 parent 8b7c8ef commit a9b7c39
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ kotlin {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.ui)
implementation(compose.components.resources)

Expand Down
64 changes: 61 additions & 3 deletions app/src/commonMain/kotlin/ui/WoldView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.CopyAll
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import model.Asteroid
import model.World
import ui.theme.DefaultSpacer
Expand All @@ -56,6 +66,7 @@ import ui.theme.defaultRoundedCornerShape
import ui.theme.defaultSpacing
import ui.theme.halfPadding
import ui.theme.halfSpacing
import ui.theme.hoverColor
import ui.theme.lightGray
import ui.theme.lightGrayTransparentBorderColor
import kotlin.math.max
Expand Down Expand Up @@ -110,6 +121,23 @@ fun WorldView(
modifier = Modifier.offset(y = -4.dp)
) {

val seedWasCopied = remember { mutableStateOf(false) }

/*
* Set notice back after 3 seconds.
*/
LaunchedEffect(seedWasCopied.value) {

if (!seedWasCopied.value)
return@LaunchedEffect

delay(3000)

seedWasCopied.value = false
}

val clipboardManager = LocalClipboardManager.current

val url = "https://stefan-oltmann.de/oni-seed-browser/#" + world.coordinate;

Spacer(modifier = Modifier.width(defaultSpacing + halfSpacing))
Expand All @@ -124,9 +152,39 @@ fun WorldView(
)
}

// Icon(
// imageVector = Icons.Default.
// )
DefaultSpacer()

val hovered = remember { mutableStateOf(false) }

Icon(
imageVector = Icons.Default.ContentCopy,
contentDescription = null,
tint = if (hovered.value)
hoverColor
else
MaterialTheme.colorScheme.onBackground,
modifier = Modifier
.onHover(hovered)
.size(16.dp)
.noRippleClickable {

clipboardManager.setText(AnnotatedString(url))

seedWasCopied.value = true
}
)

if (seedWasCopied.value) {

DefaultSpacer()

Text(
text = "Copied URL to clipboard!",
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onBackground
)
}
}

HalfSpacer()
Expand Down

0 comments on commit a9b7c39

Please sign in to comment.