Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
StageGuard committed Jul 31, 2024
1 parent 0d6984c commit d92a8ea
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ fun PreviewEditCommentSheet() {
initialExpandEditComment = false,
title = MutableStateFlow("评论:我心里危险的东西 第二季"),
stickerProvider = {
generateSequence(1) { it + 1 }
.take(64)
(0..64)
.map { EditCommentSticker(it, null) }
.toList()
},
onSend = { id, content -> },
onSend = { _, _ -> },
backgroundScope = scope.backgroundScope,
)
},
Expand All @@ -41,8 +40,7 @@ fun PreviewEditCommentSheet() {
fun PreviewEditCommentStickerPanel() {
ProvideCompositionLocalsForPreview {
EditCommentDefaults.StickerSelector(
list = generateSequence(0) { it + 1 }
.take(40)
list = (0..64)
.map { EditCommentSticker(it, null) }
.toList(),
onClickItem = { },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Face
import androidx.compose.material.icons.outlined.AddReaction
import androidx.compose.material.icons.outlined.HeartBroken
import androidx.compose.material.icons.outlined.ModeComment
import androidx.compose.material.icons.outlined.Report
import androidx.compose.material.icons.rounded.Face
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -208,7 +207,7 @@ fun Comment(
Surface(
modifier = Modifier.padding(top = if (actionRow == null) 12.dp else 0.dp),
color = MaterialTheme.colorScheme.surface,
shape = RoundedCornerShape(8.dp),
shape = MaterialTheme.shapes.small,
) {
reply()
}
Expand Down Expand Up @@ -255,13 +254,14 @@ object CommentDefaults {
verticalAlignment = Alignment.CenterVertically,
) {
val previewing = LocalIsPreviewing.current
val reactionDrawableRes = BangumiCommentSticker[reaction.id]

if (previewing) Icon(
imageVector = Icons.Default.Face,
if (previewing || reactionDrawableRes == null) Icon(
imageVector = Icons.Rounded.Face,
modifier = Modifier.padding(end = 4.dp).size(24.dp),
contentDescription = null,
) else Icon(
painter = painterResource(BangumiCommentSticker[reaction.id]!!),
painter = painterResource(reactionDrawableRes),
modifier = Modifier.padding(end = 4.dp).size(24.dp),
contentDescription = null,
)
Expand Down Expand Up @@ -347,13 +347,11 @@ object CommentDefaults {

Column(modifier = modifier) {
replies.forEach { reply ->
val prepended by remember {
derivedStateOf {
reply.content.prependText(
prependix = "${reply.creator.nickname ?: reply.creator.id.toString()}",
color = primaryColor,
)
}
val prepended = remember(reply.content, primaryColor) {
reply.content.prependText(
prependix = "${reply.creator.nickname ?: reply.creator.id.toString()}",
color = primaryColor,
)
}
RichText(
elements = prepended.elements,
Expand All @@ -364,13 +362,11 @@ object CommentDefaults {
)
}
if (hiddenReplyCount > 0) {
val prepended by remember {
derivedStateOf {
UIRichText(emptyList()).prependText(
prependix = "查看更多 $hiddenReplyCount 条回复>",
color = primaryColor,
)
}
val prepended = remember(hiddenReplyCount) {
UIRichText(emptyList()).prependText(
prependix = "查看更多 $hiddenReplyCount 条回复>",
color = primaryColor,
)
}

RichText(
Expand Down
34 changes: 32 additions & 2 deletions app/shared/src/commonMain/kotlin/ui/subject/episode/EpisodePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import me.him188.ani.app.data.source.danmaku.protocol.DanmakuInfo
import me.him188.ani.app.data.source.danmaku.protocol.DanmakuLocation
import me.him188.ani.app.navigation.LocalBrowserNavigator
import me.him188.ani.app.navigation.LocalNavigator
import me.him188.ani.app.platform.LocalContext
import me.him188.ani.app.platform.setRequestFullScreen
Expand All @@ -73,6 +74,7 @@ import me.him188.ani.app.ui.foundation.pagerTabIndicatorOffset
import me.him188.ani.app.ui.foundation.rememberImageViewerHandler
import me.him188.ani.app.ui.foundation.rememberViewModel
import me.him188.ani.app.ui.foundation.theme.weaken
import me.him188.ani.app.ui.foundation.widgets.LocalToaster
import me.him188.ani.app.ui.subject.episode.comments.EpisodeCommentColumn
import me.him188.ani.app.ui.subject.episode.comments.EpisodeEditCommentSheet
import me.him188.ani.app.ui.subject.episode.danmaku.DanmakuEditor
Expand Down Expand Up @@ -168,6 +170,9 @@ private fun EpisodeSceneTabletVeryWide(
modifier: Modifier = Modifier,
) {
var showEditCommentSheet by rememberSaveable { mutableStateOf(false) }
val browserNavigator = LocalBrowserNavigator.current
val context = LocalContext.current
val toaster = LocalToaster.current

BoxWithConstraints {
val maxWidth = maxWidth
Expand Down Expand Up @@ -220,7 +225,17 @@ private fun EpisodeSceneTabletVeryWide(
vm.editCommentState.handleNewEdit(it)
showEditCommentSheet = true
},
onClickUrl = { },
onClickUrl = {
try {
if (it.startsWith("https://") || it.startsWith("http://")) {
browserNavigator.openBrowser(context, it)
} else {
toaster.toast("此链接可能会打开其他应用,ani 将不会打开此链接:\n$it")
}
} catch (ex: Exception) {
toaster.toast("无法打开此链接:\n$it")
}
},
)
}
}
Expand Down Expand Up @@ -284,10 +299,15 @@ private fun EpisodeSceneContentPhone(
vm: EpisodeViewModel,
modifier: Modifier = Modifier,
) {
val browserNavigator = LocalBrowserNavigator.current
val context = LocalContext.current
val toaster = LocalToaster.current

var showDanmakuEditor by rememberSaveable { mutableStateOf(false) }
var didSetPaused by rememberSaveable { mutableStateOf(false) }
var showEditCommentSheet by rememberSaveable { mutableStateOf(false) }


val pauseOnPlaying: () -> Unit = {
if (vm.videoScaffoldConfig.pauseVideoOnEditDanmaku && vm.playerState.state.value.isPlaying) {
didSetPaused = true
Expand Down Expand Up @@ -337,7 +357,17 @@ private fun EpisodeSceneContentPhone(
pauseOnPlaying()

},
onClickUrl = { },
onClickUrl = {
try {
if (it.startsWith("https://") || it.startsWith("http://")) {
browserNavigator.openBrowser(context, it)
} else {
toaster.toast("此链接可能会打开其他应用,ani 将不会打开此链接:\n$it")
}
} catch (ex: Exception) {
toaster.toast("无法打开此链接:\n$it")
}
},
)
},
modifier.then(if (vm.isFullscreen) Modifier.fillMaxSize() else Modifier.navigationBarsPadding()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private class EpisodeViewModelImpl(
"${sub.displayName} ${epi?.renderEpisodeEp()}"
}.stateIn(backgroundScope, SharingStarted.Lazily, null),
stickerProvider = { BangumiCommentSticker.map { EditCommentSticker(it.first, it.second) } },
onSend = { id, content -> },
onSend = { _, _ -> },
backgroundScope = backgroundScope,
)

Expand Down

0 comments on commit d92a8ea

Please sign in to comment.