Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
add comment like method to PostDetailScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumo0922 committed Dec 11, 2023
1 parent 9ac4797 commit dc54cb5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
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
Expand All @@ -19,10 +18,7 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material.icons.outlined.BookmarkBorder
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
Expand All @@ -31,6 +27,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -250,6 +247,7 @@ private fun PostDetailScreen(
modifier: Modifier = Modifier,
) {
var isShowMenu by remember { mutableStateOf(false) }
var isPostLiked by rememberSaveable(postDetail.isLiked) { mutableStateOf(postDetail.isLiked) }
var isBookmarked by remember(postDetail.isBookmarked) { mutableStateOf(postDetail.isBookmarked) }

val isShowCoordinateHeader = when (val content = postDetail.body) {
Expand Down Expand Up @@ -316,32 +314,23 @@ private fun PostDetailScreen(
}

item {
Row(
PostDetailCommentLikeButton(
modifier = Modifier
.padding(horizontal = 16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
PostDetailCommentLikeButton(
modifier = Modifier.weight(1f),
likeCount = postDetail.likeCount,
commentCount = postDetail.commentCount,
)

IconButton(
onClick = {
isBookmarked = !isBookmarked
onClickPostBookmark.invoke(postDetail.asPost(), isBookmarked)
},
) {
Icon(
imageVector = if (isBookmarked) Icons.Default.Bookmark else Icons.Outlined.BookmarkBorder,
tint = if (isBookmarked) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface,
contentDescription = null,
)
}
}
isLiked = isPostLiked,
isBookmarked = isBookmarked,
likeCount = postDetail.likeCount,
commentCount = postDetail.commentCount,
onClickLike = {
isPostLiked = true
onClickPostLike.invoke(postDetail.id)
},
onClickBookmark = {
isBookmarked = it
onClickPostBookmark.invoke(postDetail.asPost(), isBookmarked)
},
)
}

if (postDetail.isRestricted) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,100 @@
package caios.android.fanbox.feature.post.detail.items

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.Comment
import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.outlined.BookmarkBorder
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
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
import androidx.compose.ui.unit.dp

@Composable
internal fun PostDetailCommentLikeButton(
commentCount: Int,
likeCount: Int,
isBookmarked: Boolean,
isLiked: Boolean,
onClickLike: () -> Unit,
onClickBookmark: (Boolean) -> Unit,
modifier: Modifier = Modifier,
) {
val likeColor = if (isLiked) Color(0xffe0405e) else MaterialTheme.colorScheme.onSurfaceVariant
val bookmarkColor = if (isBookmarked) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant

Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Icon(
modifier = Modifier.size(18.dp),
modifier = Modifier.size(20.dp),
imageVector = Icons.AutoMirrored.Filled.Comment,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
contentDescription = null,
)

Text(
text = commentCount.toString(),
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}

Row(
modifier = Modifier
.clip(CircleShape)
.clickable {
if (!isLiked) {
onClickLike.invoke()
}
onClickBookmark.invoke(true)
}
.padding(4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Icon(
modifier = Modifier.size(18.dp),
modifier = Modifier.size(20.dp),
imageVector = Icons.Default.Favorite,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
tint = likeColor,
contentDescription = null,
)

Text(
text = likeCount.toString(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall,
color = likeColor,
)
}

Spacer(modifier = Modifier.weight(1f))

IconButton(
onClick = { onClickBookmark.invoke(!isBookmarked) },
) {
Icon(
imageVector = if (isBookmarked) Icons.Default.Bookmark else Icons.Outlined.BookmarkBorder,
tint = bookmarkColor,
contentDescription = null,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ internal fun LoginScreen(
cookieManager.acceptCookie()
cookieManager.acceptThirdPartyCookies(it)

it.settings.loadWithOverviewMode = true
it.settings.domStorageEnabled = true
it.settings.javaScriptEnabled = true
it.settings.javaScriptCanOpenWindowsAutomatically = true
},
client = object : AccompanistWebViewClient() {
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
Expand Down

0 comments on commit dc54cb5

Please sign in to comment.