diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/atom/checkbox/PokitCheckbox.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/atom/checkbox/PokitCheckbox.kt index c366b9c8..1462af55 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/atom/checkbox/PokitCheckbox.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/atom/checkbox/PokitCheckbox.kt @@ -21,11 +21,12 @@ import pokitmons.pokit.core.ui.R import pokitmons.pokit.core.ui.components.atom.checkbox.attributes.PokitCheckboxShape import pokitmons.pokit.core.ui.components.atom.checkbox.attributes.PokitCheckboxStyle import pokitmons.pokit.core.ui.theme.PokitTheme +import pokitmons.pokit.core.ui.utils.conditional @Composable fun PokitCheckbox( checked: Boolean, - onClick: (Boolean) -> Unit, + onClick: ((Boolean) -> Unit)? = null, style: PokitCheckboxStyle = PokitCheckboxStyle.STROKE, shape: PokitCheckboxShape = PokitCheckboxShape.RECTANGLE, enabled: Boolean = true, @@ -44,14 +45,18 @@ fun PokitCheckbox( .clip( shape = checkboxShape ) - .clickable( - indication = null, - interactionSource = remember { MutableInteractionSource() }, - enabled = enabled, - onClick = { - onClick(!checked) - } - ) + .conditional( + condition = (onClick != null) + ) { + clickable( + indication = null, + interactionSource = remember { MutableInteractionSource() }, + enabled = enabled, + onClick = { + onClick?.invoke(!checked) + } + ) + } .background( color = backgroundColor ) diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/LinkCard.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/LinkCard.kt index 99d7c89f..d3fa5794 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/LinkCard.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/LinkCard.kt @@ -8,18 +8,22 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn +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.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color @@ -30,6 +34,8 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import pokitmons.pokit.core.ui.R +import pokitmons.pokit.core.ui.components.atom.checkbox.PokitCheckbox +import pokitmons.pokit.core.ui.components.atom.checkbox.attributes.PokitCheckboxStyle import pokitmons.pokit.core.ui.theme.PokitTheme import pokitmons.pokit.core.ui.utils.noRippleClickable @@ -44,6 +50,10 @@ fun LinkCard( onClickKebab: (T) -> Unit, onClickItem: (T) -> Unit, modifier: Modifier = Modifier, + hasMemo: Boolean = false, + hasMember: Boolean = false, + bookmark: Boolean? = null, + checked: Boolean? = null, ) { Box(modifier = modifier) { Row( @@ -65,6 +75,38 @@ fun LinkCard( .background(Color.Gray), contentScale = ContentScale.Crop ) + + checked?.let { + Box( + modifier = Modifier + .offset(x = 8.dp, y = 8.dp) + .size(24.dp), + contentAlignment = Alignment.Center + ) { + PokitCheckbox( + checked = it, + style = PokitCheckboxStyle.FILLED + ) + } + } + + bookmark?.let { + Box( + modifier = Modifier + .offset(x = 8.dp, y = 54.dp) + .size(32.dp) + .clip(CircleShape) + .background(PokitTheme.colors.backgroundBaseIcon), + contentAlignment = Alignment.Center + ) { + Icon( + modifier = Modifier.size(24.dp), + painter = painterResource(id = R.drawable.icon_24_star), + contentDescription = "bookmark", + tint = if (it) PokitTheme.colors.brand else PokitTheme.colors.iconDisable + ) + } + } } Spacer(modifier = Modifier.width(12.dp)) @@ -119,34 +161,72 @@ fun LinkCard( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(6.dp) ) { - badgeText?.let { badge -> + if (notRead) { Text( - text = badge, + text = stringResource(id = R.string.not_read), modifier = Modifier + .border( + width = 1.dp, + color = PokitTheme.colors.brand, + shape = RoundedCornerShape(4.dp) + ) .background( - color = PokitTheme.colors.backgroundPrimary, + color = PokitTheme.colors.backgroundBase, shape = RoundedCornerShape(4.dp) ) .padding(horizontal = 8.dp, vertical = 4.dp), - style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.textTertiary) + style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.brand) ) } - if (notRead) { - Text( - text = stringResource(id = R.string.not_read), + if (badgeText?.isNotBlank() == true) { + Box( + Modifier.weight(1f) + ) { + Text( + text = badgeText, + modifier = Modifier + .background( + color = PokitTheme.colors.backgroundPrimary, + shape = RoundedCornerShape(4.dp) + ) + .padding(horizontal = 8.dp, vertical = 4.dp), + style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.textTertiary), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + } + + if (hasMemo) { + Icon( modifier = Modifier - .border( - width = 1.dp, - color = PokitTheme.colors.borderTertiary, + .height(20.dp) + .aspectRatio(1f) + .background( + color = PokitTheme.colors.backgroundPrimary, shape = RoundedCornerShape(4.dp) ) + .padding(2.dp), + painter = painterResource(id = R.drawable.icon_24_file), + tint = PokitTheme.colors.iconSecondary, + contentDescription = "hasMemo" + ) + } + + if (hasMember) { + Icon( + modifier = Modifier + .height(20.dp) + .aspectRatio(1f) .background( - color = PokitTheme.colors.backgroundBase, + color = PokitTheme.colors.backgroundPrimary, shape = RoundedCornerShape(4.dp) ) - .padding(horizontal = 8.dp, vertical = 4.dp), - style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.textTertiary) + .padding(2.dp), + painter = painterResource(id = R.drawable.icon_24_member), + tint = PokitTheme.colors.iconSecondary, + contentDescription = "hasMemo" ) } } diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/Preview.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/Preview.kt index 68b8616b..bf722e99 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/Preview.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/linkcard/Preview.kt @@ -28,12 +28,15 @@ fun LinkCardPreview() { LinkCard( title = "타이틀\n컴포스는 왜 이런가", sub = "2024.06.25. youtube.comyoutube.comyoutube.comyoutube", - badgeText = "텍스트", + badgeText = "텍스트텍스트텍스트텍스트텍스트", painter = painterResource(id = R.drawable.icon_24_link), notRead = true, item = 3, onClickKebab = { value: Int -> }, - onClickItem = { value: Int -> } + onClickItem = { value: Int -> }, + bookmark = false, + hasMemo = true, + hasMember = true ) LinkCard( @@ -44,7 +47,8 @@ fun LinkCardPreview() { notRead = true, item = 3, onClickKebab = { value: Int -> }, - onClickItem = { value: Int -> } + onClickItem = { value: Int -> }, + checked = true ) } } diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/subcomponents/ModifyBottomSheetItem.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/texticonbutton/TextIconButton.kt similarity index 79% rename from core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/subcomponents/ModifyBottomSheetItem.kt rename to core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/texticonbutton/TextIconButton.kt index 8a0d35eb..8a49e334 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/subcomponents/ModifyBottomSheetItem.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/block/texticonbutton/TextIconButton.kt @@ -1,4 +1,4 @@ -package pokitmons.pokit.core.ui.components.template.modifybottomsheet.subcomponents +package pokitmons.pokit.core.ui.components.block.texticonbutton import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement @@ -10,16 +10,19 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.unit.dp import pokitmons.pokit.core.ui.theme.PokitTheme import pokitmons.pokit.core.ui.utils.noRippleClickable @Composable -internal fun ModifyBottomSheetItem( +internal fun TextIconButton( onClick: () -> Unit, title: String, painter: Painter, + tintColor: Color? = PokitTheme.colors.iconPrimary, ) { Row( modifier = Modifier @@ -39,7 +42,8 @@ internal fun ModifyBottomSheetItem( Image( modifier = Modifier.size(24.dp), painter = painter, - contentDescription = null + contentDescription = null, + colorFilter = tintColor?.let { ColorFilter.tint(it) } ) } } diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheet.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheet.kt index 4b11f0bc..ab86fbe6 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheet.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheet.kt @@ -1,51 +1,17 @@ package pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.ColorFilter -import androidx.compose.ui.graphics.painter.Painter -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import pokitmons.pokit.core.ui.R -import pokitmons.pokit.core.ui.components.block.linkurlcard.LinkUrlCard import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet -import pokitmons.pokit.core.ui.theme.PokitTheme -import pokitmons.pokit.core.ui.theme.color.Orange50 @Composable fun LinkDetailBottomSheet( title: String, memo: String, - url: String, - thumbnailPainter: Painter, bookmark: Boolean, - openWebBrowserByClick: Boolean, pokitName: String, dateString: String, onHideBottomSheet: () -> Unit, show: Boolean = false, - useRemind: Boolean = false, onClickBookmark: (() -> Unit)? = null, onClickRemoveLink: (() -> Unit)? = null, onClickModifyLink: (() -> Unit)? = null, @@ -55,188 +21,16 @@ fun LinkDetailBottomSheet( onHideBottomSheet = onHideBottomSheet, show = show ) { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp) - ) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically - ) { - if (useRemind) { - Image( - painter = painterResource(id = R.drawable.icon_24_bell), - contentDescription = null, - modifier = Modifier - .size(20.dp) - .background( - color = PokitTheme.colors.brand, - shape = CircleShape - ) - .padding(2.dp), - colorFilter = ColorFilter.tint(PokitTheme.colors.inverseWh) - ) - - Spacer(modifier = Modifier.width(4.dp)) - } - - Text( - text = pokitName, - modifier = Modifier - .border( - width = 1.dp, - color = PokitTheme.colors.borderTertiary, - shape = RoundedCornerShape(4.dp) - ) - .background( - color = PokitTheme.colors.backgroundBase, - shape = RoundedCornerShape(4.dp) - ) - .padding(horizontal = 8.dp, vertical = 4.dp), - style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.textTertiary) - ) - } - - Spacer(modifier = Modifier.height(8.dp)) - - Text( - text = title, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - style = PokitTheme.typography.title3.copy(color = PokitTheme.colors.textPrimary) - ) - - Spacer(modifier = Modifier.height(8.dp)) - - Text( - modifier = Modifier.fillMaxWidth(), - text = dateString, - style = PokitTheme.typography.detail2.copy(color = PokitTheme.colors.textTertiary), - textAlign = TextAlign.End - ) - } - - Spacer(modifier = Modifier.height(12.dp)) - - HorizontalDivider( - thickness = 1.dp, - color = PokitTheme.colors.borderTertiary - ) - - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp, vertical = 24.dp) - ) { - LinkUrlCard( - thumbnailPainter = thumbnailPainter, - url = url, - title = title, - openWebBrowserByClick = openWebBrowserByClick - ) - - Spacer(modifier = Modifier.height(16.dp)) - - Text( - text = memo, - modifier = Modifier - .fillMaxWidth() - .background( - color = Orange50, - shape = RoundedCornerShape(8.dp) - ) - .padding(16.dp), - style = PokitTheme.typography.body3Regular.copy(color = PokitTheme.colors.textPrimary), - maxLines = 4, - minLines = 4 - ) - } - - HorizontalDivider( - thickness = 1.dp, - color = PokitTheme.colors.borderTertiary + LinkDetailBottomSheetContent( + title = title, + memo = memo, + bookmark = bookmark, + pokitName = pokitName, + dateString = dateString, + onClickBookmark = onClickBookmark, + onClickRemoveLink = onClickRemoveLink, + onClickModifyLink = onClickModifyLink, + onClickShareLink = onClickShareLink ) - - Row( - modifier = Modifier - .fillMaxWidth() - .padding(top = 10.dp, start = 10.dp, end = 10.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Image( - modifier = Modifier - .size(36.dp) - .padding(6.dp) - .clickable( - indication = null, - interactionSource = remember { MutableInteractionSource() }, - onClick = { - onClickBookmark?.invoke() - } - ), - painter = painterResource(id = R.drawable.icon_24_star), - contentDescription = "bookmark", - colorFilter = ColorFilter.tint( - color = if (bookmark) PokitTheme.colors.brand else PokitTheme.colors.iconTertiary - ) - ) - - Spacer(modifier = Modifier.weight(1f)) - - onClickShareLink?.let { - Image( - modifier = Modifier - .size(36.dp) - .padding(6.dp) - .clickable( - indication = null, - interactionSource = remember { MutableInteractionSource() }, - onClick = onClickShareLink - ), - painter = painterResource(id = R.drawable.icon_24_share), - contentDescription = "share", - colorFilter = ColorFilter.tint( - color = PokitTheme.colors.iconSecondary - ) - ) - } - - onClickModifyLink?.let { - Image( - modifier = Modifier - .size(36.dp) - .padding(6.dp) - .clickable( - indication = null, - interactionSource = remember { MutableInteractionSource() }, - onClick = onClickModifyLink - ), - painter = painterResource(id = R.drawable.icon_24_edit), - contentDescription = "edit", - colorFilter = ColorFilter.tint( - color = PokitTheme.colors.iconSecondary - ) - ) - } - - onClickRemoveLink?.let { - Image( - modifier = Modifier - .size(36.dp) - .padding(6.dp) - .clickable( - indication = null, - interactionSource = remember { MutableInteractionSource() }, - onClick = onClickRemoveLink - ), - painter = painterResource(id = R.drawable.icon_24_trash), - contentDescription = "remove", - colorFilter = ColorFilter.tint( - color = PokitTheme.colors.iconSecondary - ) - ) - } - } } } diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheetContent.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheetContent.kt new file mode 100644 index 00000000..ef367412 --- /dev/null +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/LinkDetailBottomSheetContent.kt @@ -0,0 +1,188 @@ +package pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import pokitmons.pokit.core.ui.R +import pokitmons.pokit.core.ui.components.block.texticonbutton.TextIconButton +import pokitmons.pokit.core.ui.theme.PokitTheme +import pokitmons.pokit.core.ui.theme.color.Orange50 + +@Composable +fun LinkDetailBottomSheetContent( + title: String, + memo: String, + bookmark: Boolean, + pokitName: String, + dateString: String, + onClickBookmark: (() -> Unit)? = null, + onClickRemoveLink: (() -> Unit)? = null, + onClickModifyLink: (() -> Unit)? = null, + onClickShareLink: (() -> Unit)? = null, +) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp, vertical = 12.dp) + ) { + Text( + text = title, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + style = PokitTheme.typography.title3.copy(color = PokitTheme.colors.textPrimary) + ) + + Spacer(modifier = Modifier.height(8.dp)) + + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = pokitName, + modifier = Modifier + .background( + color = PokitTheme.colors.backgroundPrimary, + shape = RoundedCornerShape(4.dp) + ) + .padding(horizontal = 8.dp, vertical = 4.dp), + style = PokitTheme.typography.label4.copy(color = PokitTheme.colors.textTertiary) + ) + + Row { + Text( + modifier = Modifier.fillMaxWidth(), + text = dateString, + style = PokitTheme.typography.detail2.copy(color = PokitTheme.colors.textTertiary), + textAlign = TextAlign.End + ) + } + } + } + + Spacer(modifier = Modifier.height(12.dp)) + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + + Column( + modifier = Modifier + .fillMaxWidth() + .padding(top = 16.dp, bottom = 24.dp, start = 24.dp, end = 24.dp) + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = stringResource(id = R.string.memo), + style = PokitTheme.typography.body1Medium.copy(color = PokitTheme.colors.textPrimary) + ) + + Icon( + modifier = Modifier.size(24.dp), + painter = painterResource(id = R.drawable.icon_24_file), + contentDescription = null, + tint = PokitTheme.colors.iconPrimary + ) + } + + Spacer(modifier = Modifier.height(12.dp)) + + // textField? + Text( + text = memo, + modifier = Modifier + .fillMaxWidth() + .background( + color = Orange50, + shape = RoundedCornerShape(8.dp) + ) + .padding(16.dp), + style = PokitTheme.typography.body3Regular.copy(color = PokitTheme.colors.textPrimary), + maxLines = 4, + minLines = 4 + ) + } + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + + onClickBookmark?.let { + TextIconButton( + onClick = onClickBookmark, + title = stringResource(id = R.string.bookmark), + painter = painterResource( + id = if (bookmark) R.drawable.icon_24_star else R.drawable.icon_24_star_1 + ), + tintColor = if (bookmark) PokitTheme.colors.brand else PokitTheme.colors.iconPrimary + ) + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + } + + onClickShareLink?.let { + TextIconButton( + onClick = onClickShareLink, + title = stringResource(id = R.string.share), + painter = painterResource(id = R.drawable.icon_24_share) + ) + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + } + + onClickModifyLink?.let { + TextIconButton( + onClick = onClickModifyLink, + title = stringResource(id = R.string.modify), + painter = painterResource(id = R.drawable.icon_24_edit) + ) + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + } + + onClickRemoveLink?.let { + TextIconButton( + onClick = onClickRemoveLink, + title = stringResource(id = R.string.remove), + painter = painterResource(id = R.drawable.icon_24_trash) + ) + + HorizontalDivider( + thickness = 1.dp, + color = PokitTheme.colors.borderTertiary + ) + } + + Spacer(modifier = Modifier.height(20.dp)) +} diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/Preview.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/Preview.kt index 3d162637..3535d39c 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/Preview.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/linkdetailbottomsheet/Preview.kt @@ -4,9 +4,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview -import pokitmons.pokit.core.ui.R import pokitmons.pokit.core.ui.theme.PokitTheme @Preview(showBackground = true) @@ -17,18 +15,14 @@ private fun LinkDetailBottomSheetPreview() { LinkDetailBottomSheet( title = "title", memo = "some memo", - url = "https://naver.com", - thumbnailPainter = painterResource(id = R.drawable.icon_24_google), bookmark = true, - openWebBrowserByClick = false, show = true, pokitName = "TEXT", dateString = "2024.08.27", onHideBottomSheet = { }, onClickBookmark = { }, onClickModifyLink = { }, - onClickRemoveLink = { }, - onClickShareLink = { } + onClickRemoveLink = { } ) } } diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/ModifyBottomSheetContent.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/ModifyBottomSheetContent.kt index 4ea40913..8a5236df 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/ModifyBottomSheetContent.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/components/template/modifybottomsheet/ModifyBottomSheetContent.kt @@ -7,7 +7,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import pokitmons.pokit.core.ui.R -import pokitmons.pokit.core.ui.components.template.modifybottomsheet.subcomponents.ModifyBottomSheetItem +import pokitmons.pokit.core.ui.components.block.texticonbutton.TextIconButton @Composable fun ModifyBottomSheetContent( @@ -19,7 +19,7 @@ fun ModifyBottomSheetContent( modifier = Modifier.fillMaxWidth() ) { onClickShare?.let { onClickShare -> - ModifyBottomSheetItem( + TextIconButton( onClick = onClickShare, title = stringResource(id = R.string.share), painter = painterResource(id = R.drawable.icon_24_share) @@ -27,7 +27,7 @@ fun ModifyBottomSheetContent( } onClickModify?.let { onClickModify -> - ModifyBottomSheetItem( + TextIconButton( onClick = onClickModify, title = stringResource(id = R.string.modify), painter = painterResource(id = R.drawable.icon_24_edit) @@ -35,7 +35,7 @@ fun ModifyBottomSheetContent( } onClickRemove?.let { onClickRemove -> - ModifyBottomSheetItem( + TextIconButton( onClick = onClickRemove, title = stringResource(id = R.string.remove), painter = painterResource(id = R.drawable.icon_24_trash) diff --git a/core/ui/src/main/java/pokitmons/pokit/core/ui/utils/ModifierUtils.kt b/core/ui/src/main/java/pokitmons/pokit/core/ui/utils/ModifierUtils.kt index a5e1f4be..267f0c0d 100644 --- a/core/ui/src/main/java/pokitmons/pokit/core/ui/utils/ModifierUtils.kt +++ b/core/ui/src/main/java/pokitmons/pokit/core/ui/utils/ModifierUtils.kt @@ -21,7 +21,8 @@ import androidx.compose.ui.unit.IntSize import pokitmons.pokit.core.ui.theme.color.Gray300 import pokitmons.pokit.core.ui.theme.color.Gray500 -internal fun Modifier.conditional(condition: Boolean, modifier: Modifier.() -> Modifier): Modifier { +@Composable +internal fun Modifier.conditional(condition: Boolean, modifier: @Composable Modifier.() -> Modifier): Modifier { return if (condition) { then(modifier(Modifier)) } else { diff --git a/core/ui/src/main/res/drawable/icon_24_file.xml b/core/ui/src/main/res/drawable/icon_24_file.xml new file mode 100644 index 00000000..b90ce52a --- /dev/null +++ b/core/ui/src/main/res/drawable/icon_24_file.xml @@ -0,0 +1,19 @@ + + + + diff --git a/core/ui/src/main/res/drawable/icon_24_member.xml b/core/ui/src/main/res/drawable/icon_24_member.xml new file mode 100644 index 00000000..b9e2a92d --- /dev/null +++ b/core/ui/src/main/res/drawable/icon_24_member.xml @@ -0,0 +1,9 @@ + + + diff --git a/core/ui/src/main/res/values/string.xml b/core/ui/src/main/res/values/string.xml index cd43f1d7..83e13e4f 100644 --- a/core/ui/src/main/res/values/string.xml +++ b/core/ui/src/main/res/values/string.xml @@ -9,6 +9,7 @@ 공유하기 수정하기 삭제하기 + 즐겨찾기 확인 @@ -34,4 +35,7 @@ 아직 알람이 없어요 리마인드 알림을 설정하세요 + + 메모 + 메모를 입력해주세요 \ No newline at end of file diff --git a/data/src/main/java/pokitmons/pokit/data/mapper/link/LinkMapper.kt b/data/src/main/java/pokitmons/pokit/data/mapper/link/LinkMapper.kt index b7ead641..2e6b3c0e 100644 --- a/data/src/main/java/pokitmons/pokit/data/mapper/link/LinkMapper.kt +++ b/data/src/main/java/pokitmons/pokit/data/mapper/link/LinkMapper.kt @@ -19,7 +19,8 @@ object LinkMapper { alertYn = data.alertYn, createdAt = data.createdAt, isRead = data.isRead, - thumbnail = data.thumbNail + thumbnail = data.thumbNail, + favorites = data.isFavorite ) } } diff --git a/data/src/main/java/pokitmons/pokit/data/model/link/response/GetLinksResponse.kt b/data/src/main/java/pokitmons/pokit/data/model/link/response/GetLinksResponse.kt index 1b7f2320..8e33b745 100644 --- a/data/src/main/java/pokitmons/pokit/data/model/link/response/GetLinksResponse.kt +++ b/data/src/main/java/pokitmons/pokit/data/model/link/response/GetLinksResponse.kt @@ -22,6 +22,7 @@ data class GetLinksResponse( val createdAt: String, val isRead: Boolean, val thumbNail: String, + val isFavorite: Boolean, ) @Serializable diff --git a/feature/home/src/main/java/pokitmons/pokit/home/pokit/UnclassifiedScreen.kt b/feature/home/src/main/java/pokitmons/pokit/home/pokit/UnclassifiedScreen.kt index 35ceb7b1..59eb84a4 100644 --- a/feature/home/src/main/java/pokitmons/pokit/home/pokit/UnclassifiedScreen.kt +++ b/feature/home/src/main/java/pokitmons/pokit/home/pokit/UnclassifiedScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -37,15 +38,13 @@ fun UnclassifiedScreen( val currentDetailShowLink by viewModel.currentDetailShowLink.collectAsState() val context: Context = LocalContext.current + val uriHandler = LocalUriHandler.current currentDetailShowLink?.let { link -> LinkDetailBottomSheet( title = link.title, memo = link.memo, - url = link.url, - thumbnailPainter = rememberAsyncImagePainter(model = link.imageUrl), bookmark = link.bookmark, - openWebBrowserByClick = true, pokitName = link.pokitName, dateString = link.dateString, onHideBottomSheet = viewModel::hideDetailLinkBottomSheet, @@ -124,10 +123,10 @@ fun UnclassifiedScreen( notRead = !unCategoryDetail.isRead, badgeText = "미분류", onClickKebab = { - viewModel.showLinkOptionBottomSheet(unCategoryDetail) + viewModel.showDetailLinkBottomSheet(unCategoryDetail) }, onClickItem = { - viewModel.showDetailLinkBottomSheet(unCategoryDetail) + uriHandler.openUri(unCategoryDetail.url) } ) } diff --git a/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindScreen.kt b/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindScreen.kt index 3c9f74fd..35890e68 100644 --- a/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindScreen.kt +++ b/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindScreen.kt @@ -1,6 +1,5 @@ package pokitmons.pokit.home.remind -import android.content.Context import androidx.compose.foundation.background import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement @@ -19,7 +18,7 @@ import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel @@ -27,12 +26,10 @@ import coil.compose.rememberAsyncImagePainter import com.strayalpaca.pokitdetail.R import com.strayalpaca.pokitdetail.model.BottomSheetType import pokitmons.pokit.core.feature.model.NetworkState -import pokitmons.pokit.core.feature.utils.ShareUrlLink import pokitmons.pokit.core.ui.components.atom.loading.LoadingProgress import pokitmons.pokit.core.ui.components.block.linkcard.LinkCard import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheet -import pokitmons.pokit.core.ui.components.template.modifybottomsheet.ModifyBottomSheetContent import pokitmons.pokit.core.ui.components.template.pookiempty.EmptyPooki import pokitmons.pokit.core.ui.components.template.pookierror.ErrorPooki import pokitmons.pokit.core.ui.components.template.removeItemBottomSheet.TwoButtonBottomSheetContent @@ -59,9 +56,7 @@ fun RemindScreen( val currentDetailShowLink by viewModel.currentShowingLink.collectAsState() val pokitOptionBottomSheetType by viewModel.pokitOptionBottomSheetType.collectAsState() - val currentSelectedLink by viewModel.currentSelectedLink.collectAsState() - - val context: Context = LocalContext.current + val uriHandler = LocalUriHandler.current val showTotalEmpty by remember { derivedStateOf { @@ -77,23 +72,6 @@ fun RemindScreen( show = pokitOptionBottomSheetType != null ) { when (pokitOptionBottomSheetType) { - BottomSheetType.MODIFY -> { - ModifyBottomSheetContent( - onClickShare = { - ShareUrlLink( - context = context, - url = viewModel.currentShowingLink.value?.url ?: "" - ) - }, - onClickModify = remember { - { - viewModel.hideLinkOptionBottomSheet() - onNavigateToLinkModify(currentSelectedLink!!.id) - } - }, - onClickRemove = viewModel::showLinkRemoveBottomSheet - ) - } BottomSheetType.REMOVE -> { TwoButtonBottomSheetContent( title = stringResource(id = R.string.title_remove_link), @@ -115,10 +93,7 @@ fun RemindScreen( LinkDetailBottomSheet( title = link.title, memo = link.memo, - url = link.url, - thumbnailPainter = rememberAsyncImagePainter(model = link.imageUrl), bookmark = link.bookmark, - openWebBrowserByClick = true, pokitName = link.pokitName, dateString = link.dateString, onHideBottomSheet = viewModel::hideDetailLinkBottomSheet, @@ -232,10 +207,10 @@ fun RemindScreen( notRead = !unReadContent.isRead, badgeText = null, onClickKebab = { - viewModel.showLinkOptionBottomSheet(remindResult = unReadContent) + viewModel.showDetailLinkBottomSheet(remindResult = unReadContent) }, onClickItem = { - viewModel.showDetailLinkBottomSheet(remindResult = unReadContent) + uriHandler.openUri(unReadContent.data) } ) } @@ -271,13 +246,13 @@ fun RemindScreen( title = favoriteContent.title, sub = "${favoriteContent.createdAt} • ${favoriteContent.domain}", painter = rememberAsyncImagePainter(favoriteContent.thumbNail), - notRead = favoriteContent.isRead, + notRead = !favoriteContent.isRead, badgeText = null, onClickKebab = { - viewModel.showLinkOptionBottomSheet(remindResult = favoriteContent) + viewModel.showDetailLinkBottomSheet(remindResult = favoriteContent) }, onClickItem = { - viewModel.showDetailLinkBottomSheet(remindResult = favoriteContent) + uriHandler.openUri(favoriteContent.data) } ) } diff --git a/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindViewModel.kt b/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindViewModel.kt index 88254358..a52b87e4 100644 --- a/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindViewModel.kt +++ b/feature/home/src/main/java/pokitmons/pokit/home/remind/RemindViewModel.kt @@ -277,12 +277,6 @@ class RemindViewModel @Inject constructor( } } - fun showLinkRemoveBottomSheet() { - _pokitOptionBottomSheetType.update { - BottomSheetType.REMOVE - } - } - fun showLinkRemoveBottomSheet(link: Link) { _pokitOptionBottomSheetType.update { BottomSheetType.REMOVE diff --git a/feature/linklist/src/main/java/pokitmons/pokit/linklist/LinkListScreen.kt b/feature/linklist/src/main/java/pokitmons/pokit/linklist/LinkListScreen.kt index 7ed4df86..4c0f4bfb 100644 --- a/feature/linklist/src/main/java/pokitmons/pokit/linklist/LinkListScreen.kt +++ b/feature/linklist/src/main/java/pokitmons/pokit/linklist/LinkListScreen.kt @@ -27,6 +27,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -92,6 +93,8 @@ fun LinkListScreen( onClickModifyLink: (String) -> Unit, onClickBookmark: () -> Unit, ) { + val uriHandler = LocalUriHandler.current + Column( modifier = Modifier .fillMaxSize() @@ -196,7 +199,9 @@ fun LinkListScreen( notRead = !link.isRead, badgeText = link.pokitName, onClickKebab = showLinkDetailBottomSheet, - onClickItem = showLinkDetailBottomSheet, + onClickItem = { + uriHandler.openUri(link.url) + }, modifier = Modifier.padding(20.dp) ) @@ -213,15 +218,10 @@ fun LinkListScreen( val context: Context = LocalContext.current val link = state.bottomSheetInfo?.link ?: Link() - // 수정 필요 - // onHideBottomSheet 호출로 인해 후속 호출로 발생한 삭제 bottomSheet가 종료되고 있음 LinkDetailBottomSheet( title = link.title, memo = link.memo, - url = link.url, - thumbnailPainter = rememberAsyncImagePainter(link.imageUrl), bookmark = link.bookmark, - openWebBrowserByClick = true, pokitName = link.pokitName, dateString = link.dateString, onHideBottomSheet = hideLinkDetailBottomSheet, diff --git a/feature/pokitdetail/src/main/java/com/strayalpaca/pokitdetail/PokitDetailScreen.kt b/feature/pokitdetail/src/main/java/com/strayalpaca/pokitdetail/PokitDetailScreen.kt index 22920ee9..491ca8a5 100644 --- a/feature/pokitdetail/src/main/java/com/strayalpaca/pokitdetail/PokitDetailScreen.kt +++ b/feature/pokitdetail/src/main/java/com/strayalpaca/pokitdetail/PokitDetailScreen.kt @@ -28,6 +28,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -86,7 +87,6 @@ fun PokitDetailScreenContainer( showPokitModifyBottomSheet = viewModel::showPokitModifyBottomSheet, showPokitRemoveBottomSheet = viewModel::showPokitRemoveBottomSheet, hidePokitModifyBottomSheet = viewModel::hidePokitBottomSheet, - showLinkModifyBottomSheet = viewModel::showLinkModifyBottomSheet, showLinkRemoveBottomSheet = viewModel::showLinkRemoveBottomSheet, showLinkRemoveBottomSheetWithLink = remember { { link -> @@ -101,7 +101,7 @@ fun PokitDetailScreenContainer( linkListState = linkListState, pokitList = pokitList, pokitListState = pokitListState, - onClickLink = viewModel::showLinkDetailBottomSheet, + showLinkDetailBottomSheet = viewModel::showLinkDetailBottomSheet, onClickPokitModify = onNavigateToPokitModify, onClickPokitRemove = viewModel::deletePokit, onClickLinkModify = onNavigateToLinkModify, @@ -126,7 +126,6 @@ fun PokitDetailScreen( showPokitModifyBottomSheet: () -> Unit = {}, showPokitRemoveBottomSheet: () -> Unit = {}, hidePokitModifyBottomSheet: () -> Unit = {}, - showLinkModifyBottomSheet: (Link) -> Unit = {}, showLinkRemoveBottomSheet: () -> Unit = {}, showLinkRemoveBottomSheetWithLink: (Link) -> Unit = {}, hideLinkModifyBottomSheet: () -> Unit = {}, @@ -136,7 +135,7 @@ fun PokitDetailScreen( linkListState: PagingState = PagingState.IDLE, pokitList: List = emptyList(), pokitListState: PagingState = PagingState.IDLE, - onClickLink: (Link) -> Unit = {}, + showLinkDetailBottomSheet: (Link) -> Unit = {}, onClickPokitModify: (String) -> Unit = {}, onClickPokitRemove: () -> Unit = {}, onClickLinkModify: (String) -> Unit = {}, @@ -147,6 +146,8 @@ fun PokitDetailScreen( onClickBookmark: () -> Unit = {}, onClickAddLink: (String, String) -> Unit = { _, _ -> }, ) { + val uriHandler = LocalUriHandler.current + Box( modifier = Modifier.fillMaxSize() ) { @@ -228,9 +229,12 @@ fun PokitDetailScreen( painter = rememberAsyncImagePainter(link.imageUrl), notRead = !link.isRead, badgeText = link.pokitName, - onClickKebab = showLinkModifyBottomSheet, - onClickItem = onClickLink, - modifier = Modifier.padding(20.dp) + onClickKebab = showLinkDetailBottomSheet, + onClickItem = { + uriHandler.openUri(link.url) + }, + modifier = Modifier.padding(20.dp), + bookmark = link.bookmark ) HorizontalDivider( @@ -267,10 +271,7 @@ fun PokitDetailScreen( LinkDetailBottomSheet( title = state.currentLink.title, memo = state.currentLink.memo, - url = state.currentLink.url, - thumbnailPainter = rememberAsyncImagePainter(state.currentLink.imageUrl), bookmark = state.currentLink.bookmark, - openWebBrowserByClick = true, pokitName = state.currentLink.pokitName, dateString = state.currentLink.dateString, onHideBottomSheet = hideLinkDetailBottomSheet, diff --git a/feature/search/src/main/java/pokitmons/pokit/search/SearchScreen.kt b/feature/search/src/main/java/pokitmons/pokit/search/SearchScreen.kt index 44aaf940..300ed295 100644 --- a/feature/search/src/main/java/pokitmons/pokit/search/SearchScreen.kt +++ b/feature/search/src/main/java/pokitmons/pokit/search/SearchScreen.kt @@ -1,7 +1,6 @@ package pokitmons.pokit.search import android.content.Context -import android.content.Intent import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -13,15 +12,14 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import coil.compose.rememberAsyncImagePainter import pokitmons.pokit.core.feature.model.paging.PagingState import pokitmons.pokit.core.feature.utils.ShareUrlLink import pokitmons.pokit.core.ui.components.atom.loading.LoadingProgress import pokitmons.pokit.core.ui.components.template.bottomsheet.PokitBottomSheet -import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheet -import pokitmons.pokit.core.ui.components.template.modifybottomsheet.ModifyBottomSheetContent +import pokitmons.pokit.core.ui.components.template.linkdetailbottomsheet.LinkDetailBottomSheetContent import pokitmons.pokit.core.ui.components.template.pookiempty.EmptyPooki import pokitmons.pokit.core.ui.components.template.pookierror.ErrorPooki import pokitmons.pokit.core.ui.components.template.removeItemBottomSheet.TwoButtonBottomSheetContent @@ -31,10 +29,10 @@ import pokitmons.pokit.search.components.filterbottomsheet.FilterBottomSheet import pokitmons.pokit.search.components.recentsearchword.RecentSearchWord import pokitmons.pokit.search.components.searchitemlist.SearchItemList import pokitmons.pokit.search.components.toolbar.Toolbar -import pokitmons.pokit.search.model.BottomSheetType import pokitmons.pokit.search.model.Filter import pokitmons.pokit.search.model.FilterType import pokitmons.pokit.search.model.Link +import pokitmons.pokit.search.model.LinkBottomSheetState import pokitmons.pokit.search.model.SearchScreenState import pokitmons.pokit.search.model.SearchScreenStep import pokitmons.pokit.core.ui.R.string as coreString @@ -54,35 +52,6 @@ fun SearchScreenContainer( val context: Context = LocalContext.current - state.currentDetailLink?.let { link -> - LinkDetailBottomSheet( - title = link.title, - memo = link.memo, - url = link.url, - thumbnailPainter = rememberAsyncImagePainter(link.imageUrl), - bookmark = link.bookmark, - openWebBrowserByClick = true, - pokitName = link.pokitName, - dateString = link.dateString, - onHideBottomSheet = viewModel::hideLinkDetailBottomSheet, - show = state.showLinkDetailBottomSheet, - onClickShareLink = { - ShareUrlLink( - context = context, - url = state.currentDetailLink?.url ?: "" - ) - }, - onClickModifyLink = { - viewModel.hideLinkDetailBottomSheet() - onNavigateToLinkModify(link.id) - }, - onClickRemoveLink = { - viewModel.showLinkRemoveBottomSheet(link) - }, - onClickBookmark = viewModel::toggleBookmark - ) - } - FilterBottomSheet( filter = state.filter ?: Filter(), firstShowType = state.firstBottomSheetFilterType, @@ -96,48 +65,46 @@ fun SearchScreenContainer( ) PokitBottomSheet( - onHideBottomSheet = viewModel::hideLinkModifyBottomSheet, + onHideBottomSheet = viewModel::hideLinkBottomSheet, show = state.linkBottomSheetType != null ) { - if (state.linkBottomSheetType == BottomSheetType.MODIFY) { - ModifyBottomSheetContent( - onClickModify = remember { - { - state.currentTargetLink?.let { link -> - viewModel.hideLinkModifyBottomSheet() - onNavigateToLinkModify(link.id) - } - } - }, - onClickRemove = remember { - { - state.currentTargetLink?.let { link -> - viewModel.showLinkRemoveBottomSheet(link) + state.linkBottomSheetType?.let { linkBottomSheetState -> + when (linkBottomSheetState) { + is LinkBottomSheetState.CheckRemove -> { + TwoButtonBottomSheetContent( + title = stringResource(id = R.string.title_remove_link), + subText = stringResource(id = R.string.sub_remove_link), + onClickLeftButton = viewModel::hideLinkBottomSheet, + onClickRightButton = { + viewModel.deleteLink() + viewModel.hideLinkBottomSheet() } - } - }, - onClickShare = remember { - { - val intent = Intent(Intent.ACTION_SEND_MULTIPLE).apply { - type = "text/plain" - putExtra(Intent.EXTRA_TEXT, state.currentTargetLink?.url) - } - context.startActivity(Intent.createChooser(intent, "Pokit")) - } + ) } - ) - } - - if (state.linkBottomSheetType == BottomSheetType.REMOVE) { - TwoButtonBottomSheetContent( - title = stringResource(id = R.string.title_remove_link), - subText = stringResource(id = R.string.sub_remove_link), - onClickLeftButton = viewModel::hideLinkModifyBottomSheet, - onClickRightButton = { - viewModel.deleteLink() - viewModel.hideLinkModifyBottomSheet() + is LinkBottomSheetState.LinkDetail -> { + LinkDetailBottomSheetContent( + title = linkBottomSheetState.link.title, + memo = linkBottomSheetState.link.memo, + bookmark = linkBottomSheetState.link.bookmark, + pokitName = linkBottomSheetState.link.pokitName, + dateString = linkBottomSheetState.link.dateString, + onClickShareLink = { + ShareUrlLink( + context = context, + url = linkBottomSheetState.link.url + ) + }, + onClickModifyLink = { + viewModel.hideLinkBottomSheet() + onNavigateToLinkModify(linkBottomSheetState.link.id) + }, + onClickRemoveLink = { + viewModel.showLinkRemoveBottomSheet(linkBottomSheetState.link) + }, + onClickBookmark = viewModel::toggleBookmarkInBottomSheet + ) } - ) + } } } @@ -156,7 +123,6 @@ fun SearchScreenContainer( onClickFilterSelect = viewModel::showFilterBottomSheet, onClickFilterItem = viewModel::showFilterBottomSheetWithType, toggleSortOrder = viewModel::toggleSortOrder, - showLinkModifyBottomSheet = viewModel::showLinkModifyBottomSheet, showLinkDetailBottomSheet = viewModel::showLinkDetailBottomSheet, loadNextLinks = viewModel::loadNextLinks ) @@ -178,10 +144,11 @@ fun SearchScreen( onClickFilterSelect: () -> Unit = {}, onClickFilterItem: (FilterType) -> Unit = {}, toggleSortOrder: () -> Unit = {}, - showLinkModifyBottomSheet: (Link) -> Unit = {}, showLinkDetailBottomSheet: (Link) -> Unit = {}, loadNextLinks: () -> Unit = {}, ) { + val uriHandler = LocalUriHandler.current + Column( modifier = Modifier .fillMaxSize() @@ -256,8 +223,10 @@ fun SearchScreen( .weight(1f), onToggleSort = toggleSortOrder, useRecentOrder = state.sortRecent, - onClickLinkKebab = showLinkModifyBottomSheet, - onClickLink = showLinkDetailBottomSheet, + onClickLinkKebab = showLinkDetailBottomSheet, + onClickLink = { + uriHandler.openUri(it.url) + }, links = linkList, linkPagingState = linkPagingState, loadNextLinks = loadNextLinks diff --git a/feature/search/src/main/java/pokitmons/pokit/search/SearchViewModel.kt b/feature/search/src/main/java/pokitmons/pokit/search/SearchViewModel.kt index 7835fc76..422b1c9d 100644 --- a/feature/search/src/main/java/pokitmons/pokit/search/SearchViewModel.kt +++ b/feature/search/src/main/java/pokitmons/pokit/search/SearchViewModel.kt @@ -29,10 +29,10 @@ import pokitmons.pokit.domain.usecase.search.GetRecentSearchWordsUseCase import pokitmons.pokit.domain.usecase.search.GetUseRecentSearchWordsUseCase import pokitmons.pokit.domain.usecase.search.RemoveRecentSearchWordUseCase import pokitmons.pokit.domain.usecase.search.SetUseRecentSearchWordsUseCase -import pokitmons.pokit.search.model.BottomSheetType import pokitmons.pokit.search.model.Filter import pokitmons.pokit.search.model.FilterType import pokitmons.pokit.search.model.Link +import pokitmons.pokit.search.model.LinkBottomSheetState import pokitmons.pokit.search.model.Pokit import pokitmons.pokit.search.model.SearchScreenState import pokitmons.pokit.search.model.SearchScreenStep @@ -233,30 +233,10 @@ class SearchViewModel @Inject constructor( } } - fun showLinkModifyBottomSheet(link: Link) { - _state.update { state -> - state.copy( - linkBottomSheetType = BottomSheetType.MODIFY, - currentTargetLink = link - ) - } - } - fun showLinkRemoveBottomSheet(link: Link) { _state.update { state -> state.copy( - linkBottomSheetType = BottomSheetType.REMOVE, - showLinkDetailBottomSheet = false, - currentTargetLink = link - ) - } - } - - fun hideLinkModifyBottomSheet() { - _state.update { state -> - state.copy( - linkBottomSheetType = null, - currentTargetLink = null + linkBottomSheetType = LinkBottomSheetState.CheckRemove(link = link) ) } } @@ -264,16 +244,22 @@ class SearchViewModel @Inject constructor( fun showLinkDetailBottomSheet(link: Link) { _state.update { state -> state.copy( - currentDetailLink = link, - showLinkDetailBottomSheet = true, - linkBottomSheetType = null + linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = link) ) } viewModelScope.launch { val response = getLinkUseCase.getLink(link.id.toInt()) - if (response is PokitResult.Success && state.value.currentDetailLink?.id == link.id && state.value.showLinkDetailBottomSheet) { - _state.update { it.copy(currentDetailLink = Link.fromDomainLink(response.result).copy(imageUrl = link.imageUrl, isRead = true)) } + val currentBottomSheetState = state.value.linkBottomSheetType ?: return@launch + + val currentShowDetailLinkBottomSheet = (currentBottomSheetState is LinkBottomSheetState.LinkDetail) && + (currentBottomSheetState.link.id == link.id) + + if (response is PokitResult.Success && currentShowDetailLinkBottomSheet) { + val responseLink = Link.fromDomainLink(response.result).copy(imageUrl = link.imageUrl, isRead = true) + _state.update { + it.copy(linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = responseLink)) + } } val isReadChangedLink = linkPaging.pagingData.value @@ -284,11 +270,10 @@ class SearchViewModel @Inject constructor( } } - fun hideLinkDetailBottomSheet() { + fun hideLinkBottomSheet() { _state.update { state -> state.copy( - currentDetailLink = null, - showLinkDetailBottomSheet = false + linkBottomSheetType = null ) } } @@ -338,27 +323,32 @@ class SearchViewModel @Inject constructor( } } - fun toggleBookmark() { - val currentLink = state.value.currentTargetLink ?: return - val currentLinkId = currentLink.id.toIntOrNull() ?: return - val applyBookmarked = !currentLink.bookmark + fun toggleBookmarkInBottomSheet() { + val currentState = state.value + val bottomSheetLink = currentState.linkBottomSheetType?.link ?: return + val bottomSheetLinkId = bottomSheetLink.id.toIntOrNull() ?: return + val applyBookmarked = !bottomSheetLink.bookmark viewModelScope.launch { - val response = setBookmarkUseCase.setBookMarked(currentLinkId, applyBookmarked) + val response = setBookmarkUseCase.setBookMarked(bottomSheetLinkId, applyBookmarked) if (response is PokitResult.Success) { - val bookmarkChangedLink = currentLink.copy(bookmark = applyBookmarked) - _state.update { state -> - state.copy( - currentDetailLink = bookmarkChangedLink - ) + val bookmarkChangedLink = bottomSheetLink.copy(bookmark = applyBookmarked) + + if (currentState.linkBottomSheetType is LinkBottomSheetState.LinkDetail) { + _state.update { state -> + state.copy( + linkBottomSheetType = LinkBottomSheetState.LinkDetail(link = bookmarkChangedLink) + ) + } } + linkPaging.modifyItem(bookmarkChangedLink) } } } fun deleteLink() { - val currentLinkId = state.value.currentTargetLink?.id?.toIntOrNull() ?: return + val currentLinkId = state.value.linkBottomSheetType?.link?.id?.toIntOrNull() ?: return viewModelScope.launch { val response = deleteLinkUseCase.deleteLink(currentLinkId) if (response is PokitResult.Success) { diff --git a/feature/search/src/main/java/pokitmons/pokit/search/components/searchitemlist/SearchItemList.kt b/feature/search/src/main/java/pokitmons/pokit/search/components/searchitemlist/SearchItemList.kt index 95fe34e3..3781053d 100644 --- a/feature/search/src/main/java/pokitmons/pokit/search/components/searchitemlist/SearchItemList.kt +++ b/feature/search/src/main/java/pokitmons/pokit/search/components/searchitemlist/SearchItemList.kt @@ -95,7 +95,8 @@ internal fun SearchItemList( badgeText = link.pokitName, onClickKebab = onClickLinkKebab, onClickItem = onClickLink, - modifier = Modifier.padding(20.dp) + modifier = Modifier.padding(20.dp), + bookmark = link.bookmark ) } } diff --git a/feature/search/src/main/java/pokitmons/pokit/search/model/SearchScreenState.kt b/feature/search/src/main/java/pokitmons/pokit/search/model/SearchScreenState.kt index 898a5d19..4c479295 100644 --- a/feature/search/src/main/java/pokitmons/pokit/search/model/SearchScreenState.kt +++ b/feature/search/src/main/java/pokitmons/pokit/search/model/SearchScreenState.kt @@ -7,17 +7,15 @@ data class SearchScreenState( val useRecentSearchWord: Boolean = false, val showFilterBottomSheet: Boolean = false, val firstBottomSheetFilterType: FilterType = FilterType.Pokit, - val showLinkDetailBottomSheet: Boolean = false, - val linkBottomSheetType: BottomSheetType? = null, + val linkBottomSheetType: LinkBottomSheetState? = null, val sortRecent: Boolean = true, - val currentTargetLink: Link? = null, - val currentDetailLink: Link? = null, ) enum class SearchScreenStep { INPUT, RESULT } -enum class BottomSheetType { - MODIFY, REMOVE +sealed class LinkBottomSheetState(open val link: Link) { + data class LinkDetail(override val link: Link) : LinkBottomSheetState(link) + data class CheckRemove(override val link: Link) : LinkBottomSheetState(link) }