Skip to content

Commit

Permalink
feat: url copy 추가 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 2, 2024
1 parent dc7f245 commit d645dcc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.easyhz.noffice.core.design_system.R
Expand All @@ -32,6 +33,7 @@ import com.easyhz.noffice.core.design_system.theme.White
internal fun PlaceBottomSheetTopBar(
modifier: Modifier = Modifier,
placeUrl: String,
onClickUrl: () -> Unit,
onClickBack: () -> Unit,
) {
Box(
Expand Down Expand Up @@ -64,13 +66,15 @@ internal fun PlaceBottomSheetTopBar(
modifier = Modifier
.align(Alignment.Center)
.widthIn(max = 300.dp)
.noRippleClickable { onClickUrl() }
) {
Text(
text = placeUrl,
style = SemiBold14,
color = Grey700,
maxLines = 1,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
textDecoration = TextDecoration.Underline
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ sealed class DetailIntent: UiIntent() {
data class LoadWebView(val isLoading: Boolean): DetailIntent()
data object ClickOpenBrowser: DetailIntent()
data object ClickWebViewBack: DetailIntent()
data object CopyUrl: DetailIntent()
data class UpdateCanGoBack(val canGoBack: Boolean): DetailIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import com.easyhz.noffice.core.common.base.UiSideEffect
sealed class DetailSideEffect: UiSideEffect() {
data object NavigateToUp: DetailSideEffect()
data class OpenBrowser(val url: String): DetailSideEffect()
data class CopyUrl(val url: String): DetailSideEffect()
data object NavigateToUpInWebView: DetailSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -70,8 +70,10 @@ fun AnnouncementDetailScreen(
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val scrollState = rememberScrollState()
val clipBoardManager = LocalClipboardManager.current
val context = LocalContext.current
val webView = remember { WebView(context) }

LaunchedEffect(Unit) {
viewModel.postIntent(DetailIntent.InitScreen(id, title))
}
Expand Down Expand Up @@ -161,6 +163,7 @@ fun AnnouncementDetailScreen(
dragHandle = {
PlaceBottomSheetTopBar(
placeUrl = uiState.detail.placeUrl,
onClickUrl = { viewModel.postIntent(DetailIntent.CopyUrl) }
) {
viewModel.postIntent(DetailIntent.ClickWebViewBack)
}
Expand Down Expand Up @@ -209,6 +212,9 @@ fun AnnouncementDetailScreen(
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(sideEffect.url))
context.startActivity(intent)
}
is DetailSideEffect.CopyUrl -> {
clipBoardManager.setText(AnnotatedString(sideEffect.url))
}
is DetailSideEffect.NavigateToUpInWebView -> {
webView.goBack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AnnouncementDetailViewModel @Inject constructor(
is DetailIntent.LoadWebView -> { onLoadWebView(intent.isLoading) }
is DetailIntent.ClickOpenBrowser -> { onClickOpenBrowser() }
is DetailIntent.ClickWebViewBack -> { onClickWebViewBack() }
is DetailIntent.CopyUrl -> { onCopyUrl() }
is DetailIntent.UpdateCanGoBack -> { updateCanGoBack(intent.canGoBack) }
}
}
Expand Down Expand Up @@ -62,6 +63,9 @@ class AnnouncementDetailViewModel @Inject constructor(
postSideEffect { DetailSideEffect.OpenBrowser(currentState.detail.placeUrl) }
}

private fun onCopyUrl() {
postSideEffect { DetailSideEffect.CopyUrl(currentState.detail.placeUrl) }
}
private fun onClickWebViewBack() {
if (currentState.canGoBack) {
postSideEffect { DetailSideEffect.NavigateToUpInWebView }
Expand Down

0 comments on commit d645dcc

Please sign in to comment.